Search in sources :

Example 16 with LinearRingType

use of org.geosdi.geoplatform.xml.gml.v311.LinearRingType 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 17 with LinearRingType

use of org.geosdi.geoplatform.xml.gml.v311.LinearRingType in project arctic-sea by 52North.

the class GmlDecoderv321 method parsePolygonType.

private Geometry parsePolygonType(PolygonType xbPolygonType) throws DecodingException {
    int srid = -1;
    if (xbPolygonType.getSrsName() != null) {
        srid = CRSHelper.parseSrsName(xbPolygonType.getSrsName());
    }
    String exteriorCoordString = null;
    StringBuilder geomWKT = new StringBuilder();
    StringBuilder interiorCoordString = new StringBuilder();
    AbstractRingPropertyType xbExterior = xbPolygonType.getExterior();
    if (xbExterior != null) {
        AbstractRingType xbExteriorRing = xbExterior.getAbstractRing();
        if (xbExteriorRing instanceof LinearRingType) {
            LinearRingType xbLinearRing = (LinearRingType) xbExteriorRing;
            exteriorCoordString = getCoordString4LinearRing(xbLinearRing);
        } else {
            throw new DecodingException("The Polygon must contain the following elements <gml:exterior><gml:LinearRing><gml:posList>!");
        }
    }
    AbstractRingPropertyType[] xbInterior = xbPolygonType.getInteriorArray();
    if (xbInterior != null && xbInterior.length != 0) {
        for (AbstractRingPropertyType xbInteriorRing : xbInterior) {
            if (xbInteriorRing.getAbstractRing() instanceof LinearRingType) {
                interiorCoordString.append(", ").append(getCoordString4LinearRing((LinearRingType) xbInteriorRing.getAbstractRing()));
            }
        }
    }
    geomWKT.append("POLYGON(");
    geomWKT.append(exteriorCoordString);
    geomWKT.append(interiorCoordString);
    geomWKT.append(")");
    srid = setDefaultForUnsetSrid(srid);
    try {
        return JTSHelper.createGeometryFromWKT(geomWKT.toString(), srid);
    } catch (ParseException ex) {
        throw new DecodingException(ex);
    }
}
Also used : AbstractRingType(net.opengis.gml.x32.AbstractRingType) AbstractRingPropertyType(net.opengis.gml.x32.AbstractRingPropertyType) LinearRingType(net.opengis.gml.x32.LinearRingType) DecodingException(org.n52.svalbard.decode.exception.DecodingException) DateTimeParseException(org.n52.shetland.util.DateTimeParseException) ParseException(org.locationtech.jts.io.ParseException)

Example 18 with LinearRingType

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

the class GMLLinearRingGeoJsonParserTest method linearRingGeoJsonParserTest.

@Test
public void linearRingGeoJsonParserTest() throws Exception {
    LinearRingType linearRingType = jaxbContextBuilder.unmarshal(new File(dirFiles.concat("LinearRing.xml")), LinearRingType.class);
    logger.info("#######################LINEAR_RING_AS_GEOJSON : \n{}\n", mapper.writeValueAsString(linearRingParser.parseGeometryAsGeoJson(linearRingType)));
}
Also used : LinearRingType(org.geosdi.geoplatform.xml.gml.v311.LinearRingType) File(java.io.File) Test(org.junit.Test)

Example 19 with LinearRingType

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

use of org.geosdi.geoplatform.xml.gml.v311.LinearRingType 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)13 LinearRingType (net.opengis.gml.v_3_1_1.LinearRingType)9 ArrayList (java.util.ArrayList)7 MultiPolygonType (net.opengis.gml.v_3_1_1.MultiPolygonType)7 BinarySpatialOpType (net.opengis.filter.v_1_1_0.BinarySpatialOpType)6 FilterType (net.opengis.filter.v_1_1_0.FilterType)6 PolygonType (net.opengis.gml.v_3_1_1.PolygonType)6 Coordinate (org.locationtech.jts.geom.Coordinate)6 Polygon (org.locationtech.jts.geom.Polygon)5 AbstractRingPropertyType (net.opengis.gml._3.AbstractRingPropertyType)3 DirectPositionListType (net.opengis.gml._3.DirectPositionListType)3 LinearRingType (net.opengis.gml._3.LinearRingType)3 PolygonType (net.opengis.gml._3.PolygonType)3 LinearRingMemberType (ogc.schema.opengis.gml.v_2_1_2.LinearRingMemberType)3 LinearRingType (ogc.schema.opengis.gml.v_2_1_2.LinearRingType)3 MultiPolygonType (ogc.schema.opengis.gml.v_2_1_2.MultiPolygonType)3 PolygonType (ogc.schema.opengis.gml.v_2_1_2.PolygonType)3 Geometry (org.locationtech.jts.geom.Geometry)3 LinearRing (org.locationtech.jts.geom.LinearRing)3 HashMap (java.util.HashMap)2