Search in sources :

Example 6 with PolygonType

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

the class TestWfs10JTStoGML200Converter method testPolygonTypeToJAXB.

@Test
public void testPolygonTypeToJAXB() 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));
    JAXBElement<PolygonType> polygonTypeJAXBElement = (JAXBElement<PolygonType>) Wfs10JTStoGML200Converter.convertGeometryTypeToJAXB(polygonType);
    assertThat(polygonTypeJAXBElement.getName().getLocalPart().equals(Wfs10Constants.POLYGON.getLocalPart()), is(Boolean.TRUE));
    assertThat(polygonTypeJAXBElement.getDeclaredType() == PolygonType.class, is(Boolean.TRUE));
    JAXB.marshal(polygonTypeJAXBElement, writer);
    String xml = writer.toString();
    Diff diff = XMLUnit.compareXML(xml, POLYGON_GML);
    assertTrue(XMLUNIT_SIMILAR, diff.similar());
    assertThat(diff.similar(), is(Boolean.TRUE));
    assertThat(diff.identical(), is(Boolean.FALSE));
}
Also used : Diff(org.custommonkey.xmlunit.Diff) 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) JAXBElement(javax.xml.bind.JAXBElement) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) Test(org.junit.Test)

Example 7 with PolygonType

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

the class WfsFilterDelegate method createPolygon.

private JAXBElement<PolygonType> createPolygon(String wkt) {
    PolygonType polygon = new PolygonType();
    LinearRingType linearRing = new LinearRingType();
    Coordinate[] coordinates = getCoordinatesFromWkt(wkt);
    if (coordinates != null && coordinates.length > 0) {
        StringBuffer coordString = new StringBuffer();
        for (Coordinate coordinate : coordinates) {
            coordString.append(coordinate.x).append(",").append(coordinate.y).append(" ");
        }
        CoordinatesType coordinatesType = new CoordinatesType();
        coordinatesType.setValue(coordString.toString());
        coordinatesType.setDecimal(".");
        coordinatesType.setCs(",");
        coordinatesType.setTs(" ");
        linearRing.setCoordinates(coordinatesType);
        LinearRingMemberType member = new LinearRingMemberType();
        member.setGeometry(gmlObjectFactory.createLinearRing(linearRing));
        polygon.setOuterBoundaryIs(member);
        polygon.setSrsName(srsName);
        return gmlObjectFactory.createPolygon(polygon);
    } else {
        throw new IllegalArgumentException("Unable to parse Polygon coordinates from WKT String");
    }
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) LinearRingType(ogc.schema.opengis.gml.v_2_1_2.LinearRingType) LinearRingMemberType(ogc.schema.opengis.gml.v_2_1_2.LinearRingMemberType) MultiPolygonType(ogc.schema.opengis.gml.v_2_1_2.MultiPolygonType) PolygonType(ogc.schema.opengis.gml.v_2_1_2.PolygonType) CoordinatesType(ogc.schema.opengis.gml.v_2_1_2.CoordinatesType)

Example 8 with PolygonType

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

the class CswQueryFactoryTest method createPolygon.

private JAXBElement<AbstractGeometryType> createPolygon() {
    PolygonType localPolygon = new PolygonType();
    LinearRingType ring = new LinearRingType();
    for (Coordinate coordinate : polygon.getCoordinates()) {
        CoordType coord = new CoordType();
        coord.setX(BigDecimal.valueOf(coordinate.x));
        coord.setY(BigDecimal.valueOf(coordinate.y));
        if (!Double.isNaN(coordinate.z)) {
            coord.setZ(BigDecimal.valueOf(coordinate.z));
        }
        ring.getCoord().add(coord);
    }
    AbstractRingPropertyType abstractRing = new AbstractRingPropertyType();
    abstractRing.setRing(gmlObjectFactory.createLinearRing(ring));
    localPolygon.setExterior(gmlObjectFactory.createExterior(abstractRing));
    JAXBElement<AbstractGeometryType> agt = new JAXBElement<>(new QName("http://www.opengis.net/gml", "Polygon"), AbstractGeometryType.class, null, localPolygon);
    return agt;
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) AbstractGeometryType(net.opengis.gml.v_3_1_1.AbstractGeometryType) LinearRingType(net.opengis.gml.v_3_1_1.LinearRingType) AbstractRingPropertyType(net.opengis.gml.v_3_1_1.AbstractRingPropertyType) QName(javax.xml.namespace.QName) PolygonType(net.opengis.gml.v_3_1_1.PolygonType) JAXBElement(javax.xml.bind.JAXBElement) CoordType(net.opengis.gml.v_3_1_1.CoordType)

Example 9 with PolygonType

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

the class Wfs20JTStoGML321Converter method convertToPolygonType.

public static PolygonType convertToPolygonType(Polygon polygon, String srsName) {
    PolygonType polygonType = GML320_OBJECT_FACTORY.createPolygonType();
    // exterior
    LineString lineString = polygon.getExteriorRing();
    LinearRing linearRing = lineString.getFactory().createLinearRing(lineString.getCoordinateSequence());
    RingType ringType = convertToRingType(linearRing, srsName);
    JAXBElement<RingType> ringTypeJAXBElement = GML320_OBJECT_FACTORY.createRing(ringType);
    AbstractRingPropertyType abstractRingPropertyType = GML320_OBJECT_FACTORY.createAbstractRingPropertyType();
    abstractRingPropertyType.setAbstractRing(ringTypeJAXBElement);
    polygonType.setExterior(abstractRingPropertyType);
    // interiors
    for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
        LineString interiorRingN = polygon.getInteriorRingN(i);
        LinearRing linearRing1 = interiorRingN.getFactory().createLinearRing(interiorRingN.getCoordinateSequence());
        RingType ringType1 = convertToRingType(linearRing1, srsName);
        JAXBElement<RingType> ringTypeJAXBElement1 = GML320_OBJECT_FACTORY.createRing(ringType1);
        AbstractRingPropertyType abstractRingPropertyType1 = GML320_OBJECT_FACTORY.createAbstractRingPropertyType();
        abstractRingPropertyType1.setAbstractRing(ringTypeJAXBElement1);
        polygonType.getInterior().add(abstractRingPropertyType1);
    }
    polygonType.setSrsName(srsName);
    return polygonType;
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) AbstractRingPropertyType(net.opengis.gml.v_3_2_1.AbstractRingPropertyType) PolygonType(net.opengis.gml.v_3_2_1.PolygonType) LinearRing(org.locationtech.jts.geom.LinearRing) RingType(net.opengis.gml.v_3_2_1.RingType) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 10 with PolygonType

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

the class Wfs20JTStoGML321Converter method createGeometryPropertyType.

private static GeometryPropertyType createGeometryPropertyType(Geometry geometry, String srsName) {
    final GeometryPropertyType geometryPropertyType = GML320_OBJECT_FACTORY.createGeometryPropertyType();
    if (geometry instanceof Point) {
        PointType pointType = convertToPointType((Point) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertPointTypeToJAXB(pointType));
    } else if (geometry instanceof LineString) {
        LineStringType lineStringType = convertToLineStringType((LineString) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertLineStringTypeToJAXB(lineStringType));
    } else if (geometry instanceof Polygon) {
        PolygonType polygonType = convertToPolygonType((Polygon) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertPolygonTypeToJAXB(polygonType));
    } else if (geometry instanceof MultiPoint) {
        MultiPointType multiPointType = convertToMultiPointType((MultiPoint) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertMultiPointTypeToJAXB(multiPointType));
    } else if (geometry instanceof MultiLineString) {
        MultiCurveType multiCurveType = convertToMultiLineStringType((MultiLineString) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertMultiCurveTypeToJAXB(multiCurveType));
    } else if (geometry instanceof MultiPolygon) {
        MultiSurfaceType multiSurfaceType = convertToMultiSurfaceType((MultiPolygon) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertMultiSurfaceTypeToJAXB(multiSurfaceType));
    } else if (geometry instanceof GeometryCollection) {
        MultiGeometryType multiGeometryType = convertToMultiGeometryType((GeometryCollection) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertMultiGeometryTypeToJAXB(multiGeometryType));
    } else {
        throw new IllegalArgumentException();
    }
    return geometryPropertyType;
}
Also used : MultiPoint(org.locationtech.jts.geom.MultiPoint) MultiLineString(org.locationtech.jts.geom.MultiLineString) MultiCurveType(net.opengis.gml.v_3_2_1.MultiCurveType) MultiGeometryType(net.opengis.gml.v_3_2_1.MultiGeometryType) PolygonType(net.opengis.gml.v_3_2_1.PolygonType) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) LineStringType(net.opengis.gml.v_3_2_1.LineStringType) MultiPointType(net.opengis.gml.v_3_2_1.MultiPointType) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) MultiSurfaceType(net.opengis.gml.v_3_2_1.MultiSurfaceType) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) PointType(net.opengis.gml.v_3_2_1.PointType) MultiPointType(net.opengis.gml.v_3_2_1.MultiPointType) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) GeometryPropertyType(net.opengis.gml.v_3_2_1.GeometryPropertyType)

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