Skip to content

Commit

Permalink
Adds EncompassingAreaGeometry to the GroupStop and makes it queryable…
Browse files Browse the repository at this point in the history
… in the flexibleArea on the QuayType.
  • Loading branch information
eibakke committed Jan 17, 2024
1 parent 7826c0d commit 3f47b57
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,20 +380,21 @@ public static GraphQLObjectType create(
.name("flexibleArea")
.description("Geometry for flexible area.")
.type(GeoJSONCoordinatesScalar.getGraphQGeoJSONCoordinatesScalar())
.dataFetcher(environment ->
(
environment.getSource() instanceof AreaStop areaStop
? areaStop.getGeometry().getCoordinates()
: null
)
)
.dataFetcher(environment -> {
if (environment.getSource() instanceof AreaStop areaStop) {
return areaStop.getGeometry().getCoordinates();
} else if (environment.getSource() instanceof GroupStop groupStop) {
return groupStop.getEncompassingAreaGeometry().getCoordinates();
}
return null;
})
.build()
)
.field(
GraphQLFieldDefinition
.newFieldDefinition()
.name("flexibleGroup")
.description("the Quays part of an flexible group.")
.description("the Quays part of a flexible group.")
.type(GraphQLList.list(REF))
.dataFetcher(environment ->
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ StopLocation map(FlexibleStopPlace flexibleStopPlace) {
List<StopLocation> stops = new ArrayList<>();
TransitMode flexibleStopTransitMode = mapTransitMode(flexibleStopPlace);
var areas = flexibleStopPlace.getAreas().getFlexibleAreaOrFlexibleAreaRefOrHailAndRideArea();
ArrayList<Geometry> areaGeometries = new ArrayList<>();
for (var area : areas) {
if (!(area instanceof FlexibleArea flexibleArea)) {
issueStore.add(
Expand All @@ -76,6 +77,7 @@ StopLocation map(FlexibleStopPlace flexibleStopPlace) {
}

Geometry flexibleAreaGeometry = mapGeometry(flexibleArea);
areaGeometries.add(flexibleAreaGeometry);

if (shouldAddStopsFromArea(flexibleArea, flexibleStopPlace)) {
stops.addAll(
Expand All @@ -100,7 +102,8 @@ StopLocation map(FlexibleStopPlace flexibleStopPlace) {
// get the ids for the area and stop place correct
var builder = stopModelBuilder
.groupStop(idFactory.createId(flexibleStopPlace.getId()))
.withName(new NonLocalizedString(flexibleStopPlace.getName().getValue()));
.withName(new NonLocalizedString(flexibleStopPlace.getName().getValue()))
.withEncompassingAreaGeometries(areaGeometries);
stops.forEach(builder::addLocation);
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class GroupStop
private final I18NString name;
private final GeometryCollection geometry;

private final GeometryCollection encompassingAreaGeometry;

private final WgsCoordinate centroid;

GroupStop(GroupStopBuilder builder) {
Expand All @@ -33,6 +35,7 @@ public class GroupStop
this.geometry = builder.geometry();
this.centroid = Objects.requireNonNull(builder.centroid());
this.stopLocations = builder.stopLocations();
this.encompassingAreaGeometry = builder.encompassingAreaGeometry();
}

public static GroupStopBuilder of(FeedScopedId id, IntSupplier indexCounter) {
Expand Down Expand Up @@ -79,6 +82,10 @@ public Geometry getGeometry() {
return geometry;
}

public Geometry getEncompassingAreaGeometry() {
return encompassingAreaGeometry;
}

@Override
public boolean isPartOfStation() {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opentripplanner.transit.model.site;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.function.IntSupplier;
Expand All @@ -26,6 +27,11 @@ public class GroupStopBuilder extends AbstractEntityBuilder<GroupStop, GroupStop
GeometryUtils.getGeometryFactory()
);

private GeometryCollection encompassingAreaGeometry = new GeometryCollection(
null,
GeometryUtils.getGeometryFactory()
);

private WgsCoordinate centroid;

GroupStopBuilder(FeedScopedId id, IntSupplier indexCounter) {
Expand Down Expand Up @@ -53,6 +59,15 @@ public GroupStopBuilder withName(I18NString name) {
return this;
}

public GroupStopBuilder withEncompassingAreaGeometries(ArrayList<Geometry> geometries) {
this.encompassingAreaGeometry =
new GeometryCollection(
geometries.toArray(new Geometry[0]),
GeometryUtils.getGeometryFactory()
);
return this;
}

public I18NString name() {
return name;
}
Expand Down Expand Up @@ -90,6 +105,10 @@ public GeometryCollection geometry() {
return geometry;
}

public GeometryCollection encompassingAreaGeometry() {
return encompassingAreaGeometry;
}

public WgsCoordinate centroid() {
return centroid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ type Quay implements PlaceInterface {
): [EstimatedCall!]! @timingData
"Geometry for flexible area."
flexibleArea: Coordinates
"the Quays part of an flexible group."
"the Quays part of a flexible group."
flexibleGroup: [Quay]
id: ID!
"List of journey patterns servicing this quay"
Expand Down

0 comments on commit 3f47b57

Please sign in to comment.