use of org.locationtech.jts.linearref.LocationIndexedLine in project OpenTripPlanner by opentripplanner.
the class SimpleStreetSplitter method link.
/**
* split the edge and link in the transit stop
*/
private void link(Vertex tstop, StreetEdge edge, double xscale, RoutingRequest options) {
// TODO: we've already built this line string, we should save it
LineString orig = edge.getGeometry();
LineString transformed = equirectangularProject(orig, xscale);
LocationIndexedLine il = new LocationIndexedLine(transformed);
LinearLocation ll = il.project(new Coordinate(tstop.getLon() * xscale, tstop.getLat()));
// street to use the same vertices. Otherwise the order the stops are loaded in will affect where they are snapped.
if (ll.getSegmentIndex() == 0 && ll.getSegmentFraction() < 1e-8) {
makeLinkEdges(tstop, (StreetVertex) edge.getFromVertex());
} else // past the last point
if (ll.getSegmentIndex() == orig.getNumPoints() - 1) {
makeLinkEdges(tstop, (StreetVertex) edge.getToVertex());
} else // nPoints - 2: -1 to correct for index vs count, -1 to account for fencepost problem
if (ll.getSegmentIndex() == orig.getNumPoints() - 2 && ll.getSegmentFraction() > 1 - 1e-8) {
makeLinkEdges(tstop, (StreetVertex) edge.getToVertex());
} else {
TemporaryVertex temporaryVertex = null;
boolean endVertex = false;
if (tstop instanceof TemporaryVertex) {
temporaryVertex = (TemporaryVertex) tstop;
endVertex = temporaryVertex.isEndVertex();
}
// split the edge, get the split vertex
SplitterVertex v0 = split(edge, ll, temporaryVertex != null, endVertex);
makeLinkEdges(tstop, v0);
// edges that were missed by WalkableAreaBuilder
if (edge instanceof AreaEdge && tstop instanceof TransitStopVertex && this.addExtraEdgesToAreas) {
linkTransitToAreaVertices(v0, ((AreaEdge) edge).getArea());
}
}
}
use of org.locationtech.jts.linearref.LocationIndexedLine in project OpenTripPlanner by opentripplanner.
the class GeometryAndBlockProcessor method getGeometriesByShape.
private LineString[] getGeometriesByShape(List<StopTime> stopTimes, FeedScopedId shapeId, LineString shape, List<LinearLocation> locations) {
LineString[] geoms = new LineString[stopTimes.size() - 1];
Iterator<LinearLocation> locationIt = locations.iterator();
LinearLocation endLocation = locationIt.next();
double distanceSoFar = 0;
int last = 0;
for (int i = 0; i < stopTimes.size() - 1; ++i) {
LinearLocation startLocation = endLocation;
endLocation = locationIt.next();
// it does not matter at all if this is accurate so long as it is consistent
for (int j = last; j < startLocation.getSegmentIndex(); ++j) {
Coordinate from = shape.getCoordinateN(j);
Coordinate to = shape.getCoordinateN(j + 1);
double xd = from.x - to.x;
double yd = from.y - to.y;
distanceSoFar += FastMath.sqrt(xd * xd + yd * yd);
}
last = startLocation.getSegmentIndex();
double startIndex = distanceSoFar + startLocation.getSegmentFraction() * startLocation.getSegmentLength(shape);
// advance distanceSoFar up to start of segment containing endLocation
for (int j = last; j < endLocation.getSegmentIndex(); ++j) {
Coordinate from = shape.getCoordinateN(j);
Coordinate to = shape.getCoordinateN(j + 1);
double xd = from.x - to.x;
double yd = from.y - to.y;
distanceSoFar += FastMath.sqrt(xd * xd + yd * yd);
}
last = startLocation.getSegmentIndex();
double endIndex = distanceSoFar + endLocation.getSegmentFraction() * endLocation.getSegmentLength(shape);
ShapeSegmentKey key = new ShapeSegmentKey(shapeId, startIndex, endIndex);
LineString geometry = geometriesByShapeSegmentKey.get(key);
if (geometry == null) {
LocationIndexedLine locationIndexed = new LocationIndexedLine(shape);
geometry = (LineString) locationIndexed.extractLine(startLocation, endLocation);
// Pack the resulting line string
CoordinateSequence sequence = new PackedCoordinateSequence.Double(geometry.getCoordinates(), 2);
geometry = geometryFactory.createLineString(sequence);
}
geoms[i] = geometry;
}
return geoms;
}
Aggregations