Skip to content

Commit 934841a

Browse files
committed
Improve place layer with boundary and admin_level details. Loads additional rows as well as columns. #16
1 parent 527a2a2 commit 934841a

File tree

2 files changed

+68
-11
lines changed

2 files changed

+68
-11
lines changed

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

0 commit comments

Comments
 (0)