-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add distance for stop-to-stop shapes, PointsOnLink in Transmodel API #6982
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
Open
t2gran
wants to merge
8
commits into
opentripplanner:dev-2.x
Choose a base branch
from
entur:distance-on-service-links
base: dev-2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
51a59d2
refactor: remove Serializable implementation from EncodedPolyline
t2gran 8f33334
refactor: Lazy initialize EncodedPolyline
t2gran c9fa3da
refactor: Rename EncodedPolyline encode() -> of()
t2gran 86b1740
refactor: Remove dependency from ElevationModule to EncodedPolyline
t2gran 8c7af15
refactor: Move EncodedPolyline to o.o.api.model.geometry
t2gran 4bb3070
feat: Add sumDistances method to calculate total distance between coo…
t2gran 7006b61
feat: Add distance calculation to EncodedPolyline and expose it in Gr…
t2gran 56aa376
doc: Add enhanced PolylineEncoder documentation
t2gran 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
85 changes: 85 additions & 0 deletions
85
application/src/main/java/org/opentripplanner/api/model/geometry/EncodedPolyline.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,85 @@ | ||
| package org.opentripplanner.api.model.geometry; | ||
|
|
||
| import java.util.Objects; | ||
| import org.locationtech.jts.geom.Geometry; | ||
| import org.opentripplanner.framework.geometry.GeometryUtils; | ||
| import org.opentripplanner.framework.geometry.PolylineEncoder; | ||
| import org.opentripplanner.utils.tostring.ToStringBuilder; | ||
|
|
||
| /** | ||
| * A list of coordinates encoded as a string, the length (number of coordinates) and the distance. | ||
| * <p> | ||
| * See <a href="http://code.google.com/apis/maps/documentation/polylinealgorithm.html">Encoded | ||
| * polyline algorithm format</a> | ||
| * | ||
| * The attributes are lazy initialized to avoid unnecessary computation in case only the | ||
| * line-string or the distance is requested, or none. | ||
| * | ||
| * THIS CLASS IS NOT THREAD-SAFE. | ||
| */ | ||
| public final class EncodedPolyline { | ||
|
|
||
| private static final int NOT_SET = -1; | ||
| private final Geometry geometry; | ||
|
|
||
| private String points = null; | ||
| private int length = NOT_SET; | ||
| private int distance_m = NOT_SET; | ||
|
|
||
| private EncodedPolyline(Geometry geometry) { | ||
| this.geometry = geometry; | ||
| } | ||
|
|
||
| public static EncodedPolyline of(Geometry geometry) { | ||
| return new EncodedPolyline(geometry); | ||
| } | ||
|
|
||
| public String points() { | ||
| calculateLineString(); | ||
| return points; | ||
| } | ||
|
|
||
| public int length() { | ||
| calculateLineString(); | ||
| return length; | ||
| } | ||
|
|
||
| public int distanceInMeters() { | ||
| calculateDistance(); | ||
| return distance_m; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| EncodedPolyline that = (EncodedPolyline) o; | ||
| return length() == that.length() && Objects.equals(points(), that.points()); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(points(), length()); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return ToStringBuilder.of("EncodedPolyline") | ||
| .addNum("length", length()) | ||
| .addObj("points", points()) | ||
| .toString(); | ||
| } | ||
|
|
||
| private void calculateLineString() { | ||
| if (length == NOT_SET) { | ||
| var line = PolylineEncoder.encodeGeometry(geometry); | ||
| this.points = line.points(); | ||
| this.length = line.length(); | ||
| } | ||
| } | ||
|
|
||
| private void calculateDistance() { | ||
| if (distance_m == NOT_SET) { | ||
| distance_m = (int) GeometryUtils.sumDistances(geometry.getCoordinates()); | ||
| } | ||
| } | ||
| } |
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
2 changes: 1 addition & 1 deletion
2
...ava/org/opentripplanner/apis/transmodel/model/framework/EncodedPolylineBeanWithStops.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
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
17 changes: 0 additions & 17 deletions
17
application/src/main/java/org/opentripplanner/framework/geometry/EncodedPolyline.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
Oops, something went wrong.
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.
I haven't seen markdown comments in OTP before, do you think we should start using them even though they're not really supported until java 23?
It will be nice to not have to write html