-
Notifications
You must be signed in to change notification settings - Fork 309
Add bbox parameter #364
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
Closed
Closed
Add bbox parameter #364
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/de/komoot/photon/query/BoundingBoxParamConverter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package de.komoot.photon.query; | ||
|
||
import com.vividsolutions.jts.geom.Envelope; | ||
|
||
import de.komoot.photon.utils.Function; | ||
import spark.Request; | ||
|
||
/** | ||
* Converts the bbox parameter into an Envelope and performs format checking. | ||
* Created by Holger Bruch on 10/13/2018. | ||
*/ | ||
public class BoundingBoxParamConverter implements Function<Request, Envelope, BadRequestException> { | ||
|
||
private static final String INVALID_BBOX_ERROR_MESSAGE = "invalid search term 'bbox', expected format is: minLon,minLat,maxLon,maxLat"; | ||
|
||
@Override | ||
public Envelope apply(Request webRequest) throws BadRequestException { | ||
String bboxParam = webRequest.queryParams("bbox"); | ||
if (bboxParam == null) { | ||
return null; | ||
} | ||
Envelope bbox = null; | ||
try { | ||
String[] bboxCoords = bboxParam.split(","); | ||
if (bboxCoords.length != 4) { | ||
throw new BadRequestException(400, INVALID_BBOX_ERROR_MESSAGE); | ||
} | ||
Double minLon = Double.valueOf(bboxCoords[0]); | ||
Double minLat = Double.valueOf(bboxCoords[2]); | ||
Double maxLon = Double.valueOf(bboxCoords[1]); | ||
Double maxLat = Double.valueOf(bboxCoords[3]); | ||
if (minLon > 180.0 || minLon < -180.00 || maxLon > 180.0 || maxLon < -180.00) { | ||
throw new BadRequestException(400, INVALID_BBOX_ERROR_MESSAGE); | ||
} | ||
if (minLat > 90.0 || minLat < -90.00 || maxLat > 90.0 || maxLat < -90.00) { | ||
throw new BadRequestException(400, INVALID_BBOX_ERROR_MESSAGE); | ||
} | ||
bbox = new Envelope(minLon, minLat, maxLon, maxLat); | ||
} catch (NumberFormatException nfe) { | ||
throw new BadRequestException(400, INVALID_BBOX_ERROR_MESSAGE); | ||
} | ||
|
||
return bbox; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It would be important to mention which order the bbox has. Maybe we should also use a different order with left,bottom and right,top points ala
latSouth,lonWest,latNorth,lonEast
or why did you pick this order?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 are right, this should be documented. Concerning the order: to me this was the one I‘m used to, but Nomination and Overpass both use a different order.
Should I change it?
And before merging, I should add a verification of the lat/lon limits.
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.
Up, not necessary. I confused the APIs ;)
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.
Did you change the order now? Because I read from the code below that you expect <minLon, maxLon, minLat, maxLat>. My preference would be as documented: <minLon,minLat,maxLon,maxLat>. (Or to be precise: <x1,y1,x2,y2>, Envelope() does not seem to care if it is min,max or max,min.)
Just to mention it, the odd boundingbox format of Nominatim is only used for output. The viewbox input parameter also expects <minLon,minLat,maxLon,maxLat>.
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.
As you have a preference then we should do x1,y1,x2,y2