From e55ac77c9441359a44e5c4d464353a7970a648c7 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sun, 6 Aug 2017 18:42:04 +0200 Subject: [PATCH] add simple tests for postcode import --- test/bdd/db/import/postcodes.feature | 115 ++++++++++++++++++ test/bdd/steps/db_ops.py | 2 +- .../scenes/data/building-on-street-corner.wkt | 2 +- test/scenes/data/poly-area.wkt | 22 ++-- test/scenes/data/way-area-with-center.wkt | 8 +- utils/setup.php | 2 +- 6 files changed, 133 insertions(+), 18 deletions(-) create mode 100644 test/bdd/db/import/postcodes.feature diff --git a/test/bdd/db/import/postcodes.feature b/test/bdd/db/import/postcodes.feature new file mode 100644 index 00000000..be469fe6 --- /dev/null +++ b/test/bdd/db/import/postcodes.feature @@ -0,0 +1,115 @@ +@DB +Feature: Import of postcodes + Tests for postcode estimation + + Scenario: Postcodes on the object are prefered over those on the address + Given the scene admin-areas + And the named places + | osm | class | type | admin | addr+postcode | geometry | + | R1 | boundary | administrative | 6 | 112 | :b0 | + | R34 | boundary | administrative | 8 | 112 DE | :b1:E | + | R4 | boundary | administrative | 10 | 112 DE 34 | :b2:N | + And the named places + | osm | class | type | addr+postcode | geometry | + | W93 | highway | residential | 112 DE 344 | :w2N | + | W22 | building | yes | 112 DE 344N | :building:w2N | + When importing + Then placex contains + | object | postcode | + | W22 | 112 DE 344N | + | W93 | 112 DE 344 | + | R4 | 112 DE 34 | + | R34 | 112 DE | + | R1 | 112 | + + Scenario: Postcodes from a road are inherited by an attached building + Given the scene admin-areas + And the named places + | osm | class | type | addr+postcode | geometry | + | W93 | highway | residential | 86034 | :w2N | + And the named places + | osm | class | type | geometry | + | W22 | building | yes | :building:w2N | + When importing + Then placex contains + | object | postcode | parent_place_id | + | W22 | 86034 | W93 | + + Scenario: Postcodes from the lowest admin area are inherited by ways + Given the scene admin-areas + And the named places + | osm | class | type | admin | addr+postcode | geometry | + | R1 | boundary | administrative | 6 | 112 | :b0 | + | R34 | boundary | administrative | 8 | 112 DE | :b1:E | + | R4 | boundary | administrative | 10 | 112 DE 34 | :b2:N | + And the named places + | osm | class | type | geometry | + | W93 | highway | residential | :w2N | + When importing + Then placex contains + | object | postcode | + | W93 | 112 DE 34 | + + Scenario: Postcodes from the lowest admin area with postcode are inherited by ways + Given the scene admin-areas + And the named places + | osm | class | type | admin | addr+postcode | geometry | + | R1 | boundary | administrative | 6 | 112 | :b0 | + | R34 | boundary | administrative | 8 | 112 DE | :b1:E | + And the named places + | osm | class | type | admin | geometry | + | R4 | boundary | administrative | 10 | :b2:N | + And the named places + | osm | class | type | geometry | + | W93 | highway | residential | :w2N | + When importing + Then placex contains + | object | postcode | parent_place_id | + | W93 | 112 DE | R4 | + + Scenario: Postcodes from the lowest admin area are inherited by buildings + Given the scene admin-areas + And the named places + | osm | class | type | admin | addr+postcode | geometry | + | R1 | boundary | administrative | 6 | 112 | :b0 | + | R34 | boundary | administrative | 8 | 112 DE | :b1:E | + | R4 | boundary | administrative | 10 | 112 DE 34 | :b2:N | + And the named places + | osm | class | type | geometry | + | W22 | building | yes | :building:w2N | + When importing + Then placex contains + | object | postcode | + | W22 | 112 DE 34 | + + Scenario: Roads get postcodes from nearby buildings without other info + Given the scene admin-areas + And the named places + | osm | class | type | geometry | + | W93 | highway | residential | :w2N | + And the named places + | osm | class | type | addr+postcode | geometry | + | W22 | building | yes | 445023 | :building:w2N | + When importing + Then placex contains + | object | postcode | + | W93 | 445023 | + + @wip + Scenario: Postcodes from admin boundaries are preferred over estimated postcodes + Given the scene admin-areas + And the named places + | osm | class | type | admin | addr+postcode | geometry | + | R1 | boundary | administrative | 6 | 112 | :b0 | + | R34 | boundary | administrative | 8 | 112 DE | :b1:E | + | R4 | boundary | administrative | 10 | 112 DE 34 | :b2:N | + And the named places + | osm | class | type | geometry | + | W93 | highway | residential | :w2N | + And the named places + | osm | class | type | addr+postcode | geometry | + | W22 | building | yes | 445023 | :building:w2N | + When importing + Then placex contains + | object | postcode | + | W93 | 112 DE 34 | diff --git a/test/bdd/steps/db_ops.py b/test/bdd/steps/db_ops.py index fa8cd0de..be2211fa 100644 --- a/test/bdd/steps/db_ops.py +++ b/test/bdd/steps/db_ops.py @@ -287,7 +287,7 @@ def import_and_index_data_from_place_table(context): WHERE class='place' and type='houses' and osm_type='W' and ST_GeometryType(geometry) = 'ST_LineString'""") context.db.commit() - context.nominatim.run_setup_script('index', 'index-noanalyse') + context.nominatim.run_setup_script('calculate-postcodes', 'index', 'index-noanalyse') @when("updating places") def update_place_table(context): diff --git a/test/scenes/data/building-on-street-corner.wkt b/test/scenes/data/building-on-street-corner.wkt index 4c007e9e..24da78f1 100644 --- a/test/scenes/data/building-on-street-corner.wkt +++ b/test/scenes/data/building-on-street-corner.wkt @@ -4,4 +4,4 @@ n-outer | POINT(1.0039478 2.0004676) n-edge-WE | POINT(1.0039599 2.0002345) w-WE | LINESTRING(1.0031759 2.0002316,1.0040361 2.0002211,1.0042735 2.0002264) w-NS | LINESTRING(1.0040414 2.0001051,1.0040361 2.0002211,1.0040364 2.0006377) -w-building | MULTIPOLYGON(((1.0040019 2.000324,1.0040016 2.0002344,1.0039599 2.0002345,1.0039037 2.0002347,1.0039043 2.0004389,1.0040023 2.0004386,1.0040019 2.000324))) +w-building | MULTIPOLYGON(((1.0039037 2.0002347,1.0039599 2.0002345,1.0040016 2.0002344,1.0040019 2.000324,1.0040023 2.0004386,1.0039043 2.0004389,1.0039037 2.0002347))) diff --git a/test/scenes/data/poly-area.wkt b/test/scenes/data/poly-area.wkt index a8fb045d..e65f2054 100644 --- a/test/scenes/data/poly-area.wkt +++ b/test/scenes/data/poly-area.wkt @@ -1,11 +1,11 @@ -0.0001 | MULTIPOLYGON(((0.001 0,0 0,0 0.1,0.001 0.1,0.001 0))) -0.0005 | MULTIPOLYGON(((0.005 0,0 0,0 0.1,0.005 0.1,0.005 0))) -0.001 | MULTIPOLYGON(((0.01 0,0 0,0 0.1,0.01 0.1,0.01 0))) -0.005 | MULTIPOLYGON(((0.05 0,0 0,0 0.1,0.05 0.1,0.05 0))) -0.01 | MULTIPOLYGON(((0.1 0,0 0,0 0.1,0.1 0.1,0.1 0))) -0.05 | MULTIPOLYGON(((0.5 0,0 0,0 0.1,0.5 0.1,0.5 0))) -0.1 | MULTIPOLYGON(((0.1 0,0 0,0 1,0.1 1,0.1 0))) -0.5 | MULTIPOLYGON(((0.5 0,0 0,0 1,0.5 1,0.5 0))) -1.0 | MULTIPOLYGON(((1 0,0 0,0 1,1 1,1 0))) -2.0 | MULTIPOLYGON(((2 0,0 0,0 1,2 1,2 0))) -5.0 | MULTIPOLYGON(((5 0,0 0,0 1,5 1,5 0))) +0.0001 | MULTIPOLYGON(((0 0,0.001 0,0.001 0.1,0 0.1,0 0))) +0.0005 | MULTIPOLYGON(((0 0,0.005 0,0.005 0.1,0 0.1,0 0))) +0.001 | MULTIPOLYGON(((0 0,0.01 0,0.01 0.1,0 0.1,0 0))) +0.005 | MULTIPOLYGON(((0 0,0.05 0,0.05 0.1,0 0.1,0 0))) +0.01 | MULTIPOLYGON(((0 0,0.1 0,0.1 0.1,0 0.1,0 0))) +0.05 | MULTIPOLYGON(((0 0,0.5 0,0.5 0.1,0 0.1,0 0))) +0.1 | MULTIPOLYGON(((0 0,0.1 0,0.1 1,0 1,0 0))) +0.5 | MULTIPOLYGON(((0 0,0.5 0,0.5 1,0 1,0 0))) +1.0 | MULTIPOLYGON(((0 0,1 0,1 1,0 1,0 0))) +2.0 | MULTIPOLYGON(((0 0,2 0,2 1,0 1,0 0))) +5.0 | MULTIPOLYGON(((0 0,5 0,5 1,0 1,0 0))) diff --git a/test/scenes/data/way-area-with-center.wkt b/test/scenes/data/way-area-with-center.wkt index 8a773633..ed34cd3b 100644 --- a/test/scenes/data/way-area-with-center.wkt +++ b/test/scenes/data/way-area-with-center.wkt @@ -1,5 +1,5 @@ -inner-C | POINT(0.0035625 -0.0066188) -outer-C | POINT(0.0041244 -0.0060007) -inner-N | POINT(0.0018846 -0.0023652) inner-S | POINT(0.0048516 -0.0095176) -area | MULTIPOLYGON(((0.0077125 -0.0066566,0.0065469 -0.0099414,0.0038979 -0.0109481,0.0026794 -0.0105772,0.0022025 -0.0099944,0.0026264 -0.0091997,0.0026264 -0.0080341,0.0019376 -0.0065507,0.0010369 -0.0072924,0.0005071 -0.0060738,0.0017787 -0.00565,0.0005071 -0.0042195,0.0005601 -0.0025771,0.0013019 -0.0015175,0.0050105 -0.0021533,0.006441 -0.0025771,0.0075006 -0.0040076,0.0033681 -0.0059149,0.0051694 -0.0076633,0.0061231 -0.0064977,0.0068648 -0.0049612,0.0077125 -0.0066566))) +inner-N | POINT(0.0018846 -0.0023652) +outer-C | POINT(0.0041244 -0.0060007) +inner-C | POINT(0.0035625 -0.0066188) +area | MULTIPOLYGON(((0.0005071 -0.0060738,0.0010369 -0.0072924,0.0019376 -0.0065507,0.0026264 -0.0080341,0.0026264 -0.0091997,0.0022025 -0.0099944,0.0026794 -0.0105772,0.0038979 -0.0109481,0.0065469 -0.0099414,0.0077125 -0.0066566,0.0068648 -0.0049612,0.0061231 -0.0064977,0.0051694 -0.0076633,0.0033681 -0.0059149,0.0075006 -0.0040076,0.006441 -0.0025771,0.0050105 -0.0021533,0.0013019 -0.0015175,0.0005601 -0.0025771,0.0005071 -0.0042195,0.0017787 -0.00565,0.0005071 -0.0060738))) diff --git a/utils/setup.php b/utils/setup.php index 5236a827..67c7fd7f 100755 --- a/utils/setup.php +++ b/utils/setup.php @@ -541,7 +541,7 @@ if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) { } } $sSQL = "SELECT count(getorcreate_postcode_id(v)) FROM "; - $sSQL .= "(SELECT distinct(postcode) FROM location_postcode) p"; + $sSQL .= "(SELECT distinct(postcode) as v FROM location_postcode) p"; if (!pg_query($oDB->connection, $sSQL)) { fail(pg_last_error($oDB->connection)); -- 2.39.5