Skip to content

Commit

Permalink
Refactors GroupStopBuilder addLocation method.
Browse files Browse the repository at this point in the history
It now simply adds the geometry of the location to the geometry collection of the GroupStop. It was unclear what the large (100x100 degree) envelopes around regular stops were doing. It  looked like a bug, and the geometry of GroupStops appears unused so it should be safe to change.
  • Loading branch information
eibakke committed Jan 31, 2024
1 parent 9235518 commit 9610132
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.List;
import java.util.function.IntSupplier;
import javax.annotation.Nonnull;
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryCollection;
import org.opentripplanner.framework.geometry.GeometryUtils;
Expand Down Expand Up @@ -69,24 +68,26 @@ public I18NString name() {
}

public GroupStopBuilder addLocation(StopLocation location) {
if (
!(
location.getStopType() == StopType.REGULAR ||
location.getStopType() == StopType.FLEXIBLE_AREA
)
) {
throw new RuntimeException(
"Unsupported location for GroupStop. Must be Regular or FlexibleArea."
);
}

stopLocations.add(location);

int numGeometries = geometry.getNumGeometries();
Geometry[] newGeometries = new Geometry[numGeometries + 1];
for (int i = 0; i < numGeometries; i++) {
newGeometries[i] = geometry.getGeometryN(i);
}
if (location instanceof RegularStop) {
WgsCoordinate coordinate = location.getCoordinate();
Envelope envelope = new Envelope(coordinate.asJtsCoordinate());
double xscale = Math.cos(coordinate.latitude() * Math.PI / 180);
envelope.expandBy(100 / xscale, 100);
newGeometries[numGeometries] = GeometryUtils.getGeometryFactory().toGeometry(envelope);
} else if (location instanceof AreaStop) {
newGeometries[numGeometries] = location.getGeometry();
} else {
throw new RuntimeException("Unknown location type");
}
newGeometries[numGeometries] = location.getGeometry();

geometry = new GeometryCollection(newGeometries, GeometryUtils.getGeometryFactory());
centroid = new WgsCoordinate(geometry.getCentroid());

Expand Down

0 comments on commit 9610132

Please sign in to comment.