use of org.opentripplanner.common.geometry.PackedCoordinateSequence in project OpenTripPlanner by opentripplanner.
the class TripPattern method makeGeometry.
/**
* Generates a geometry for the full pattern.
* This is done by concatenating the shapes of all the constituent hops.
* It could probably just come from the full shapes.txt entry for the trips in the route, but given all the details
* in how the individual hop geometries are constructed we just recombine them here.
*/
public void makeGeometry() {
CoordinateArrayListSequence coordinates = new CoordinateArrayListSequence();
if (patternHops != null && patternHops.length > 0) {
for (int i = 0; i < patternHops.length; i++) {
LineString geometry = patternHops[i].getGeometry();
if (geometry != null) {
if (coordinates.size() == 0) {
coordinates.extend(geometry.getCoordinates());
} else {
// Avoid duplicate coords at stops
coordinates.extend(geometry.getCoordinates(), 1);
}
}
}
// The CoordinateArrayListSequence is easy to append to, but is not serializable.
// It might be possible to just mark it serializable, but it is not particularly compact either.
// So we convert it to a packed coordinate sequence, since that is serializable and smaller.
// FIXME It seems like we could simply accumulate the coordinates into an array instead of using the CoordinateArrayListSequence.
PackedCoordinateSequence packedCoords = new PackedCoordinateSequence.Double(coordinates.toCoordinateArray(), 2);
this.geometry = GeometryUtils.getGeometryFactory().createLineString(packedCoords);
}
}
Aggregations