Merge branch 'geojson-output' of https://github.com/mtmail/Nominatim into mtmail-geojson-output

This commit is contained in:
Sarah Hoffmann
2018-07-06 20:26:33 +02:00
17 changed files with 455 additions and 23 deletions

View File

@@ -8,9 +8,10 @@ Feature: Places by osm_type and osm_id Tests
And exactly 3 results are returned
Examples:
| format |
| xml |
| json |
| format |
| xml |
| json |
| geojson |
Scenario: address lookup for non-existing or invalid node, way, relation
When sending xml lookup query for X99,,N0,nN158845944,ABC,,W9

View File

@@ -13,6 +13,7 @@ Feature: Parameters for Reverse API
| format |
| json |
| jsonv2 |
| geojson |
| xml |
Scenario Outline: Coordinates must be floating-point numbers
@@ -35,6 +36,7 @@ Feature: Parameters for Reverse API
| xml |
| json |
| jsonv2 |
| geojson |
Scenario Outline: Reverse Geocoding with namedetails
When sending <format> reverse coordinates 10.776455623137625,106.70175343751907
@@ -47,6 +49,7 @@ Feature: Parameters for Reverse API
| xml |
| json |
| jsonv2 |
| geojson |
Scenario Outline: Reverse Geocoding contains TEXT geometry
When sending <format> reverse coordinates 47.165989816710066,9.515774846076965
@@ -107,5 +110,18 @@ Feature: Parameters for Reverse API
| xml | geojson |
| json | geojson |
| jsonv2 | geojson |
| geojson | geojson |
Scenario Outline: Reverse Geocoding in geojson format contains no non-geojson geometry
When sending geojson reverse coordinates 47.165989816710066,9.515774846076965
| polygon_text | polygon | polygon_svg | polygon_geokml |
| 1 | 1 | 1 | 1 |
Then result 0 has not attributes <response_attribute>
Examples:
| response_attribute |
| geotext |
| polygonpoints |
| svg |
| geokml |

View File

@@ -11,6 +11,8 @@ Feature: Simple Reverse Tests
Then the result is valid json
When sending jsonv2 reverse coordinates <lat>,<lon>
Then the result is valid json
When sending geojson reverse coordinates <lat>,<lon>
Then the result is valid geojson
When sending html reverse coordinates <lat>,<lon>
Then the result is valid html
@@ -42,6 +44,10 @@ Feature: Simple Reverse Tests
| param | value |
| <parameter> | <value> |
Then the result is valid json
When sending geojson reverse coordinates 53.603,10.041
| param | value |
| <parameter> | <value> |
Then the result is valid geojson
Examples:
| parameter | value |
@@ -60,12 +66,13 @@ Feature: Simple Reverse Tests
When sending <format> reverse coordinates 67.3245,0.456
| json_callback |
| foo |
Then the result is valid json
Then the result is valid <outformat>
Examples:
| format |
| json |
| jsonv2 |
| format | outformat |
| json | json |
| jsonv2 | json |
| geojson | geojson |
Scenario Outline: Boundingbox is returned
When sending <format> reverse coordinates 14.62,108.1
@@ -77,6 +84,7 @@ Feature: Simple Reverse Tests
| format |
| json |
| jsonv2 |
| geojson |
| xml |
Scenario Outline: Reverse-geocoding with zoom
@@ -89,6 +97,7 @@ Feature: Simple Reverse Tests
| format |
| json |
| jsonv2 |
| geojson |
| html |
| xml |

View File

@@ -276,6 +276,7 @@ Feature: Search queries
| xml |
| json |
| jsonv2 |
| geojson |
Scenario Outline: Search with namedetails
When sending <format> search query "Hauptstr"
@@ -288,6 +289,7 @@ Feature: Search queries
| xml |
| json |
| jsonv2 |
| geojson |
Scenario Outline: Search result with contains TEXT geometry
When sending <format> search query "Highmore"
@@ -348,6 +350,20 @@ Feature: Search queries
| xml | geojson |
| json | geojson |
| jsonv2 | geojson |
| geojson | geojson |
Scenario Outline: Search result in geojson format contains no non-geojson geometry
When sending geojson search query "Highmore"
| polygon_text | polygon | polygon_svg | polygon_geokml |
| 1 | 1 | 1 | 1 |
Then result 0 has not attributes <response_attribute>
Examples:
| response_attribute |
| geotext |
| polygonpoints |
| svg |
| geokml |
Scenario: Search along a route
When sending json search query "restaurant" with address
@@ -356,3 +372,5 @@ Feature: Search queries
Then result addresses contain
| city |
| Rapid City |

View File

@@ -23,6 +23,10 @@ Feature: Simple Tests
| param | value |
| <parameter> | <value> |
Then at least 1 result is returned
When sending geojson search query "Hamburg"
| param | value |
| <parameter> | <value> |
Then at least 1 result is returned
Examples:
| parameter | value |
@@ -68,6 +72,8 @@ Feature: Simple Tests
Then the result is valid json
When sending jsonv2 search query "<query>"
Then the result is valid json
When sending geojson search query "<query>"
Then the result is valid geojson
Examples:
| query |

View File

@@ -110,6 +110,10 @@ class SearchResponse(GenericResponse):
self.header['json_func'] = m.group(1)
self.result = json.JSONDecoder(object_pairs_hook=OrderedDict).decode(code)
def parse_geojson(self):
self.parse_json()
self.result = geojson_results_to_json_results(self.result)
def parse_html(self):
content, errors = tidy_document(self.page,
options={'char-encoding' : 'utf8'})
@@ -185,6 +189,12 @@ class ReverseResponse(GenericResponse):
self.header['json_func'] = m.group(1)
self.result = [json.JSONDecoder(object_pairs_hook=OrderedDict).decode(code)]
def parse_geojson(self):
self.parse_json()
if 'error' in self.result:
return
self.result = geojson_results_to_json_results(self.result[0])
def parse_xml(self):
et = ET.fromstring(self.page)
@@ -250,6 +260,27 @@ class StatusResponse(GenericResponse):
self.result = [json.JSONDecoder(object_pairs_hook=OrderedDict).decode(self.page)]
def geojson_result_to_json_result(geojson_result):
result = geojson_result['properties']
result['geojson'] = geojson_result['geometry']
if 'bbox' in geojson_result:
# bbox is minlon, minlat, maxlon, maxlat
# boundingbox is minlat, maxlat, minlon, maxlon
result['boundingbox'] = [
geojson_result['bbox'][1],
geojson_result['bbox'][3],
geojson_result['bbox'][0],
geojson_result['bbox'][2]
]
return result
def geojson_results_to_json_results(geojson_results):
if 'error' in geojson_results:
return
return list(map(geojson_result_to_json_result, geojson_results['features']))
@when(u'searching for "(?P<query>.*)"(?P<dups> with dups)?')
def query_cmd(context, query, dups):
""" Query directly via PHP script.
@@ -414,6 +445,8 @@ def website_lookup_request(context, fmt, query):
if fmt == 'json ':
outfmt = 'json'
elif fmt == 'geojson ':
outfmt = 'geojson'
else:
outfmt = 'xml'