Skip to content
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

JTS geometries in Place #50

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/main/java/org/opentripplanner/client/model/Place.java
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -9,4 +13,26 @@ public record Place(
Optional<Stop> stop,
Optional<VehicleRentalStation> vehicleRentalStation,
Optional<RentalVehicle> rentalVehicle,
Optional<VehicleParking> vehicleParking) {}
Optional<VehicleParking> 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 <a
* href="https://gtfs.org/schedule/reference/#field-types">GTFSdoc </a>.
*/
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());
}
}
9 changes: 8 additions & 1 deletion src/test/java/org/opentripplanner/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,17 @@ 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());

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());

Expand Down