
org.opentripplanner.netex.mapping.OpenGisMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
package org.opentripplanner.netex.mapping;
import net.opengis.gml._3.AbstractRingPropertyType;
import net.opengis.gml._3.LinearRingType;
import net.opengis.gml._3.PolygonType;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.CoordinateSequence;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.LinearRing;
import org.locationtech.jts.geom.Polygon;
import org.opentripplanner.api.resource.CoordinateArrayListSequence;
import org.opentripplanner.common.geometry.GeometryUtils;
import java.util.ArrayList;
import java.util.List;
/**
* This maps from the OpenGIS PolygonType to LocationTech geometry.
*/
class OpenGisMapper {
static Geometry mapGeometry(PolygonType polygonType) {
return new Polygon(
new LinearRing(mapCoordinateSequence(polygonType.getExterior()),
GeometryUtils.getGeometryFactory()
),
polygonType
.getInterior()
.stream()
.map(c -> new LinearRing(mapCoordinateSequence(c), GeometryUtils.getGeometryFactory()))
.toArray(LinearRing[]::new),
GeometryUtils.getGeometryFactory()
);
}
private static CoordinateSequence mapCoordinateSequence(
AbstractRingPropertyType abstractRingPropertyType
) {
List posList = ((LinearRingType) abstractRingPropertyType.getAbstractRing().getValue())
.getPosList()
.getValue();
// Convert a single list of alternating lat/lon values into coordinates
ArrayList coordinates = new ArrayList<>();
for (int i = 0; i < posList.size(); i += 2) {
coordinates.add(new Coordinate(posList.get(i + 1), posList.get(i)));
}
return new CoordinateArrayListSequence(coordinates);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy