Search in sources :

Example 11 with PolygonType

use of net.opengis.gml.x32.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 12 with PolygonType

use of net.opengis.gml.x32.PolygonType 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 PolygonType

use of net.opengis.gml.x32.PolygonType in project arctic-sea by 52North.

the class GmlDecoderv321 method parseCompositeSurfaceType.

private Geometry parseCompositeSurfaceType(CompositeSurfaceType xbCompositeSurface) throws DecodingException {
    SurfacePropertyType[] xbCurfaceProperties = xbCompositeSurface.getSurfaceMemberArray();
    int srid = -1;
    ArrayList<Polygon> polygons = new ArrayList<>(xbCurfaceProperties.length);
    if (xbCompositeSurface.getSrsName() != null) {
        srid = CRSHelper.parseSrsName(xbCompositeSurface.getSrsName());
    }
    for (SurfacePropertyType xbSurfaceProperty : xbCurfaceProperties) {
        AbstractSurfaceType xbAbstractSurface = xbSurfaceProperty.getAbstractSurface();
        if (srid == -1 && xbAbstractSurface.getSrsName() != null) {
            srid = CRSHelper.parseSrsName(xbAbstractSurface.getSrsName());
        }
        if (xbAbstractSurface instanceof PolygonType) {
            polygons.add((Polygon) parsePolygonType((PolygonType) xbAbstractSurface));
        } else {
            throw new DecodingException("The FeatureType %s is not supportted! Only PolygonType", xbAbstractSurface);
        }
    }
    if (polygons.isEmpty()) {
        throw new DecodingException("The FeatureType: %s does not contain any member!", xbCompositeSurface);
    }
    srid = setDefaultForUnsetSrid(srid);
    GeometryFactory factory = new GeometryFactory();
    Geometry geom = factory.createMultiPolygon(polygons.toArray(new Polygon[polygons.size()]));
    geom.setSRID(srid);
    return geom;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) AbstractSurfaceType(net.opengis.gml.x32.AbstractSurfaceType) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) SurfacePropertyType(net.opengis.gml.x32.SurfacePropertyType) ArrayList(java.util.ArrayList) PolygonType(net.opengis.gml.x32.PolygonType) DecodingException(org.n52.svalbard.decode.exception.DecodingException) Polygon(org.locationtech.jts.geom.Polygon)

Aggregations

LineString (com.vividsolutions.jts.geom.LineString)4 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)4 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)4 Polygon (com.vividsolutions.jts.geom.Polygon)4 PolygonType (net.opengis.gml.v_3_2_1.PolygonType)4 MultiPolygonType (ogc.schema.opengis.gml.v_2_1_2.MultiPolygonType)4 PolygonType (ogc.schema.opengis.gml.v_2_1_2.PolygonType)4 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)3 Point (com.vividsolutions.jts.geom.Point)3 LinearRingMemberType (ogc.schema.opengis.gml.v_2_1_2.LinearRingMemberType)3 LinearRingType (ogc.schema.opengis.gml.v_2_1_2.LinearRingType)3 Polygon (org.locationtech.jts.geom.Polygon)3 Coordinate (com.vividsolutions.jts.geom.Coordinate)2 JAXBElement (javax.xml.bind.JAXBElement)2 AbstractRingPropertyType (net.opengis.gml.v_3_2_1.AbstractRingPropertyType)2 MultiSurfaceType (net.opengis.gml.v_3_2_1.MultiSurfaceType)2 AbstractRingPropertyType (net.opengis.gml.x32.AbstractRingPropertyType)2 AbstractRingType (net.opengis.gml.x32.AbstractRingType)2 LineString (org.locationtech.jts.geom.LineString)2 MultiLineString (org.locationtech.jts.geom.MultiLineString)2