-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option for polygon/linestring in results #823
base: master
Are you sure you want to change the base?
Conversation
I haven't done a full review yet but I do have some general thoughts on the implementation:
Two other considerations come in mind but they are easily deferred to follow-up PRs:
|
Thanks. I will update the PR with the changes in this file soon. One question though about the 'Elasticsearch is on it's way out': I've been planning to update the Elastic client to the Java API so you can use an existing Elasticsearch cluster instead of the internal one (newer versions of Elasticsearch don't support the Transport client). Is my new PR still a good idea?
Will take this along as well.
Agreed
OK. I will make the default to return the polygon when it's available in the index. The option 'polygon=false' will return the centroid instead.
Will do.
I have to look into this issue.
I will look into this. |
We'll drop ES support completely and go with OpenSearch. Note that the OS version already supports an external OpenSearch cluster. The support is just somewhat rudimentary and HTTP-only. |
Would this PR return a Multipolygon in case for queries like "hamburg"? See the nominatim response. Currently photon returns a slightly confusing, but correct extent as only a single extent is allowed https://photon.komoot.io/api/?q=hamburg ... or maybe we add a new field |
Yes, it would return a Polygon like Nominatim does. |
Done
Done
Done I'm looking forward to your response :) |
Sorry for the long delay in responding. I've decided to get a release out first before looking into this again. Because of this there is a minor merge conflict now regarding the dependencies. Also, the opensearch variant doesn't compile because |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of more comments after trying this out. The OpenSearch version currently doesn't work at all. It already fails to import.
The output for the ElasticSearch version displays a wrong projection:
...
"geometry": {
"coordinates":[9.5227103,47.1395576],
"type":"Point",
"crs":{"type":"name","properties":{"name":"EPSG:0"}}
}
...
Photon doesn't supply a CRS at all with the geometry. I'd leave it at that.
} | ||
|
||
if (!supportPolygons && (photonRequest.isPolygonRequest() && photonRequest.getReturnPolygon())) { | ||
throw new BadRequestException(400, "You're requesting a polygon, but polygons are not imported!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to throw a halt
at this point and make sure the content is json formatted, see line 43 above.
returnPolygon = photonRequest.getReturnPolygon(); | ||
} | ||
|
||
if (!supportPolygons && (photonRequest.isPolygonRequest() && photonRequest.getReturnPolygon())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check comes to late. Parameter need to be tested and rejected before the actual search is done (around line 45).
@@ -51,6 +51,6 @@ public String handle(Request request, Response response) { | |||
debugInfo = requestHandler.dumpQuery(photonRequest); | |||
} | |||
*/ | |||
return new GeocodeJsonFormatter(photonRequest.getDebug(), photonRequest.getLanguage()).convert(results, debugInfo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect the same code here as in the SearchRequestHandler (check if available etc.)
@@ -53,6 +53,6 @@ public String handle(Request request, Response response) { | |||
debugInfo = requestHandler.dumpQuery(photonRequest); | |||
} | |||
|
|||
return new GeocodeJsonFormatter(false, photonRequest.getLanguage()).convert(results, debugInfo); | |||
return new GeocodeJsonFormatter(false, photonRequest.getLanguage(), photonRequest.getPolygon()).convert(results, debugInfo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect the same code here as in the SearchRequestHandler (check if available etc.)
@@ -24,7 +24,7 @@ | |||
public class NominatimConnector { | |||
private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(NominatimConnector.class); | |||
|
|||
private static final String SELECT_COLS_PLACEX = "SELECT place_id, osm_type, osm_id, class, type, name, postcode, address, extratags, ST_Envelope(geometry) AS bbox, parent_place_id, linked_place_id, rank_address, rank_search, importance, country_code, centroid"; | |||
private static final String SELECT_COLS_PLACEX = "SELECT place_id, osm_type, osm_id, class, type, name, postcode, address, extratags, ST_Envelope(geometry) AS bbox, parent_place_id, linked_place_id, rank_address, rank_search, importance, country_code, centroid, geometry"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Geometries can become very large, so should only be added to the returned columns when really needed.
|
||
if (webRequest.queryParams("polygon") != null) { | ||
request.setPolygonRequest(true); | ||
request.setReturnPolygon(Boolean.parseBoolean(webRequest.queryParams("polygon"))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd need a full parsing function here that throws on unknown values. Question is if we should allow 0/1, yes/no besides true/false.
At the moment, photon only returns the point of a location, and not the polygon (see #259). This PR will add the option to add the polygon (i.e. geometry) to the Elasticsearch Index and a API parameter
polygon
to return said polygon. If no polygon exists, the point is returned.WARNING: This will increase the Elasticsearch Index size! (~575GB for a Planet import).
To enable: add the command line argument
-use-geometry-column
whilst importing and add&polygon=true
to the API call.