diff options
author | Nemael <100dragons@gmail.com> | 2021-02-05 16:09:19 +0100 |
---|---|---|
committer | Nemael <100dragons@gmail.com> | 2021-02-05 16:09:19 +0100 |
commit | b30fad1d0744ec070335612a46d2a15bac06f1d2 (patch) | |
tree | e3492d32fa962d60b3d800ec01cb995d2b1799c3 /doc/import/ParserConcertes.rb | |
parent | 757decefafb5d82557a8b7fa9691f94f19c3207e (diff) | |
download | incommon-map-b30fad1d0744ec070335612a46d2a15bac06f1d2.tar.gz |
Split parser in three files with thress .geojson output. Also added a parser for Potagers. Added the need of rgeo and rgeo-geojson gems
Diffstat (limited to 'doc/import/ParserConcertes.rb')
-rw-r--r-- | doc/import/ParserConcertes.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/doc/import/ParserConcertes.rb b/doc/import/ParserConcertes.rb new file mode 100644 index 0000000..b63fba1 --- /dev/null +++ b/doc/import/ParserConcertes.rb @@ -0,0 +1,56 @@ +require 'json' +require 'csv' +require 'rgeo' +require 'rgeo-geojson' + +class Parser + def initialize() + @list_of_locations = {} + @list_of_locations["type"] = "FeatureCollection" + @list_of_locations["features"] = [] + end + def parseConcertesFiles(data_file, coordinates_file) + data = CSV.parse(File.read(data_file), headers: true, :col_sep => ";") + coord = CSV.parse(File.read(coordinates_file), headers: true, :col_sep => ";") + i = 0 + while i < data.size + new_item = {} + new_item["type"] = "Feature" + new_item["geometry"] = {} + new_item["geometry"]["type"] = "Point" + new_item["geometry"]["coordinates"] = [coord[i]["CoordLamb_X"].to_f, coord[i]["CoordLamb_Y"].to_f] + new_item["properties"] = {} + new_item["properties"]["name"] = data[i]["Denomination_FULL"] + new_item["properties"]["description"] = data[i]["description"] + new_item["properties"]["entry_number"] = data[i]["NumEntr"] + new_item["properties"]["phone_number"] = coord[i]["Tel"] + new_item["properties"]["website"] = coord[i]["Web"] + new_item["properties"]["mail"] = coord[i]["Email"] + new_item["properties"]["address"] = coord[i]["Adresse"] + new_item["properties"]["city"] = data[i]["INS_COMMUNE"] + new_item["properties"]["postal_code"] = coord[i]["Code postal"] + new_item["properties"]["categories"] = [] + new_item["properties"]["source"] = "Concertes" + new_item["properties"]["srid"] = "4326" #Not precised in Concertes database + @list_of_locations["features"].push(new_item) + i += 1 + end + File.write("Locations.geojson", JSON.pretty_generate(@list_of_locations)) + end + def writeToFile(write_file) + File.write(write_file, JSON.pretty_generate(@list_of_locations)) + end +end + +BEGIN { + puts "Starting parser" +} + +parser = Parser.new() +parser.parseConcertesFiles("Concertes/20200312_EntreprisesSignaletique.csv", "Concertes/20200312_EntreprisesCoordonnees.csv") +parser.writeToFile("LocationsConcertes.geojson") + + +END { + puts "Ending parser" +} |