aboutsummaryrefslogtreecommitdiff
path: root/data_extractor/data_extractor.lua
blob: e10da247d70e830169a3c5732b5057a26a299e0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-- Based on: https://osm2pgsql.org/examples/poi-db/
-- 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 = '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
		elseif object.tags.highway then
			a.class = 'highway'
			a.subclass = object.tags.highway
		elseif object.tags.railway then
			a.class = 'railway'
			a.subclass = object.tags.railway
		--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

		poi:insert(a)
	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