Search in sources :

Example 16 with DirectPositionListType

use of org.geotoolkit.gml.xml.v311.DirectPositionListType in project geotoolkit by Geomatys.

the class GeometrytoJTSTest method gmlPolygonToJTSTest2D.

@Test
public void gmlPolygonToJTSTest2D() throws Exception {
    GeometryFactory fact = GF;
    final Coordinate[] coordinates = new Coordinate[5];
    coordinates[0] = new Coordinate(0, 0);
    coordinates[1] = new Coordinate(0, 1);
    coordinates[2] = new Coordinate(1, 1);
    coordinates[3] = new Coordinate(1, 0);
    coordinates[4] = new Coordinate(0, 0);
    LinearRing linear = GF.createLinearRing(coordinates);
    Polygon expected = new Polygon(linear, null, fact);
    expected.setSRID(2154);
    LinearRingType exterior = new LinearRingType();
    List<Double> coords = new ArrayList<>();
    coords.add(0.0);
    coords.add(0.0);
    coords.add(0.0);
    coords.add(1.0);
    coords.add(1.0);
    coords.add(1.0);
    coords.add(1.0);
    coords.add(0.0);
    coords.add(0.0);
    coords.add(0.0);
    exterior.setPosList(new DirectPositionListType(coords));
    PolygonType gml = new PolygonType(exterior, null);
    final Geometry result = GeometrytoJTS.toJTS((org.geotoolkit.gml.xml.Polygon) gml);
    Assert.assertEquals(expected, result);
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) LinearRingType(org.geotoolkit.gml.xml.v321.LinearRingType) ArrayList(java.util.ArrayList) DirectPositionListType(org.geotoolkit.gml.xml.v321.DirectPositionListType) PolygonType(org.geotoolkit.gml.xml.v321.PolygonType) Geometry(org.locationtech.jts.geom.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) Test(org.junit.Test)

Example 17 with DirectPositionListType

use of org.geotoolkit.gml.xml.v311.DirectPositionListType in project tiamat by entur.

the class LineStringConverter method convertFrom.

@Override
public LineStringType convertFrom(LineString lineString, Type<LineStringType> typ, MappingContext mappingContext) {
    LineStringType lineStringType = new LineStringType();
    DirectPositionListType directPositionListType = new DirectPositionListType();
    if (lineString.getCoordinates() != null) {
        logger.debug("Converting coordinates {}", lineString.getCoordinates());
        List<Double> positions = directPositionListType.getValue();
        for (Coordinate coordinate : lineString.getCoordinates()) {
            positions.add(coordinate.y);
            positions.add(coordinate.x);
        }
        directPositionListType.setCount(BigInteger.valueOf(positions.size()));
        directPositionListType.setSrsDimension(BigInteger.valueOf(2L));
    }
    lineStringType.setPosList(directPositionListType);
    lineStringType.setId(LineString.class.getSimpleName());
    lineStringType.setSrsDimension(BigInteger.valueOf(2L));
    return lineStringType;
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) DirectPositionListType(net.opengis.gml._3.DirectPositionListType) LineStringType(net.opengis.gml._3.LineStringType)

Example 18 with DirectPositionListType

use of org.geotoolkit.gml.xml.v311.DirectPositionListType 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 19 with DirectPositionListType

use of org.geotoolkit.gml.xml.v311.DirectPositionListType in project tiamat by entur.

the class TopographicPlaceImportTest method publicationDeliveryWithTopographicPlaceAndPolygon.

@Test
public void publicationDeliveryWithTopographicPlaceAndPolygon() throws Exception {
    List<Double> values = new ArrayList<>();
    values.add(9.8468);
    values.add(59.2649);
    values.add(9.8456);
    values.add(59.2654);
    values.add(9.8457);
    values.add(59.2655);
    values.add(9.8443);
    values.add(59.2663);
    values.add(values.get(0));
    values.add(values.get(1));
    DirectPositionListType positionList = new DirectPositionListType().withValue(values);
    LinearRingType linearRing = new LinearRingType().withPosList(positionList);
    PolygonType polygonType = new PolygonType().withId("KVE-07").withExterior(new AbstractRingPropertyType().withAbstractRing(openGisObjectFactory.createLinearRing(linearRing)));
    MultilingualString nameDescriptor = new MultilingualString().withValue("Vestfold").withLang("nb");
    TopographicPlace topographicPlace = new TopographicPlace().withId("KVE:TopographicPlace:07").withName(nameDescriptor).withVersion("1").withDescriptor(new TopographicPlaceDescriptor_VersionedChildStructure().withName(nameDescriptor)).withTopographicPlaceType(TopographicPlaceTypeEnumeration.COUNTY).withCountryRef(new CountryRef().withValue("NO")).withPolygon(polygonType);
    PublicationDeliveryStructure publicationDelivery = publicationDeliveryTestHelper.createPublicationDeliveryTopographicPlace(topographicPlace);
    PublicationDeliveryStructure response = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery);
    List<TopographicPlace> result = publicationDeliveryTestHelper.extractTopographicPlace(response);
    assertThat(result).as("Expecting topographic place in return").hasSize(1);
    TopographicPlace actualTopographicPlace = result.get(0);
    assertThat(actualTopographicPlace.getPolygon()).as("polygon must not be null").isNotNull();
    List<Double> actualExteriorValues = polygonConverter.extractValues(topographicPlace.getPolygon().getExterior());
    assertThat(actualExteriorValues).isEqualTo(values);
    assertThat(actualTopographicPlace.getId()).isEqualTo(topographicPlace.getId());
}
Also used : TopographicPlaceDescriptor_VersionedChildStructure(org.rutebanken.netex.model.TopographicPlaceDescriptor_VersionedChildStructure) LinearRingType(net.opengis.gml._3.LinearRingType) AbstractRingPropertyType(net.opengis.gml._3.AbstractRingPropertyType) TopographicPlace(org.rutebanken.netex.model.TopographicPlace) ArrayList(java.util.ArrayList) DirectPositionListType(net.opengis.gml._3.DirectPositionListType) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) PolygonType(net.opengis.gml._3.PolygonType) CountryRef(org.rutebanken.netex.model.CountryRef) MultilingualString(org.rutebanken.netex.model.MultilingualString) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 20 with DirectPositionListType

use of org.geotoolkit.gml.xml.v311.DirectPositionListType in project tiamat by entur.

the class PolygonConverterTest method convertFrom.

@Test
public void convertFrom() throws Exception {
    List<Double> values = new ArrayList<>();
    values.add(9.8468);
    values.add(59.2649);
    values.add(9.8456);
    values.add(59.2654);
    values.add(9.8457);
    values.add(59.2655);
    values.add(values.get(0));
    values.add(values.get(1));
    DirectPositionListType positionList = new DirectPositionListType().withValue(values);
    LinearRingType linearRing = new LinearRingType().withPosList(positionList);
    PolygonType polygonType = new PolygonType().withId("KVE-07").withExterior(new AbstractRingPropertyType().withAbstractRing(openGisObjectFactory.createLinearRing(linearRing)));
    Polygon polygon = polygonConverter.convertFrom(polygonType, new TypeBuilder<Polygon>() {
    }.build(), new MappingContext(new HashMap<>()));
    assertThat(polygon).isExactlyInstanceOf(Polygon.class).isNotNull();
    assertThat(polygon.getExteriorRing().getCoordinates()).hasSize(values.size() / 2);
    assertCoordinatesMatch(polygon.getExteriorRing(), values, "Exterior ring");
}
Also used : MappingContext(ma.glasnost.orika.MappingContext) TypeBuilder(ma.glasnost.orika.metadata.TypeBuilder) HashMap(java.util.HashMap) LinearRingType(net.opengis.gml._3.LinearRingType) AbstractRingPropertyType(net.opengis.gml._3.AbstractRingPropertyType) ArrayList(java.util.ArrayList) DirectPositionListType(net.opengis.gml._3.DirectPositionListType) PolygonType(net.opengis.gml._3.PolygonType) Polygon(org.locationtech.jts.geom.Polygon) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 DirectPositionListType (net.opengis.gml._3.DirectPositionListType)7 ArrayList (java.util.ArrayList)6 Coordinate (org.locationtech.jts.geom.Coordinate)6 DirectPositionListType (net.opengis.gml.x32.DirectPositionListType)5 DirectPositionListType (org.geotoolkit.gml.xml.v321.DirectPositionListType)5 Polygon (org.locationtech.jts.geom.Polygon)5 LineStringType (net.opengis.gml._3.LineStringType)4 LineString (org.locationtech.jts.geom.LineString)4 TypeBuilder (ma.glasnost.orika.metadata.TypeBuilder)3 AbstractRingPropertyType (net.opengis.gml._3.AbstractRingPropertyType)3 LinearRingType (net.opengis.gml._3.LinearRingType)3 PolygonType (net.opengis.gml._3.PolygonType)3 Geometry (org.locationtech.jts.geom.Geometry)3 StringReader (java.io.StringReader)2 StringWriter (java.io.StringWriter)2 BigDecimal (java.math.BigDecimal)2 HashMap (java.util.HashMap)2 JAXBElement (javax.xml.bind.JAXBElement)2 Duration (javax.xml.datatype.Duration)2