Search in sources :

Example 11 with LinearRingType

use of org.geotoolkit.gml.xml.v321.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 12 with LinearRingType

use of org.geotoolkit.gml.xml.v321.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 13 with LinearRingType

use of org.geotoolkit.gml.xml.v321.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 14 with LinearRingType

use of org.geotoolkit.gml.xml.v321.LinearRingType in project ddf by codice.

the class CswJTSToGML311LinearRingConverter method doCreateGeometryType.

/**
 * @see {@code JTSToGML311LinearRingConverter#doCreateGeometryType}
 */
@Override
protected LinearRingType doCreateGeometryType(LinearRing linearRing) {
    final LinearRingType resultLinearRing;
    if (usePosList) {
        resultLinearRing = getObjectFactory().createLinearRingType();
        List<Double> posDoubleList = new ArrayList<Double>();
        for (Coordinate coordinate : linearRing.getCoordinates()) {
            posDoubleList.add(coordinate.x);
            posDoubleList.add(coordinate.y);
        }
        DirectPositionListType directPosListType = new DirectPositionListType();
        directPosListType.setValue(posDoubleList);
        resultLinearRing.setPosList(directPosListType);
    } else {
        resultLinearRing = super.doCreateGeometryType(linearRing);
    }
    return resultLinearRing;
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRingType(net.opengis.gml.v_3_1_1.LinearRingType) ArrayList(java.util.ArrayList) DirectPositionListType(net.opengis.gml.v_3_1_1.DirectPositionListType)

Example 15 with LinearRingType

use of org.geotoolkit.gml.xml.v321.LinearRingType in project ddf by codice.

the class WfsFilterDelegateTest method testMultiPolygonWithSinglePolygonSupportsOnlyPolygon.

@Test
public void testMultiPolygonWithSinglePolygonSupportsOnlyPolygon() {
    final String MULTIPOLYGON_SINGLE_POLYGON = "MULTIPOLYGON (((30 20, 10 40, 45 40, 30 20)))";
    final WfsFilterDelegate delegate = setupFilterDelegate(SPATIAL_OPERATORS.INTERSECTS.getValue(), new LatLonCoordinateStrategy());
    delegate.setSupportedGeometryOperands(singletonList(Wfs11Constants.POLYGON));
    final FilterType filter = delegate.intersects(Metacard.ANY_GEO, MULTIPOLYGON_SINGLE_POLYGON);
    assertThat(filter.getSpatialOps().getValue(), is(instanceOf(BinarySpatialOpType.class)));
    final BinarySpatialOpType binarySpatialOpType = (BinarySpatialOpType) filter.getSpatialOps().getValue();
    assertThat(binarySpatialOpType.getGeometry().getValue(), is(instanceOf(PolygonType.class)));
    final PolygonType polygonType = (PolygonType) binarySpatialOpType.getGeometry().getValue();
    assertThat(polygonType.getExterior().getValue().getRing().getValue(), is(instanceOf(LinearRingType.class)));
    final LinearRingType linearRingType = (LinearRingType) polygonType.getExterior().getValue().getRing().getValue();
    assertThat(linearRingType.getCoordinates().getValue(), is("20.0,30.0 40.0,10.0 40.0,45.0 20.0,30.0"));
}
Also used : FilterType(net.opengis.filter.v_1_1_0.FilterType) LinearRingType(net.opengis.gml.v_3_1_1.LinearRingType) BinarySpatialOpType(net.opengis.filter.v_1_1_0.BinarySpatialOpType) PolygonType(net.opengis.gml.v_3_1_1.PolygonType) MultiPolygonType(net.opengis.gml.v_3_1_1.MultiPolygonType) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Test(org.junit.Test)

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