aboutsummaryrefslogtreecommitdiff
path: root/doc/import/ParserDewey.rb
diff options
context:
space:
mode:
authorNemael <100dragons@gmail.com>2021-02-05 16:09:19 +0100
committerNemael <100dragons@gmail.com>2021-02-05 16:09:19 +0100
commitb30fad1d0744ec070335612a46d2a15bac06f1d2 (patch)
treee3492d32fa962d60b3d800ec01cb995d2b1799c3 /doc/import/ParserDewey.rb
parent757decefafb5d82557a8b7fa9691f94f19c3207e (diff)
downloadincommon-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/ParserDewey.rb')
-rw-r--r--doc/import/ParserDewey.rb65
1 files changed, 65 insertions, 0 deletions
diff --git a/doc/import/ParserDewey.rb b/doc/import/ParserDewey.rb
new file mode 100644
index 0000000..bc4b3f5
--- /dev/null
+++ b/doc/import/ParserDewey.rb
@@ -0,0 +1,65 @@
+require 'json'
+
+class Parser
+ def initialize()
+ @list_of_locations = {}
+ @list_of_locations["type"] = "FeatureCollection"
+ @list_of_locations["features"] = []
+ end
+ def parseDeweyFiles(data_file)
+ data = JSON.parse(File.read(data_file))
+ i = 0
+ cat_nbr = 0
+ while i < data.size
+ new_item = {}
+ new_item["type"] = "Feature"
+ new_item["geometry"] = {}
+ new_item["geometry"]["type"] = "Point"
+ coords = data[i]["fields"]["position"].split(";")[1].gsub("POINT (","").gsub(")","").split(" ")
+ coords[0] = coords[0].to_f
+ coords[1] = coords[1].to_f
+ new_item["geometry"]["coordinates"] = coords
+ new_item["properties"] = {}
+ new_item["properties"]["name"] = data[i]["fields"]["name"]
+ new_item["properties"]["description"] = data[i]["fields"]["comment"]
+ new_item["properties"]["entry_number"] = data[i]["pk"]
+ new_item["properties"]["phone_number"] = data[i]["fields"]["phone"]
+ new_item["properties"]["website"] = data[i]["fields"]["web"]
+ new_item["properties"]["mail"] = data[i]["fields"]["email"]
+ new_item["properties"]["address"] = data[i]["fields"]["address"]
+ new_item["properties"]["city"] = "" #No equivalent in Dewey database
+ new_item["properties"]["postal_code"] = "" #No equivalent in Dewey database
+ new_item["properties"]["categories"] = data[i]["fields"]["subcategories"]
+ new_item["properties"]["source"] = "Dewey"
+ new_item["properties"]["srid"] = data[i]["fields"]["position"].split(";")[0].gsub("SRID=","")
+ @list_of_locations["features"].push(new_item)
+ i += 1
+ end
+ end
+ def writeToFile(write_file)
+ File.write(write_file, JSON.pretty_generate(@list_of_locations))
+ end
+ def seeCategories(data_file)
+ data = CSV.parse(File.read(data_file), headers: true, :col_sep => ";")
+ i = 0
+ p = Set.new
+ while i < data.size
+ p << data[i]["Cat"]
+ i += 1
+ end
+ puts p
+ end
+end
+
+BEGIN {
+ puts "Starting parser"
+}
+
+parser = Parser.new()
+parser.parseDeweyFiles("Dewey/dewey-maps-markers.json")
+parser.writeToFile("LocationsDewey.geojson")
+
+
+END {
+ puts "Ending parser"
+}