Search in sources :

Example 26 with LineStringType

use of org.geotoolkit.gml.xml.v321.LineStringType in project tiamat by entur.

the class PathLinkImportTest method publicationDeliveryWithPathLink.

@Test
public void publicationDeliveryWithPathLink() throws Exception {
    StopPlace fromStopPlace = new StopPlace().withId("RUT:StopPlace:123123").withVersion("1").withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("9")).withLongitude(new BigDecimal("71"))));
    StopPlace toStopPlace = new StopPlace().withId("RUT:StopPlace:321654").withVersion("1").withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("9.6")).withLongitude(new BigDecimal("76"))));
    LineStringType lineStringType = new LineStringType().withId("LineString").withPosList(new DirectPositionListType().withSrsDimension(BigInteger.valueOf(new GeometryFactoryConfig().geometryFactory().getSRID())).withValue(9.1, 71.1, 9.5, 74.1));
    Duration duration = Duration.ofMillis(10000);
    PathLink netexPathLink = new PathLink().withId("NRI:ConnectionLink:762130479_762130479").withVersion("1").withAllowedUse(PathDirectionEnumeration.TWO_WAY).withTransferDuration(new TransferDurationStructure().withDefaultDuration(duration)).withLineString(lineStringType).withFrom(new PathLinkEndStructure().withPlaceRef(new PlaceRefStructure().withRef(fromStopPlace.getId()))).withTo(new PathLinkEndStructure().withPlaceRef(new PlaceRefStructure().withRef(toStopPlace.getId()).withVersion("1")));
    PublicationDeliveryStructure publicationDelivery = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(fromStopPlace, toStopPlace);
    publicationDeliveryTestHelper.addPathLinks(publicationDelivery, netexPathLink);
    PublicationDeliveryStructure response = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery);
    List<PathLink> result = publicationDeliveryTestHelper.extractPathLinks(response);
    assertThat(result).as("Expecting path link in return").hasSize(1);
    PathLink importedPathLink = result.get(0);
    assertThat(importedPathLink.getAllowedUse()).isEqualTo(netexPathLink.getAllowedUse());
    assertThat(importedPathLink.getFrom().getPlaceRef().getRef()).contains(fromStopPlace.getClass().getSimpleName());
    assertThat(importedPathLink.getTo().getPlaceRef().getRef()).contains(toStopPlace.getClass().getSimpleName());
    assertThat(importedPathLink.getTransferDuration().getDefaultDuration()).isEqualTo(duration);
    assertThat(importedPathLink.getLineString()).isNotNull();
    assertThat(importedPathLink.getLineString().getPosList()).isNotNull();
    assertThat(importedPathLink.getLineString().getPosList().getValue()).hasSize(4);
}
Also used : StopPlace(org.rutebanken.netex.model.StopPlace) DirectPositionListType(net.opengis.gml._3.DirectPositionListType) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) SimplePoint_VersionStructure(org.rutebanken.netex.model.SimplePoint_VersionStructure) Duration(java.time.Duration) PlaceRefStructure(org.rutebanken.netex.model.PlaceRefStructure) LineStringType(net.opengis.gml._3.LineStringType) TransferDurationStructure(org.rutebanken.netex.model.TransferDurationStructure) LocationStructure(org.rutebanken.netex.model.LocationStructure) BigDecimal(java.math.BigDecimal) GeometryFactoryConfig(org.rutebanken.tiamat.config.GeometryFactoryConfig) PathLink(org.rutebanken.netex.model.PathLink) PathLinkEndStructure(org.rutebanken.netex.model.PathLinkEndStructure) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 27 with LineStringType

use of org.geotoolkit.gml.xml.v321.LineStringType in project tiamat by entur.

the class LineStringConverterTest method convertFromLineStringToNetexGmlLineStringType.

@Test
public void convertFromLineStringToNetexGmlLineStringType() throws Exception {
    Coordinate[] coordinates = new Coordinate[2];
    coordinates[0] = new Coordinate(11, 60);
    coordinates[1] = new Coordinate(11.1, 60.1);
    CoordinateSequence points = new CoordinateArraySequence(coordinates);
    LineString lineString = new LineString(points, geometryFactory);
    LineStringType gisLineString = lineStringConverter.convertFrom(lineString, new TypeBuilder<LineStringType>() {
    }.build(), mappingContext);
    assertThat(gisLineString).isNotNull();
    assertThat(gisLineString.getPosList().getCount().intValue()).isEqualTo(4);
    assertThat(gisLineString.getId()).isNotEmpty();
    // Check that the format is Y,X
    assertThat(gisLineString.getPosList().getValue().get(0)).isEqualTo(coordinates[0].y);
    assertThat(gisLineString.getPosList().getValue().get(1)).isEqualTo(coordinates[0].x);
    assertThat(gisLineString.getPosList().getValue().get(2)).isEqualTo(coordinates[1].y);
    assertThat(gisLineString.getPosList().getValue().get(3)).isEqualTo(coordinates[1].x);
    assertThat(gisLineString.getSrsDimension().intValue()).isEqualTo(2);
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) DoubleValuesToCoordinateSequence(org.rutebanken.tiamat.geo.DoubleValuesToCoordinateSequence) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) TypeBuilder(ma.glasnost.orika.metadata.TypeBuilder) LineStringType(net.opengis.gml._3.LineStringType) CoordinateArraySequence(org.locationtech.jts.geom.impl.CoordinateArraySequence) Test(org.junit.Test)

Example 28 with LineStringType

use of org.geotoolkit.gml.xml.v321.LineStringType in project geotoolkit by Geomatys.

the class KMLStore method convert.

private static Geometry convert(Object geomType) throws DataStoreException {
    if (geomType instanceof JAXBElement)
        geomType = ((JAXBElement) geomType).getValue();
    Geometry geom = null;
    if (geomType instanceof ModelType) {
        final ModelType modelType = (ModelType) geomType;
        final LocationType location = modelType.getLocation();
        geom = GF.createPoint(new Coordinate(location.getLongitude(), location.getLatitude()));
    } else if (geomType instanceof PointType) {
        final PointType pointType = (PointType) geomType;
        final List<String> coordinates = pointType.getCoordinates();
        geom = GF.createPoint(toCoordinates(coordinates, 1, false));
    } else if (geomType instanceof PolygonType) {
        final PolygonType polygonType = (PolygonType) geomType;
        final CoordinateSequence outter = toCoordinates(polygonType.getOuterBoundaryIs().getLinearRing().getCoordinates(), 3, true);
        final List<BoundaryType> inners = polygonType.getInnerBoundaryIs();
        final LinearRing[] holes = new LinearRing[inners.size()];
        for (int i = 0; i < holes.length; i++) {
            holes[i] = GF.createLinearRing(toCoordinates(inners.get(i).getLinearRing().getCoordinates(), 3, true));
        }
        geom = GF.createPolygon(GF.createLinearRing(outter), holes);
    } else if (geomType instanceof LinearRingType) {
        final LinearRingType linearRingType = (LinearRingType) geomType;
        geom = GF.createLineString(toCoordinates(linearRingType.getCoordinates(), 3, true));
    } else if (geomType instanceof MultiGeometryType) {
        final MultiGeometryType multigeometryType = (MultiGeometryType) geomType;
        final List<JAXBElement<? extends AbstractGeometryType>> children = multigeometryType.getAbstractGeometryGroup();
        final Geometry[] childs = new Geometry[children.size()];
        for (int i = 0; i < childs.length; i++) {
            childs[i] = convert(children.get(i));
        }
        geom = GF.createGeometryCollection(childs);
    } else if (geomType instanceof LineStringType) {
        final LineStringType lineStringType = (LineStringType) geomType;
        geom = GF.createLineString(toCoordinates(lineStringType.getCoordinates(), 2, false));
    }
    if (geom != null) {
        JTS.setCRS(geom, CRS);
    }
    return geom;
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) PackedCoordinateSequence(org.locationtech.jts.geom.impl.PackedCoordinateSequence) AbstractGeometryType(org.geotoolkit.kml.xml.v220.AbstractGeometryType) LinearRingType(org.geotoolkit.kml.xml.v220.LinearRingType) MultiGeometryType(org.geotoolkit.kml.xml.v220.MultiGeometryType) PolygonType(org.geotoolkit.kml.xml.v220.PolygonType) JAXBElement(javax.xml.bind.JAXBElement) LineStringType(org.geotoolkit.kml.xml.v220.LineStringType) Geometry(org.locationtech.jts.geom.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate) ModelType(org.geotoolkit.kml.xml.v220.ModelType) PointType(org.geotoolkit.kml.xml.v220.PointType) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) LinearRing(org.locationtech.jts.geom.LinearRing) LocationType(org.geotoolkit.kml.xml.v220.LocationType) BoundaryType(org.geotoolkit.kml.xml.v220.BoundaryType)

Aggregations

Test (org.junit.Test)11 LineString (org.locationtech.jts.geom.LineString)9 Coordinate (org.locationtech.jts.geom.Coordinate)7 ArrayList (java.util.ArrayList)6 JAXBElement (javax.xml.bind.JAXBElement)6 Geometry (org.locationtech.jts.geom.Geometry)6 LineStringType (net.opengis.gml._3.LineStringType)5 LineStringType (net.opengis.gml.v_3_2_1.LineStringType)5 LineStringType (ogc.schema.opengis.gml.v_2_1_2.LineStringType)5 MultiLineStringType (ogc.schema.opengis.gml.v_2_1_2.MultiLineStringType)5 LineString (com.vividsolutions.jts.geom.LineString)4 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)4 List (java.util.List)4 DirectPositionListType (net.opengis.gml._3.DirectPositionListType)4 LineStringType (net.opengis.gml.v_3_1_1.LineStringType)3 LineStringType (org.geotoolkit.gml.xml.v311.LineStringType)3 MultiPoint (org.locationtech.jts.geom.MultiPoint)3 Point (org.locationtech.jts.geom.Point)3 BigDecimal (java.math.BigDecimal)2 TypeBuilder (ma.glasnost.orika.metadata.TypeBuilder)2