-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgeometries-alone.lua
More file actions
113 lines (98 loc) · 3.36 KB
/
geometries-alone.lua
File metadata and controls
113 lines (98 loc) · 3.36 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
-- This is a very simple Lua config for the Flex output
-- which only stores the geometries (not even the tags)
-- for use with Underpass-API to mimic Overpass
local tables = {}
tables.nodes_geom = osm2pgsql.define_table({
name = 'nodes_geom',
ids = { type = 'node', id_column = 'id', create_index='unique' },
columns = {
{ column = 'geom', type = 'point', projection = 4326, not_null = true }
}})
tables.ways_geom = osm2pgsql.define_table({
name = 'ways_geom',
ids = { type = 'way', id_column = 'id', create_index='unique' },
columns = {
{ column = 'geom', type = 'geometry', projection = 4326, not_null = true },
{ column = 'area', type = 'real' }
}})
tables.rels_geom = osm2pgsql.define_table({
name = 'rels_geom',
ids = { type = 'relation', id_column = 'id', create_index='unique' },
columns = {
{ column = 'geom', type = 'geometry', projection = 4326, not_null = true },
{ column = 'area', type = 'real' }
}})
-- Helper function that looks at the tags and decides if this is possibly an area
local function has_area_tags(tags)
if tags.area == 'yes' or tags.area == 'true' or tags.area == '1' then
return true
end
if tags.area == 'no' or tags.area == 'false' or tags.area == '0' then
return false
end
return tags.aeroway
or tags.amenity
or tags.building
or tags.harbour
or tags.historic
or tags.landuse
or tags.leisure
or tags.man_made
or tags.military
or tags.natural
or tags.office
or tags.place
or tags.power
or tags.public_transport
or tags.shop
or tags.sport
or tags.tourism
or tags.water
or tags.waterway
or tags.wetland
or tags['abandoned:aeroway']
or tags['abandoned:amenity']
or tags['abandoned:building']
or tags['abandoned:landuse']
or tags['abandoned:power']
or tags['area:highway']
end
-- Store geometry of nodes (so that they can be indexed)
function osm2pgsql.process_node(object)
tables.nodes_geom:insert({
geom = object:as_point()
})
end
function osm2pgsql.process_way(object)
-- A closed way that also has the right tags for an area is a polygon.
if object.is_closed and has_area_tags(object.tags) then
-- Creating the polygon geometry takes time, so we do it once here
-- and later store it in the table and use it to calculate the area.
local geom = object:as_polygon()
tables.ways_geom:insert({
geom = geom,
area = geom:spherical_area() -- calculate "real" area in spheroid
})
else
-- Store way as line
tables.ways_geom:insert({
geom = object:as_linestring()
})
end
end
function osm2pgsql.process_relation(object)
local relation_type = object:grab_tag('type')
-- Store multipolygon and boundary relations as multipolygons, with their area
if relation_type == 'multipolygon' or relation_type == 'boundary' then
local geom = object:as_multipolygon()
tables.rels_geom:insert({
geom = geom,
area = geom:spherical_area()
})
else
-- Store other relations as geometryCollection
tables.rels_geom:insert({
geom = object:as_geometrycollection()
})
end
end