Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void flexTripInTransitMode() {
EncodedPolyline legGeometry = EncodedPolyline.of(leg.legGeometry());
assertThatPolylinesAreEqual(
legGeometry.points(),
"kfsmEjojcOa@eBRKfBfHR|ALjBBhVArMG|OCrEGx@OhAKj@a@tAe@hA]l@MPgAnAgw@nr@cDxCm@t@c@t@c@x@_@~@]pAyAdIoAhG}@lE{AzHWhAtt@t~Aj@tAb@~AXdBHn@FlBC`CKnA_@nC{CjOa@dCOlAEz@E|BRtUCbCQ~CWjD??????qBvXBl@kBvWOzAc@dDOx@sHv]aIG?q@@c@ZaB\\mA"
"kfsmEjojcOa@eBRKfBfHR|ALjBBhVArMG|OCrEGx@OhAKj@a@tAe@hA]l@MPgAnAgw@nr@cDxCm@t@c@t@c@x@_@~@]pAyAdIoAhG}@lE{AzHWhAtt@t~Aj@tAb@~AXdBHn@FlBC`CKnA_@nC{CjOa@dCOlAEz@E|BRtUCbCQ~CWjD??qBvXBl@kBvWOzAc@dDOx@sHv]aIG?q@@c@ZaB\\mA"
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.opentripplanner.ext.transferanalyzer.annotations;

import java.util.List;
import org.locationtech.jts.geom.Geometry;
import org.opentripplanner.graph_builder.issue.api.DataImportIssue;
import org.opentripplanner.street.geometry.GeometryUtils;
Expand Down Expand Up @@ -63,11 +62,6 @@ public int getPriority() {

@Override
public Geometry getGeometry() {
return GeometryUtils.makeLineString(
List.of(
origin.getCoordinate().asJtsCoordinate(),
destination.getCoordinate().asJtsCoordinate()
)
);
return GeometryUtils.makeLineString(origin.getCoordinate(), destination.getCoordinate());
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.opentripplanner.model.plan.leg;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.LineString;
import org.opentripplanner.street.geometry.GeometryUtils;
import org.opentripplanner.transit.model.network.TripPattern;

/**
Expand All @@ -15,19 +14,15 @@ public class LegConstructionSupport {
* Given a pattern, board and alight stop index compute the list of coordinates that this
* segment of the pattern visits.
*/
public static List<Coordinate> extractTransitLegCoordinates(
public static LineString extractSubGeometry(
TripPattern tripPattern,
int boardStopIndexInPattern,
int alightStopIndexInPattern
) {
List<Coordinate> transitLegCoordinates = new ArrayList<>();

var lineStrings = new ArrayList<LineString>();
for (int i = boardStopIndexInPattern + 1; i <= alightStopIndexInPattern; i++) {
transitLegCoordinates.addAll(
Arrays.asList(tripPattern.getHopGeometry(i - 1).getCoordinates())
);
lineStrings.add(tripPattern.getHopGeometry(i - 1));
}

return transitLegCoordinates;
return GeometryUtils.concatenateLineStrings(lineStrings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Objects;
import java.util.Set;
import javax.annotation.Nullable;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.LineString;
import org.opentripplanner.core.model.accessibility.Accessibility;
import org.opentripplanner.core.model.basic.Cost;
Expand Down Expand Up @@ -120,15 +119,15 @@ protected ScheduledTransitLeg(ScheduledTransitLegBuilder<?> builder) {

this.generalizedCost = builder.generalizedCost();

List<Coordinate> transitLegCoordinates = LegConstructionSupport.extractTransitLegCoordinates(
LineString transitLegCoordinates = LegConstructionSupport.extractSubGeometry(
tripPattern,
boardStopPosInPattern,
alightStopPosInPattern
);
this.legGeometry = GeometryUtils.makeLineString(transitLegCoordinates);
this.legGeometry = transitLegCoordinates;

this.distanceMeters = DoubleUtils.roundTo2Decimals(
GeometryUtils.sumDistances(transitLegCoordinates)
GeometryUtils.sumDistances(transitLegCoordinates.getCoordinateSequence())
);
this.transitAlerts = Set.copyOf(builder.alerts());
this.fromViaLocationType = builder.fromViaLocationType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ private List<Leg> mapTransferLeg(
.withTo(to)
.withDistanceMeters(transfer.getDistanceMeters())
.withGeneralizedCost(toOtpDomainCost(pathLeg.c1()))
.withGeometry(GeometryUtils.makeLineString(transfer.getCoordinates()))
.withGeometry(transfer.getGeometry())
.withWalkSteps(List.of())
.build()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.opentripplanner.transfer.regular.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.LineString;
import org.opentripplanner.raptor.spi.RaptorCostConverter;
import org.opentripplanner.street.geometry.GeometryUtils;
import org.opentripplanner.street.model.StreetMode;
import org.opentripplanner.street.model.edge.Edge;
import org.opentripplanner.street.search.request.StreetSearchRequest;
Expand Down Expand Up @@ -49,17 +48,12 @@ public Transfer(int toStopIndex, int distanceMeters, EnumSet<StreetMode> modes)
this(toStopIndex, distanceMeters, modes, null);
}

public List<Coordinate> getCoordinates() {
List<Coordinate> coordinates = new ArrayList<>();
public LineString getGeometry() {
if (edges == null) {
return coordinates;
}
for (Edge edge : edges) {
if (edge.getGeometry() != null) {
coordinates.addAll((Arrays.asList(edge.getGeometry().getCoordinates())));
}
return GeometryUtils.getGeometryFactory().createLineString();
} else {
return GeometryUtils.concatenateLineStrings(edges, Edge::getGeometry);
}
return coordinates;
}

public int getToStop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"shortName": "RBUS"
},
"legGeometry": {
"points": "_{rc@_d{r@????_ibE_t`B"
"points": "_{rc@_d{r@??_ibE_t`B"
}
},
{
Expand Down Expand Up @@ -97,7 +97,7 @@
"shortName": "R2"
},
"legGeometry": {
"points": "_evi@_y|u@????_ibE_t`B"
"points": "_evi@_y|u@??_ibE_t`B"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.locationtech.jts.algorithm.ConvexHull;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.CoordinateSequence;
import org.locationtech.jts.geom.CoordinateSequenceFactory;
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryCollection;
Expand All @@ -31,7 +30,7 @@

public class GeometryUtils {

private static final CoordinateSequenceFactory CSF = new PackedCoordinateSequenceFactory();
private static final PackedCoordinateSequenceFactory CSF = new PackedCoordinateSequenceFactory();
private static final GeometryFactory GF = new GeometryFactory(CSF);

public static <T> Geometry makeConvexHull(
Expand All @@ -50,12 +49,8 @@ public static <T> Geometry makeConvexHull(
}

public static LineString makeLineString(double... coords) {
GeometryFactory factory = getGeometryFactory();
Coordinate[] coordinates = new Coordinate[coords.length / 2];
for (int i = 0; i < coords.length; i += 2) {
coordinates[i / 2] = new Coordinate(coords[i], coords[i + 1]);
}
return factory.createLineString(coordinates);
var seq = CSF.create(coords, 2);
return GF.createLineString(seq);
}

public static LineString makeLineString(List<Coordinate> coordinates) {
Expand Down Expand Up @@ -294,17 +289,6 @@ public static Stream<Envelope> toEnvelopes(LineString ls) {
return Arrays.stream(envelopes);
}

/**
* Returns the sum of the distances in between the pairs of coordinates in meters.
*/
public static double sumDistances(List<Coordinate> coordinates) {
double distance = 0;
for (int i = 1; i < coordinates.size(); i++) {
distance += SphericalDistanceLibrary.distance(coordinates.get(i - 1), coordinates.get(i));
}
return distance;
}

/// Returns the sum of the distances in between the pairs of coordinates in meters.
/// If the number of coordinates is empty or just one(a point), then `0` is returned.
public static double sumDistances(Coordinate[] coordinates) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.opentripplanner.street.model.edge;

import java.util.List;
import org.locationtech.jts.geom.LineString;
import org.opentripplanner.street.geometry.GeometryUtils;
import org.opentripplanner.street.model.vertex.StreetVertex;
Expand Down Expand Up @@ -40,7 +39,7 @@ protected int getStreetToStopTime() {

@Override
public LineString getGeometry() {
return GeometryUtils.makeLineString(List.of(fromv.getCoordinate(), tov.getCoordinate()));
return GeometryUtils.makeLineString(fromv.getX(), fromv.getY(), tov.getX(), tov.getY());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.opentripplanner.street.model.edge;

import java.util.List;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.LineString;
import org.opentripplanner.core.model.i18n.I18NString;
import org.opentripplanner.core.model.i18n.NonLocalizedString;
Expand All @@ -26,9 +24,7 @@ public class ElevatorBoardEdge extends Edge implements BikeWalkableEdge, Elevato

private ElevatorBoardEdge(Vertex from, ElevatorHopVertex to) {
super(from, to);
geometry = GeometryUtils.makeLineString(
List.of(new Coordinate(from.getX(), from.getY()), new Coordinate(to.getX(), to.getY()))
);
geometry = GeometryUtils.makeLineString(from.getX(), from.getY(), to.getX(), to.getY());
}

public static ElevatorBoardEdge createElevatorBoardEdge(Vertex from, ElevatorHopVertex to) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ void toEnvelopes() {

@Test
void sumDistances() {
var coordinates = List.of(BERLIN, HAMBURG);
var meters = GeometryUtils.sumDistances(coordinates);
var meters = GeometryUtils.sumDistances(new Coordinate[] { BERLIN, HAMBURG });
assertEquals(255_384.0, meters, 0.5);
}

Expand Down
Loading