Skip to content

Commit 54ec659

Browse files
Merge pull request #19 from rustprooflabs/new-layers
Add amenity, improve place
2 parents 29a4a63 + 934841a commit 54ec659

File tree

7 files changed

+210
-11
lines changed

7 files changed

+210
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Current environment variables:
8585
* `PGOSM_SRID`
8686
* `PGOSM_SCHEMA`
8787

88+
> WARNING: Customizing the schema name will cause the `.sql` scripts to break.
8889
8990
To use SRID 4326 and the `osm_custom` schema:
9091

flex-config/amenity.lua

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
require "helpers"
2+
3+
local tables = {}
4+
5+
tables.amenity_point = osm2pgsql.define_table({
6+
name = 'amenity_point',
7+
schema = schema_name,
8+
ids = { type = 'node', id_column = 'osm_id' },
9+
columns = {
10+
{ column = 'osm_type', type = 'text', not_null = true },
11+
{ column = 'name', type = 'text' },
12+
{ column = 'geom', type = 'point' , projection = srid},
13+
}
14+
})
15+
16+
tables.amenity_line = osm2pgsql.define_table({
17+
name = 'amenity_line',
18+
schema = schema_name,
19+
ids = { type = 'way', id_column = 'osm_id' },
20+
columns = {
21+
{ column = 'osm_type', type = 'text', not_null = true },
22+
{ column = 'name', type = 'text' },
23+
{ column = 'geom', type = 'linestring' , projection = srid},
24+
}
25+
})
26+
27+
28+
tables.amenity_polygon = osm2pgsql.define_table({
29+
name = 'amenity_polygon',
30+
schema = schema_name,
31+
ids = { type = 'area', id_column = 'osm_id' },
32+
columns = {
33+
{ column = 'osm_type', type = 'text', not_null = true },
34+
{ column = 'name', type = 'text' },
35+
{ column = 'geom', type = 'multipolygon' , projection = srid},
36+
}
37+
})
38+
39+
40+
function amenity_process_node(object)
41+
if not object.tags.amenity then
42+
return
43+
end
44+
45+
-- Using grab_tag() removes from remaining key/value saved to Pg
46+
local osm_type = object:grab_tag('amenity')
47+
local name = object:grab_tag('name')
48+
49+
tables.amenity_point:add_row({
50+
osm_type = osm_type,
51+
name = name,
52+
geom = { create = 'point' }
53+
})
54+
55+
end
56+
57+
-- Change function name here
58+
function amenity_process_way(object)
59+
if not object.tags.amenity then
60+
return
61+
end
62+
63+
local osm_type = object:grab_tag('amenity')
64+
local name = object:grab_tag('name')
65+
66+
if object.is_closed then
67+
tables.amenity_polygon:add_row({
68+
osm_type = osm_type,
69+
name = name,
70+
geom = { create = 'area' }
71+
})
72+
else
73+
tables.amenity_line:add_row({
74+
osm_type = osm_type,
75+
name = name,
76+
geom = { create = 'line' }
77+
})
78+
end
79+
80+
end
81+
82+
83+
function amenity_process_relation(object)
84+
if not object.tags.amenity then
85+
return
86+
end
87+
88+
local osm_type = object:grab_tag('amenity')
89+
local name = object:grab_tag('name')
90+
91+
if object.tags.type == 'multipolygon' or object.tags.type == 'boundary' then
92+
tables.amenity_polygon:add_row({
93+
osm_type = osm_type,
94+
name = name,
95+
geom = { create = 'area' }
96+
})
97+
end
98+
end
99+
100+
101+
102+
if osm2pgsql.process_node == nil then
103+
osm2pgsql.process_node = amenity_process_node
104+
else
105+
local nested = osm2pgsql.process_node
106+
osm2pgsql.process_node = function(object)
107+
local object_copy = deep_copy(object)
108+
nested(object)
109+
amenity_process_node(object_copy)
110+
end
111+
end
112+
113+
114+
115+
if osm2pgsql.process_way == nil then
116+
osm2pgsql.process_way = amenity_process_way
117+
else
118+
local nested = osm2pgsql.process_way
119+
osm2pgsql.process_way = function(object)
120+
local object_copy = deep_copy(object)
121+
nested(object)
122+
amenity_process_way(object_copy)
123+
end
124+
end
125+
126+
127+
if osm2pgsql.process_relation == nil then
128+
osm2pgsql.process_relation = amenity_process_relation
129+
else
130+
local nested = osm2pgsql.process_relation
131+
osm2pgsql.process_relation = function(object)
132+
local object_copy = deep_copy(object)
133+
nested(object)
134+
amenity_process_relation(object_copy)
135+
end
136+
end

flex-config/amenity.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
COMMENT ON TABLE osm.amenity_point IS 'OpenStreetMap amenity points - all points with an amenity tag. Some amenity tags are pulled into other tables (e.g. infrastructure, shop, and traffic layers) and duplicated again here. This is currently intentional but may change in the future. Generated by osm2pgsql Flex output using pgosm-flex/flex-config/amenity.lua';
2+
COMMENT ON TABLE osm.amenity_line IS 'OpenStreetMap amenity lines - all lines with an amenity tag. Some amenity tags are pulled into other tables (e.g. infrastructure, shop, and traffic layers) and duplicated again here. This is currently intentional but may change in the future. Generated by osm2pgsql Flex output using pgosm-flex/flex-config/amenity.lua';
3+
COMMENT ON TABLE osm.amenity_polygon IS 'OpenStreetMap amenity polygons - all polygons with an amenity tag. Some amenity tags are pulled into other tables (e.g. infrastructure, shop, and traffic layers) and duplicated again here. This is currently intentional but may change in the future. Generated by osm2pgsql Flex output using pgosm-flex/flex-config/amenity.lua';

flex-config/place.lua

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ tables.place_point = osm2pgsql.define_table({
99
ids = { type = 'node', id_column = 'osm_id' },
1010
columns = {
1111
{ column = 'osm_type', type = 'text', not_null = true },
12+
{ column = 'boundary', type = 'text' },
13+
{ column = 'admin_level', type = 'text' },
1214
{ column = 'name', type = 'text' },
1315
{ column = 'geom', type = 'point' , projection = srid},
1416
}
@@ -20,6 +22,8 @@ tables.place_line = osm2pgsql.define_table({
2022
ids = { type = 'way', id_column = 'osm_id' },
2123
columns = {
2224
{ column = 'osm_type', type = 'text', not_null = true },
25+
{ column = 'boundary', type = 'text' },
26+
{ column = 'admin_level', type = 'text' },
2327
{ column = 'name', type = 'text' },
2428
{ column = 'geom', type = 'linestring' , projection = srid},
2529
}
@@ -32,47 +36,80 @@ tables.place_polygon = osm2pgsql.define_table({
3236
ids = { type = 'area', id_column = 'osm_id' },
3337
columns = {
3438
{ column = 'osm_type', type = 'text', not_null = true },
39+
{ column = 'boundary', type = 'text' },
40+
{ column = 'admin_level', type = 'text' },
3541
{ column = 'name', type = 'text' },
3642
{ column = 'geom', type = 'multipolygon' , projection = srid},
3743
}
3844
})
3945

4046

4147
function place_process_node(object)
42-
if not object.tags.place then
48+
if not object.tags.place
49+
and not object.tags.boundary
50+
and not object.tags.admin_level then
4351
return
4452
end
4553

46-
-- Using grab_tag() removes from remaining key/value saved to Pg
47-
local osm_type = object:grab_tag('place')
54+
local osm_type
55+
56+
if object.tags.place then
57+
osm_type = object:grab_tag('place')
58+
elseif object.tags.boundary then
59+
osm_type = 'boundary'
60+
elseif object.tags.admin_level then
61+
osm_type = 'admin_level'
62+
end
63+
64+
local boundary = object:grab_tag('boundary')
65+
local admin_level = object:grab_tag('admin_level')
4866
local name = object:grab_tag('name')
4967

5068
tables.place_point:add_row({
5169
osm_type = osm_type,
70+
boundary = boundary,
71+
admin_level = admin_level,
5272
name = name,
5373
geom = { create = 'point' }
5474
})
5575

5676
end
5777

58-
-- Change function name here
78+
5979
function place_process_way(object)
60-
if not object.tags.place then
80+
if not object.tags.place
81+
and not object.tags.boundary
82+
and not object.tags.admin_level
83+
then
6184
return
6285
end
6386

64-
local osm_type = object:grab_tag('place')
87+
if object.tags.place then
88+
osm_type = object:grab_tag('place')
89+
elseif object.tags.boundary then
90+
osm_type = 'boundary'
91+
elseif object.tags.admin_level then
92+
osm_type = 'admin_level'
93+
end
94+
95+
96+
local boundary = object:grab_tag('boundary')
97+
local admin_level = object:grab_tag('admin_level')
6598
local name = object:grab_tag('name')
6699

67100
if object.is_closed then
68101
tables.place_polygon:add_row({
69102
osm_type = osm_type,
103+
boundary = boundary,
104+
admin_level = admin_level,
70105
name = name,
71106
geom = { create = 'area' }
72107
})
73108
else
74109
tables.place_line:add_row({
75110
osm_type = osm_type,
111+
boundary = boundary,
112+
admin_level = admin_level,
76113
name = name,
77114
geom = { create = 'line' }
78115
})
@@ -82,16 +119,31 @@ end
82119

83120

84121
function place_process_relation(object)
85-
if not object.tags.place then
122+
if not object.tags.place
123+
and not object.tags.boundary
124+
and not object.tags.admin_level
125+
then
86126
return
87127
end
88128

89-
local osm_type = object:grab_tag('place')
129+
if object.tags.place then
130+
osm_type = object:grab_tag('place')
131+
elseif object.tags.boundary then
132+
osm_type = 'boundary'
133+
elseif object.tags.admin_level then
134+
osm_type = 'admin_level'
135+
end
136+
137+
138+
local boundary = object:grab_tag('boundary')
139+
local admin_level = object:grab_tag('admin_level')
90140
local name = object:grab_tag('name')
91141

92142
if object.tags.type == 'multipolygon' or object.tags.type == 'boundary' then
93143
tables.place_polygon:add_row({
94144
osm_type = osm_type,
145+
boundary = boundary,
146+
admin_level = admin_level,
95147
name = name,
96148
geom = { create = 'area' }
97149
})

flex-config/place.sql

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
COMMENT ON TABLE osm.place_point IS 'OpenStreetMap named places. Generated by osm2pgsql Flex output using pgosm-flex/flex-config/place.lua';
2-
COMMENT ON TABLE osm.place_line IS 'OpenStreetMap named places. Generated by osm2pgsql Flex output using pgosm-flex/flex-config/place.lua';
3-
COMMENT ON TABLE osm.place_polygon IS 'OpenStreetMap named places. Generated by osm2pgsql Flex output using pgosm-flex/flex-config/place.lua';
1+
COMMENT ON TABLE osm.place_point IS 'OpenStreetMap named places and administrative boundaries. Generated by osm2pgsql Flex output using pgosm-flex/flex-config/place.lua';
2+
COMMENT ON TABLE osm.place_line IS 'OpenStreetMap named places and administrative boundaries. Generated by osm2pgsql Flex output using pgosm-flex/flex-config/place.lua';
3+
COMMENT ON TABLE osm.place_polygon IS 'OpenStreetMap named places and administrative boundaries. Generated by osm2pgsql Flex output using pgosm-flex/flex-config/place.lua';
4+
5+
6+
COMMENT ON COLUMN osm.place_point.osm_type IS 'Values from place if a place tag exists. If no place tag, values boundary or admin_level indicate the source of the feature.';
7+
COMMENT ON COLUMN osm.place_line.osm_type IS 'Values from place if a place tag exists. If no place tag, values boundary or admin_level indicate the source of the feature.';
8+
COMMENT ON COLUMN osm.place_polygon.osm_type IS 'Values from place if a place tag exists. If no place tag, values boundary or admin_level indicate the source of the feature.';
49

510

611
ALTER TABLE osm.place_point

flex-config/run-no-tags.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ require "infrastructure"
88
require "water"
99
require "indoor"
1010
require "shop"
11+
require "amenity"

flex-config/run-no-tags.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
\i water.sql
99
\i indoor.sql
1010
\i shop.sql
11+
\i amenity.sql

0 commit comments

Comments
 (0)