From 18b8b1099c23aa103c4aa5c89877d2b6c28efaa9 Mon Sep 17 00:00:00 2001 From: Tobias Walter Date: Thu, 20 Jun 2024 13:33:43 +0200 Subject: [PATCH 1/2] feat(trip plan): add JTS point, geometry as getter --- .../opentripplanner/client/model/Place.java | 28 ++++++++++++++++++- .../org/opentripplanner/IntegrationTest.java | 4 +++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/opentripplanner/client/model/Place.java b/src/main/java/org/opentripplanner/client/model/Place.java index fcc69ac..01be86a 100644 --- a/src/main/java/org/opentripplanner/client/model/Place.java +++ b/src/main/java/org/opentripplanner/client/model/Place.java @@ -1,6 +1,10 @@ package org.opentripplanner.client.model; import java.util.Optional; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.Point; +import org.locationtech.jts.geom.PrecisionModel; public record Place( String name, @@ -9,4 +13,26 @@ public record Place( Optional stop, Optional vehicleRentalStation, Optional rentalVehicle, - Optional vehicleParking) {} + Optional vehicleParking) { + + private static final int DEFAULT_SRID = 4326; + + /** create a JTS Geometry */ + public Coordinate coordinate() { + return new Coordinate(lon, lat); + } + + /** + * Return the geometry as JTF Point which defaults to SRID as defined in GTFSdoc . + */ + public Point point() { + return point(DEFAULT_SRID); + } + + /** creates a JTS Point by a passed SRID */ + public Point point(int SRID) { + GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), SRID); + return geometryFactory.createPoint(coordinate()); + } +} diff --git a/src/test/java/org/opentripplanner/IntegrationTest.java b/src/test/java/org/opentripplanner/IntegrationTest.java index 6fb6be3..65e0951 100644 --- a/src/test/java/org/opentripplanner/IntegrationTest.java +++ b/src/test/java/org/opentripplanner/IntegrationTest.java @@ -65,7 +65,11 @@ public void plan() throws IOException { var transitLeg = result.transitItineraries().get(0).transitLegs().get(0); assertFalse(transitLeg.from().stop().isEmpty()); + assertNotNull(transitLeg.from().coordinate()); + assertNotNull(transitLeg.from().point()); assertFalse(transitLeg.to().stop().isEmpty()); + assertNotNull(transitLeg.to().coordinate()); + assertNotNull(transitLeg.to().point()); assertNotNull(transitLeg.from().stop().get().id()); assertTrue(transitLeg.trip().headsign().isPresent()); From ea97d5679e529a52d3888af98cc2ddc20e46d765 Mon Sep 17 00:00:00 2001 From: Tobias Walter Date: Thu, 20 Jun 2024 13:35:51 +0200 Subject: [PATCH 2/2] test(trap plan): add tests for transit legs --- src/test/java/org/opentripplanner/IntegrationTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/opentripplanner/IntegrationTest.java b/src/test/java/org/opentripplanner/IntegrationTest.java index 65e0951..9ccde6f 100644 --- a/src/test/java/org/opentripplanner/IntegrationTest.java +++ b/src/test/java/org/opentripplanner/IntegrationTest.java @@ -72,7 +72,10 @@ public void plan() throws IOException { assertNotNull(transitLeg.to().point()); assertNotNull(transitLeg.from().stop().get().id()); assertTrue(transitLeg.trip().headsign().isPresent()); - + assertNotNull(transitLeg.agency()); + assertNotNull(transitLeg.intermediatePlaces().get().get(0).name()); + assertNotNull(transitLeg.intermediatePlaces().get().get(0).departureTime()); + assertNotNull(transitLeg.intermediatePlaces().get().get(0).arrivalTime()); assertNotNull(transitLeg.geometry().toGoogleEncoding()); assertNotNull(transitLeg.geometry().toLinestring());