-
Notifications
You must be signed in to change notification settings - Fork 309
Bbox #421
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
Merged
Merged
Bbox #421
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cfd2083
Add bbox parameter
hbruch f6f5dfb
Add documentation and validation of bbox coords order
hbruch 56c299b
slightly improved readability
Gerungofulus b729e93
fixed broken bounding box creation from input params
Gerungofulus a51ff29
added test for wrong longitude
Gerungofulus 9b773f9
added proper tests and new exception description
Gerungofulus 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.
There is a double error in here that happens to cancel itself out. bbox above is parsed as (minLon, maxLon, minLat, maxLat) while it should be (minLon, minLat, MaxLon, MaxLat). In the constructor for Envelope the exact reverse is true.
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.
Changed code according to the documentation