Search in sources :

Example 26 with PolygonType

use of org.geotoolkit.gml.xml.v311.PolygonType in project ddf by codice.

the class WfsFilterDelegate method createPolygon.

private JAXBElement<PolygonType> createPolygon(Geometry geometry) {
    PolygonType polygonType = gml320ObjectFactory.createPolygonType();
    polygonType.setSrsName(GeospatialUtil.EPSG_4326_URN);
    LinearRingType ring = gml320ObjectFactory.createLinearRingType();
    ring.setCoordinates(createCoordinates(geometry));
    AbstractRingPropertyType abstractRing = gml320ObjectFactory.createAbstractRingPropertyType();
    abstractRing.setAbstractRing(gml320ObjectFactory.createLinearRing(ring));
    polygonType.setExterior(abstractRing);
    return gml320ObjectFactory.createPolygon(polygonType);
}
Also used : LinearRingType(net.opengis.gml.v_3_2_1.LinearRingType) AbstractRingPropertyType(net.opengis.gml.v_3_2_1.AbstractRingPropertyType) PolygonType(net.opengis.gml.v_3_2_1.PolygonType)

Example 27 with PolygonType

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

the class PolygonConverter method convertFrom.

@Override
public Polygon convertFrom(PolygonType polygonType, Type<Polygon> type, MappingContext mappingContext) {
    Optional<List<Double>> optionalExteriorValues = Optional.ofNullable(polygonType).map(PolygonType::getExterior).map(this::extractValues);
    Optional<List<List<Double>>> interiorValues = Optional.ofNullable(polygonType).map(PolygonType::getInterior).map(list -> list.stream().map(this::extractValues).collect(Collectors.toList())).filter(list -> !list.isEmpty());
    if (optionalExteriorValues.isPresent()) {
        List<Double> exteriorValues = optionalExteriorValues.get();
        CoordinateSequence exteriorCoordinateSequence = doubleValuesToCoordinateSequence.convert(exteriorValues);
        LinearRing exteriorLinearRing = new LinearRing(exteriorCoordinateSequence, geometryFactory);
        LinearRing[] interiorHoles = null;
        if (interiorValues.isPresent()) {
            interiorHoles = interiorValues.get().stream().map(doubleValuesToCoordinateSequence::convert).map(coordinateSequence -> new LinearRing(coordinateSequence, geometryFactory)).toArray(size -> new LinearRing[size]);
        }
        return new Polygon(exteriorLinearRing, interiorHoles, geometryFactory);
    }
    logger.warn("Cannot convert polygon from PolygonType. Cannot find exterior values: {}", polygonType);
    return null;
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) LinearRing(org.locationtech.jts.geom.LinearRing) LoggerFactory(org.slf4j.LoggerFactory) PolygonType(net.opengis.gml._3.PolygonType) Coordinate(org.locationtech.jts.geom.Coordinate) Autowired(org.springframework.beans.factory.annotation.Autowired) MappingContext(ma.glasnost.orika.MappingContext) ArrayList(java.util.ArrayList) DoubleValuesToCoordinateSequence(org.rutebanken.tiamat.geo.DoubleValuesToCoordinateSequence) DirectPositionListType(net.opengis.gml._3.DirectPositionListType) BidirectionalConverter(ma.glasnost.orika.converter.BidirectionalConverter) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Logger(org.slf4j.Logger) ObjectFactory(net.opengis.gml._3.ObjectFactory) LinearRingType(net.opengis.gml._3.LinearRingType) JAXBElement(javax.xml.bind.JAXBElement) Type(ma.glasnost.orika.metadata.Type) Collectors(java.util.stream.Collectors) LineString(org.locationtech.jts.geom.LineString) AtomicLong(java.util.concurrent.atomic.AtomicLong) AbstractRingPropertyType(net.opengis.gml._3.AbstractRingPropertyType) Component(org.springframework.stereotype.Component) List(java.util.List) Polygon(org.locationtech.jts.geom.Polygon) Optional(java.util.Optional) CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) DoubleValuesToCoordinateSequence(org.rutebanken.tiamat.geo.DoubleValuesToCoordinateSequence) ArrayList(java.util.ArrayList) List(java.util.List) PolygonType(net.opengis.gml._3.PolygonType) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon)

Example 28 with PolygonType

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

use of org.geotoolkit.gml.xml.v311.PolygonType 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)

Example 30 with PolygonType

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

the class PolygonConverterTest method convertToWithHoles.

@Test
public void convertToWithHoles() throws Exception {
    Coordinate[] coordinates = new Coordinate[] { new Coordinate(9.8468, 59.2649), new Coordinate(9.8456, 59.2654), new Coordinate(9.8457, 59.2655), new Coordinate(9.8468, 59.2649) };
    LinearRing linearRing = new LinearRing(new CoordinateArraySequence(coordinates), geometryFactory);
    LinearRing[] holes = new LinearRing[] { new LinearRing(new CoordinateArraySequence(coordinates), geometryFactory) };
    Polygon polygon = new Polygon(linearRing, holes, geometryFactory);
    PolygonType actual = polygonConverter.convertTo(polygon, new TypeBuilder<PolygonType>() {
    }.build(), new MappingContext(new HashMap<>()));
    assertThat(actual).isNotNull();
    List<Double> actualDoublevalues = polygonConverter.extractValues(actual.getExterior());
    assertThat(actualDoublevalues).hasSize(coordinates.length * 2);
    List<Double> actualHoleDoubleValues = polygonConverter.extractValues(actual.getInterior().get(0));
    assertThat(actualHoleDoubleValues).hasSize(coordinates.length * 2);
}
Also used : MappingContext(ma.glasnost.orika.MappingContext) Coordinate(org.locationtech.jts.geom.Coordinate) TypeBuilder(ma.glasnost.orika.metadata.TypeBuilder) HashMap(java.util.HashMap) PolygonType(net.opengis.gml._3.PolygonType) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) CoordinateArraySequence(org.locationtech.jts.geom.impl.CoordinateArraySequence) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 ArrayList (java.util.ArrayList)11 Polygon (org.locationtech.jts.geom.Polygon)11 Geometry (org.locationtech.jts.geom.Geometry)8 PolygonType (net.opengis.gml.v_3_1_1.PolygonType)7 Coordinate (org.locationtech.jts.geom.Coordinate)7 LinearRing (org.locationtech.jts.geom.LinearRing)7 List (java.util.List)6 JAXBElement (javax.xml.bind.JAXBElement)6 LinearRingType (net.opengis.gml.v_3_1_1.LinearRingType)6 MultiPolygonType (net.opengis.gml.v_3_1_1.MultiPolygonType)6 PolygonType (net.opengis.gml._3.PolygonType)5 PolygonType (org.geosdi.geoplatform.xml.gml.v311.PolygonType)5 LineString (org.locationtech.jts.geom.LineString)5 File (java.io.File)4 MappingContext (ma.glasnost.orika.MappingContext)4 BinarySpatialOpType (net.opengis.filter.v_1_1_0.BinarySpatialOpType)4 FilterType (net.opengis.filter.v_1_1_0.FilterType)4 PolygonType (net.opengis.gml.v_3_2_1.PolygonType)4 Point (org.locationtech.jts.geom.Point)4