aboutsummaryrefslogtreecommitdiff
path: root/data_extractor
diff options
context:
space:
mode:
Diffstat (limited to 'data_extractor')
-rw-r--r--data_extractor/Makefile38
-rw-r--r--data_extractor/data_extractor.lua76
2 files changed, 79 insertions, 35 deletions
diff --git a/data_extractor/Makefile b/data_extractor/Makefile
index 3ae44a7..c896889 100644
--- a/data_extractor/Makefile
+++ b/data_extractor/Makefile
@@ -1,2 +1,36 @@
-process_data:
- osm2pgsql -d map -O flex -S data_extractor.lua ~/Downloads/denmark-latest.osm.pbf
+.PHONY: process_data
+SHELL := /bin/bash
+
+pbfs/hamburg-latest.osm.pbf:
+ cd pbfs && wget https://download.geofabrik.de/europe/germany/hamburg-latest.osm.pbf
+
+pbfs/denmark-latest.osm.pbf:
+ cd pbfs && wget https://download.geofabrik.de/europe/denmark-latest.osm.pbf
+
+hamburg: pbfs/hamburg-latest.osm.pbf
+ # Load Hamburg, this resets DB
+ sudo -u postgres osm2pgsql -d map.node5.net -O flex -S data_extractor.lua pbfs/hamburg-latest.osm.pbf --slim
+ sudo -u postgres psql -d map.node5.net -c "update poi set region = 'Hamburg' where region IS NULL;"
+ sudo -u postgres psql -d map.node5.net -c "update poi set country = 'Germany' where country IS NULL;"
+
+denmark:
+ # Load Denmark
+ sudo -u postgres osm2pgsql -d map.node5.net -O flex -S data_extractor.lua pbfs/denmark-latest.osm.pbf --append --slim
+ sudo -u postgres psql -d map.node5.net -c "update poi set country = 'Denmark' where country IS NULL;"
+
+permission:
+ # Set code user permission
+ sudo -u postgres psql -d map.node5.net -c 'grant select on table poi to "map.node5.net";'
+
+count_per_country:
+ sudo -u postgres psql -d map.node5.net -c "select country, count(*) from poi group by country;"
+
+db_shell:
+ sudo -u postgres psql -d map.node5.net
+
+notify_desktop:
+ notify-send "OSM processing" "done"
+
+process_data: hamburg denmark count_per_country notify_desktop
+
+.DEFAULT_GOAL := process_data
diff --git a/data_extractor/data_extractor.lua b/data_extractor/data_extractor.lua
index 5f5cc9e..a51a1f1 100644
--- a/data_extractor/data_extractor.lua
+++ b/data_extractor/data_extractor.lua
@@ -2,43 +2,53 @@
-- Data: https://download.geofabrik.de/europe/denmark-latest.osm.pbf
local poi = osm2pgsql.define_table({
- name = 'poi',
- ids = { type = 'any', type_column = 'osm_type', id_column = 'osm_id' },
- columns = {
- { column = 'name' },
- { column = 'class', not_null = true },
- { column = 'subclass' },
- { column = 'brand' },
- { column = 'geom', type = 'point', not_null = true },
-}})
-
-function process_poi(object, geom)
- local a = {
- name = object.tags.name,
- geom = geom
- }
+ name = 'poi',
+ ids = { type = 'any', type_column = 'osm_type', id_column = 'osm_id' },
+ columns = {
+ { column = 'name' },
+ { column = 'country' },
+ { column = 'region' },
+ { column = 'class', not_null = true },
+ { column = 'subclass' },
+ { column = 'brand' },
+ { column = 'geom', type = 'point', not_null = true },
+ }})
+ function process_poi(object, geom)
+ local a = {
+ name = object.tags.name,
+ geom = geom
+ }
if object.tags.shop then
- a.class = 'shop'
- a.subclass = object.tags.shop
- a.brand = object.tags.brand
+ a.class = 'shop'
+ a.subclass = object.tags.shop
+ a.brand = object.tags.brand
+ elseif object.tags.highway then
+ a.class = 'highway'
+ a.subclass = object.tags.highway
+ elseif object.tags.public_transport == "station" or object.tags.railway == "station" then
+ a.class = 'railway'
+ a.subclass = 'station'
+ --elseif object.tags.brand == "McDonald's" then
+ -- a.class = 'amenity'
+ -- a.subclass = "McDonald's"
elseif object.tags.amenity then
- a.class = 'amenity'
- a.subclass = object.tags.amenity
- else
- return
- end
+ a.class = 'amenity'
+ a.subclass = object.tags.amenity
+ else
+ return
+ end
- poi:insert(a)
-end
+ poi:insert(a)
+ end
-function osm2pgsql.process_node(object)
- process_poi(object, object:as_point())
-end
+ function osm2pgsql.process_node(object)
+ process_poi(object, object:as_point())
+ end
-function osm2pgsql.process_way(object)
- if object.is_closed and object.tags.building then
- process_poi(object, object:as_polygon():centroid())
- end
-end
+ function osm2pgsql.process_way(object)
+ if object.is_closed and object.tags.building then
+ process_poi(object, object:as_polygon():centroid())
+ end
+ end