Skip to content

Commit bea98ca

Browse files
Merge pull request #120 from rustprooflabs/fix-bench-119
Rework and consolidate logic for amenity inclusion
2 parents 7256c0c + 631e8b9 commit bea98ca

File tree

6 files changed

+125
-35
lines changed

6 files changed

+125
-35
lines changed

db/qc/osm_tag_suggestions.sql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11

22

33
SELECT geom_type, osm_id,
4-
'Update to: amenity=bicycle_parking per https://wiki.openstreetmap.org/wiki/Key:bicycle_parking'::TEXT AS suggestion,
4+
'Update to: amenity=bicycle_parking per https://wiki.openstreetmap.org/wiki/Key:bicycle_parking'::TEXT
5+
AS suggestion,
56
osm_url, tags
67
FROM osm.tags
78
WHERE tags->>'bicycle_parking' IS NOT NULL
89
AND tags->>'amenity' IS NULL
10+
UNION
11+
SELECT t.geom_type, t.osm_id,
12+
'Invald bench value. Valid values for `bench` are "yes" and "no" per https://wiki.openstreetmap.org/wiki/Key:bench'::TEXT
13+
AS suggestion,
14+
t.osm_url, t.tags
15+
FROM osm.tags t
16+
WHERE t.tags->>'amenity' IS NULL
17+
AND t.tags->>'bench' IS NOT NULL
18+
AND t.tags->>'bench' NOT IN ('yes', 'no')
919
;
1020

flex-config/style/amenity.lua

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,31 @@ local amenity_first_level_keys = {
6464

6565
local is_first_level_amenity = make_check_in_list_func(amenity_first_level_keys)
6666

67-
function amenity_process_node(object)
68-
if not is_first_level_amenity(object.tags) then
69-
return
70-
end
71-
72-
if object.tags.bench == 'no' then
73-
return
74-
end
7567

68+
local function get_osm_type(object)
7669
local osm_type = object.tags.amenity
70+
7771
if osm_type == nil and object.tags.bench == 'yes' then
7872
osm_type = 'bench'
7973
elseif osm_type == nil and object.tags.brewery then
8074
osm_type = 'brewery'
8175
end
8276

77+
return osm_type
78+
end
79+
80+
81+
function amenity_process_node(object)
82+
if not is_first_level_amenity(object.tags) then
83+
return
84+
end
85+
86+
local osm_type = get_osm_type(object)
87+
88+
if osm_type == nil then
89+
return
90+
end
91+
8392
local name = get_name(object.tags)
8493

8594

@@ -111,15 +120,10 @@ function amenity_process_way(object)
111120
return
112121
end
113122

114-
if object.tags.bench == 'no' then
115-
return
116-
end
123+
local osm_type = get_osm_type(object)
117124

118-
local osm_type = object.tags.amenity
119-
if osm_type == nil and object.tags.bench == 'yes' then
120-
osm_type = 'bench'
121-
elseif osm_type == nil and object.tags.brewery then
122-
osm_type = 'brewery'
125+
if osm_type == nil then
126+
return
123127
end
124128

125129
local name = get_name(object.tags)
@@ -166,18 +170,12 @@ function amenity_process_relation(object)
166170
return
167171
end
168172

169-
if object.tags.bench == 'no' then
170-
return
171-
end
173+
local osm_type = get_osm_type(object)
172174

173-
local osm_type = object.tags.amenity
174-
if osm_type == nil and object.tags.bench == 'yes' then
175-
osm_type = 'bench'
176-
elseif osm_type == nil and object.tags.brewery then
177-
osm_type = 'brewery'
175+
if osm_type == nil then
176+
return
178177
end
179178

180-
181179
local name = get_name(object.tags)
182180

183181
local address = get_address(object.tags)

tests/README.md

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,48 @@
33

44
Under development - See #112.
55

6-
## Data
76

8-
Load `data/district-of-columbia-2021-01-13.osm.pbf` for all tests.
7+
```bash
8+
cd tests/
9+
```
10+
911

10-
PBF sourced [from Geofabrik's download service](https://download.geofabrik.de/)
11-
on January 13, 2021.
12+
## Test for import failures
1213

14+
Test for specific regions that have had failures due to unusual
15+
tags and/or bugs in PgOSM-Flex.
1316

14-
Run tests
17+
18+
Run extra region load tests.
1519

1620
```bash
17-
cd tests/
18-
./run-tests.sh
21+
./run-extra-loads.sh
22+
```
23+
24+
## Output Tests
25+
26+
Load `data/district-of-columbia-2021-01-13.osm.pbf` with `run-all`
27+
before running these tests.
28+
29+
30+
Run output tests (need D.C. region loaded first).
31+
32+
```bash
33+
./run-output-tests.sh
1934
```
2035

2136

22-
## Creating Tests
37+
> PBF sourced [from Geofabrik's download service](https://download.geofabrik.de/) on January 13, 2021.
38+
39+
40+
41+
### Creating Tests
2342

2443
Write query. Ensure results are ordered using `COLLATE "C"` to ensure consistent ordering across
2544
systems.
2645

2746

28-
## Creating expected output
47+
### Creating expected output
2948

3049

3150
To create new tests, or to update existing tests use `psql --no-psqlrc -tA <details>`.
@@ -38,3 +57,23 @@ psql --no-psqlrc -tA \
3857
> expected/amenity_osm_type_count.out
3958
```
4059

60+
61+
62+
## Create PBFs for areas w/ Failures
63+
64+
Identify a feature related to the issue and load small region around
65+
into JOSM (as if making an edit).
66+
67+
Use JOSM's "Save As..." to save the `<region-failure-name>.osm` file.
68+
Use `osmium-tool` (https://osmcode.org/osmium-tool/manual.html)
69+
to convert to `.pbf` format.
70+
71+
```bash
72+
osmium cat <region-failure-name>.osm -o <region-failure-name>.osm.pbf
73+
mv <region-failure-name>.osm.pbf ~/git/pgosm-flex/tests/data/extra-regions/
74+
```
75+
76+
77+
78+
79+
Binary file not shown.

tests/run-extra-loads.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
echo "Running PgOSM-Flex extra region loads"
3+
4+
set -e
5+
6+
if [ -z $PGOSM_CONN ]; then
7+
PGOSM_CONN=pgosm_tests
8+
else
9+
PGOSM_CONN=$PGOSM_CONN
10+
fi
11+
12+
if [ -z $PGOSM_CONN_PG ]; then
13+
PGOSM_CONN_PG=postgres
14+
else
15+
PGOSM_CONN_PG=$PGOSM_CONN_PG
16+
fi
17+
18+
DATA_PATH=data/extra-regions
19+
20+
for filename in ${DATA_PATH}/*.osm.pbf; do
21+
#file_base=$(basename "${filename}" .osm.pbf)
22+
#echo $file_base
23+
echo $filename
24+
25+
echo 'Dropping test DB pgosm_tests'
26+
psql -d $PGOSM_CONN_PG -c "DROP DATABASE pgosm_tests;" || true
27+
28+
echo 'Creating test DB pgosm_tests'
29+
psql -d $PGOSM_CONN_PG -c "CREATE DATABASE pgosm_tests;"
30+
psql -d $PGOSM_CONN -c "CREATE EXTENSION postgis; CREATE SCHEMA osm;"
31+
32+
original_dir=$PWD
33+
echo $original_dir
34+
35+
cd ../flex-config
36+
osm2pgsql --slim --drop -d ${PGOSM_CONN} \
37+
--output=flex --style=run-all.lua \
38+
../tests/${filename}
39+
40+
cd $original_dir
41+
42+
done
43+
File renamed without changes.

0 commit comments

Comments
 (0)