Skip to content

Commit 4b0d8d0

Browse files
committed
Add "protected_areas" topic to "explore" theme
Remove old version of this from experimental theme.
1 parent f0b9e3b commit 4b0d8d0

File tree

5 files changed

+161
-59
lines changed

5 files changed

+161
-59
lines changed

config/explore_protected_areas.lua

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-- ---------------------------------------------------------------------------
2+
--
3+
-- Example config for exploring OSM data
4+
--
5+
-- Configuration for the osm2pgsql Themepark framework
6+
--
7+
-- ---------------------------------------------------------------------------
8+
9+
local themepark = require('themepark')
10+
11+
-- For debug mode set this or the environment variable THEMEPARK_DEBUG.
12+
themepark.debug = true
13+
14+
-- ---------------------------------------------------------------------------
15+
16+
themepark:set_option('debug', 'debug') -- Add JSONB column `debug` with debug infos in debug mode
17+
themepark:set_option('tags', 'all_tags') -- Add JSONB column `tags` with original OSM tags in debug mode
18+
19+
-- ---------------------------------------------------------------------------
20+
21+
themepark:add_topic('core/name-with-fallback', {
22+
keys = {
23+
name = { 'name', 'name:en', 'name:de' },
24+
name_de = { 'name:de', 'name', 'name:en' },
25+
name_en = { 'name:en', 'name', 'name:de' },
26+
}
27+
})
28+
29+
themepark:add_topic('explore/protected_areas')
30+
31+
-- ---------------------------------------------------------------------------

themes/experimental/topics/protected_areas.lua

Lines changed: 0 additions & 59 deletions
This file was deleted.

themes/explore/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ osmium tags-filter -o postcodes.osm.pbf DATA.osm.pbf \
8888
'addr:*' r/postal_code
8989
```
9090

91+
## Topic: Protected Areas
92+
93+
Areas protected for nature conservancy such as national parks. There is a wide
94+
variety of types of such areas found around the world and also quite varied
95+
tagging.
96+
97+
Pre-Filtering:
98+
99+
```
100+
osmium tags-filter -o protected_areas.osm.pbf DATA.osm.pbf \
101+
boundary=protected_area,national_park,water_protection_area \
102+
leisure=nature_reserve \
103+
protect_class protection_title short_protection_title
104+
```
105+
91106
## Topic: Restrictions
92107

93108
Turn restrictions (relations tagged `type=restrictions`) for road navigation.
27.9 KB
Binary file not shown.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
-- ---------------------------------------------------------------------------
2+
--
3+
-- Theme: explore
4+
-- Topic: protected_areas
5+
--
6+
-- ---------------------------------------------------------------------------
7+
8+
local themepark, theme, cfg = ...
9+
10+
themepark:add_table({
11+
name = 'protected_areas_boundaries',
12+
ids_type = 'area',
13+
geom = 'multipolygon',
14+
columns = themepark:columns('core/name', {
15+
{ column = 'boundary', type = 'text' },
16+
{ column = 'protect_class', type = 'text' },
17+
{ column = 'protection_title', type = 'text' },
18+
{ column = 'short_protection_title', type = 'text' },
19+
{ column = 'nature_reserve', type = 'bool', not_null = true }, -- has tag leisure=nature_reserve
20+
{ column = 'ref', type = 'text' },
21+
{ column = 'access', type = 'text' },
22+
{ column = 'wikidata', type = 'text' },
23+
{ column = 'website', type = 'text' },
24+
{ column = 'operator', type = 'text' },
25+
{ column = 'operator_wikidata', type = 'text' },
26+
{ column = 'related_law', type = 'text' },
27+
{ column = 'related_law_url', type = 'text' },
28+
{ column = 'iucn', type = 'text' }, -- tag "ref:IUCN"
29+
{ column = 'iucn_level', type = 'text' }, -- tag "iucn_level"
30+
{ column = 'wdpa', type = 'int' }, -- WDPA
31+
{ column = 'capad_pa_id', type = 'text' }, -- Collaborative Australian Protected Areas Database (CAPAD)
32+
{ column = 'dtp_id', type = 'text' }, -- DIGITIZE THE PLANET
33+
}),
34+
})
35+
36+
themepark:add_table({
37+
name = 'protected_areas_errors',
38+
ids_type = 'area',
39+
geom = 'multipolygon',
40+
columns = {
41+
{ column = 'errormsg', type = 'text', not_null = true },
42+
{ column = 'value', type = 'text' },
43+
}
44+
})
45+
46+
local get_qcode = function(wd)
47+
if wd and wd:match('^Q%d+$') then
48+
return wd
49+
end
50+
return nil
51+
end
52+
53+
themepark:add_proc('area', function(object, data)
54+
local t = object.tags
55+
if t.boundary == 'protected_area' or t.boundary == 'national_park' or t.boundary == 'water_protection_area' or t.leisure == 'nature_reserve' or t.protected_area then
56+
57+
-- Check that wikidata tags contain syntactically valid Q codes
58+
-- https://www.wikidata.org/wiki/{wikidata_code}
59+
local wikidata_code = get_qcode(t.wikidata)
60+
local operator_wikidata_code = get_qcode(t.operator_wikidata)
61+
62+
if t.wikidata ~= wikidata_code then
63+
themepark:insert('protected_areas_errors', { errormsg = 'invalid Q-item code for wikidata tag', value = t.wikidata }, t)
64+
end
65+
if t.operator_wikidata ~= operator_wikidata_code then
66+
themepark:insert('protected_areas_errors', { errormsg = 'invalid Q-item code for operator_wikidata tag', value = t.operator_wikidata }, t)
67+
end
68+
69+
-- WDPA is always an integer
70+
-- https://www.protectedplanet.net/{wdpa}
71+
local wdpa = t['ref:WDPA']
72+
if wdpa and wdpa:match('^%d+$') then
73+
wdpa = tonumber(wdpa)
74+
else
75+
themepark:insert('protected_areas_errors', { errormsg = 'not a number in ref:WDPA tag', value = wdpa }, t)
76+
wdpa = nil
77+
end
78+
79+
-- Digitize The Planet uses UUIDs
80+
-- https://content.digitizetheplanet.org/de/rules/show_protectedarea/{dtp_id}
81+
local dtp_id = t.dtp_id
82+
if dtp_id and not dtp_id:match('^[0-9a-f-]+$') then
83+
themepark:insert('protected_areas_errors', { errormsg = 'not a UUID in dtp_id tag', value = dtp_id }, t)
84+
end
85+
86+
local a = {
87+
boundary = t.boundary,
88+
protect_class = t.protect_class,
89+
protection_title = t.protection_title,
90+
short_protection_title = t.short_protection_title,
91+
nature_reserve = (t.leisure == 'nature_reserve'),
92+
protected_area = t.protected_area,
93+
ref = t.ref,
94+
access = t.access,
95+
wikidata = wikidata_code,
96+
website = t.website,
97+
operator = t.operator,
98+
operator_wikidata = operator_wikidata_code,
99+
related_law = t.related_law,
100+
related_law_url = t['related_law:url'],
101+
iucn = t['ref:IUCN'],
102+
iucn_level = t.iucn_level,
103+
wdpa = wdpa,
104+
capad_pa_id = t['ref:capad:pa_id'],
105+
dtp_id = dtp_id,
106+
geom = object:as_area(),
107+
}
108+
109+
themepark.themes.core.add_name(a, object)
110+
111+
themepark:insert('protected_areas_boundaries', a, t)
112+
end
113+
end)
114+
115+
-- ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)