Search in sources :

Example 16 with PolygonType

use of org.geosdi.geoplatform.xml.gml.v311.PolygonType in project geo-platform by geosdi.

the class GMLPolygonGeoJsonParserTest method a_polygonGeoJsonParserTest.

@Test
public void a_polygonGeoJsonParserTest() throws Exception {
    PolygonType polygonType = jaxbContextBuilder.unmarshal(new File(dirFiles.concat("Polygon.xml")), PolygonType.class);
    Polygon polygon = polygonParser.parseGeometryAsGeoJson(polygonType);
    List<List<LngLatAlt>> interiorRings = polygon.getInteriorRings();
    assertNotNull(interiorRings);
    Assert.assertTrue(interiorRings.size() == 2);
    logger.info("#######################POLYGON_AS_GEOJSON : \n{}\n", mapper.writeValueAsString(polygon));
}
Also used : PolygonType(org.geosdi.geoplatform.xml.gml.v311.PolygonType) List(java.util.List) Polygon(org.geojson.Polygon) File(java.io.File) Test(org.junit.Test)

Example 17 with PolygonType

use of org.geosdi.geoplatform.xml.gml.v311.PolygonType in project geo-platform by geosdi.

the class GMLPolygonGeoJsonParserTest method b_polygonGeoJsonParserTest.

@Test
public void b_polygonGeoJsonParserTest() throws Exception {
    PolygonType polygonType = jaxbContextBuilder.unmarshal(new File(dirFiles.concat("Polygon_1.xml")), PolygonType.class);
    Polygon polygon = polygonParser.parseGeometryAsGeoJson(polygonType);
    Assert.assertTrue(polygon.getInteriorRings().size() == 0);
    logger.info("#######################POLYGON1_AS_GEOJSON : \n{}\n", mapper.writeValueAsString(polygon));
}
Also used : PolygonType(org.geosdi.geoplatform.xml.gml.v311.PolygonType) Polygon(org.geojson.Polygon) File(java.io.File) Test(org.junit.Test)

Example 18 with PolygonType

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

the class TestWfs10JTStoGML200Converter method testGMLToPolygonType.

@Test
public void testGMLToPolygonType() throws JAXBException, SAXException, IOException, ParseException, NullPointerException {
    Polygon polygon = (Polygon) getGeometryFromWkt(POLYGON);
    assertThat(polygon == null, is(Boolean.FALSE));
    String polygonGML = Wfs10JTStoGML200Converter.convertGeometryToGML(polygon);
    PolygonType polygonType = (PolygonType) Wfs10JTStoGML200Converter.convertGMLToGeometryType(polygonGML, Wfs10Constants.POLYGON);
    assertThat(null != polygonType, is(Boolean.TRUE));
    assertThat(polygonType.isSetInnerBoundaryIs(), is(Boolean.FALSE));
    assertThat(polygonType.isSetOuterBoundaryIs(), is(Boolean.TRUE));
    LinearRingMemberType linearRingMemberType = polygonType.getOuterBoundaryIs();
    JAXBElement<? extends AbstractGeometryType> geometry = linearRingMemberType.getGeometry();
    LinearRingType linearRingType = (LinearRingType) geometry.getValue();
    String coordinates = linearRingType.getCoordinates().getValue().replaceAll("\n", "").trim();
    assertThat(POLYGON_COORDS.equals(coordinates), is(Boolean.TRUE));
}
Also used : LinearRingType(ogc.schema.opengis.gml.v_2_1_2.LinearRingType) LinearRingMemberType(ogc.schema.opengis.gml.v_2_1_2.LinearRingMemberType) PolygonType(ogc.schema.opengis.gml.v_2_1_2.PolygonType) MultiPolygonType(ogc.schema.opengis.gml.v_2_1_2.MultiPolygonType) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) Test(org.junit.Test)

Example 19 with PolygonType

use of org.geosdi.geoplatform.xml.gml.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 20 with PolygonType

use of org.geosdi.geoplatform.xml.gml.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)

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