Search in sources :

Example 6 with LinearRingType

use of net.opengis.gml._3.LinearRingType in project ddf by codice.

the class WfsFilterDelegateTest method testPolygonLonLatOrder.

@Test
public void testPolygonLonLatOrder() {
    final WfsFilterDelegate delegate = setupFilterDelegate(SPATIAL_OPERATORS.INTERSECTS.getValue(), new LonLatCoordinateStrategy());
    final FilterType filter = delegate.intersects(Metacard.ANY_GEO, 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("40.0,-10.0 40.0,30.0 10.0,30.0 10.0,-10.0 40.0,-10.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) Test(org.junit.Test)

Example 7 with LinearRingType

use of net.opengis.gml._3.LinearRingType in project ddf by codice.

the class WfsFilterDelegateTest method testPolygonLatLonOrder.

@Test
public void testPolygonLatLonOrder() {
    final WfsFilterDelegate delegate = setupFilterDelegate(SPATIAL_OPERATORS.INTERSECTS.getValue(), new LatLonCoordinateStrategy());
    final FilterType filter = delegate.intersects(Metacard.ANY_GEO, 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("-10.0,40.0 30.0,40.0 30.0,10.0 -10.0,10.0 -10.0,40.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) Test(org.junit.Test)

Example 8 with LinearRingType

use of net.opengis.gml._3.LinearRingType in project arctic-sea by 52North.

the class GmlEncoderv321 method createPolygonFromJtsGeometry.

/**
 * Creates a XML Polygon from a SOS Polygon.
 *
 * @param jtsPolygon
 *            SOS Polygon
 * @param xbPolType
 *            XML Polygon
 */
private void createPolygonFromJtsGeometry(Polygon jtsPolygon, PolygonType xbPolType) {
    List<?> jtsPolygons = PolygonExtracter.getPolygons(jtsPolygon);
    String srsName = getSrsName(jtsPolygon);
    for (int i = 0; i < jtsPolygons.size(); i++) {
        Polygon pol = (Polygon) jtsPolygons.get(i);
        AbstractRingPropertyType xbArpt = xbPolType.addNewExterior();
        AbstractRingType xbArt = xbArpt.addNewAbstractRing();
        LinearRingType xbLrt = LinearRingType.Factory.newInstance();
        // Exterior ring
        // LineString ring = pol.getExteriorRing();
        Coordinate[] ring = JTSHelper.getExteriorRingCoordinatesFromPolygon(pol);
        DirectPositionListType xbPosList = xbLrt.addNewPosList();
        xbPosList.setSrsName(srsName);
        xbPosList.setStringValue(JTSHelper.getCoordinatesString(ring));
        xbArt.set(xbLrt);
        // Rename element name for output
        XmlCursor cursor = xbArpt.newCursor();
        if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING_32)) {
            cursor.setName(GmlConstants.QN_LINEAR_RING_32);
        }
        cursor.dispose();
        // Interior ring
        int numberOfInteriorRings = pol.getNumInteriorRing();
        for (int ringNumber = 0; ringNumber < numberOfInteriorRings; ringNumber++) {
            xbArpt = xbPolType.addNewInterior();
            xbArt = xbArpt.addNewAbstractRing();
            xbLrt = LinearRingType.Factory.newInstance();
            xbPosList = xbLrt.addNewPosList();
            xbPosList.setSrsName(srsName);
            xbPosList.setStringValue(JTSHelper.getCoordinatesString(pol.getInteriorRingN(ringNumber)));
            xbArt.set(xbLrt);
            // Rename element name for output
            cursor = xbArpt.newCursor();
            if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING_32)) {
                cursor.setName(GmlConstants.QN_LINEAR_RING_32);
            }
            cursor.dispose();
        }
    }
}
Also used : AbstractRingType(net.opengis.gml.x32.AbstractRingType) Coordinate(org.locationtech.jts.geom.Coordinate) AbstractRingPropertyType(net.opengis.gml.x32.AbstractRingPropertyType) LinearRingType(net.opengis.gml.x32.LinearRingType) DirectPositionListType(net.opengis.gml.x32.DirectPositionListType) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Polygon(org.locationtech.jts.geom.Polygon) MultiPoint(org.locationtech.jts.geom.MultiPoint) Point(org.locationtech.jts.geom.Point) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 9 with LinearRingType

use of net.opengis.gml._3.LinearRingType in project geotoolkit by Geomatys.

the class GeometrytoJTSTest method gmlPolygonToJTSTest3D.

@Test
public void gmlPolygonToJTSTest3D() throws Exception {
    GeometryFactory fact = GF;
    final Coordinate[] coordinates = new Coordinate[5];
    coordinates[0] = new Coordinate(0, 0, 1);
    coordinates[1] = new Coordinate(0, 1, 1);
    coordinates[2] = new Coordinate(1, 1, 1);
    coordinates[3] = new Coordinate(1, 0, 1);
    coordinates[4] = new Coordinate(0, 0, 1);
    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(1.0);
    coords.add(0.0);
    coords.add(1.0);
    coords.add(1.0);
    coords.add(1.0);
    coords.add(1.0);
    coords.add(1.0);
    coords.add(1.0);
    coords.add(0.0);
    coords.add(1.0);
    coords.add(0.0);
    coords.add(0.0);
    coords.add(1.0);
    exterior.setPosList(new DirectPositionListType(coords));
    exterior.setSrsDimension(3);
    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 10 with LinearRingType

use of net.opengis.gml._3.LinearRingType in project tiamat by entur.

the class PolygonConverterTest method convertFromWithHoles.

@Test
public void convertFromWithHoles() 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(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))).withInterior(new AbstractRingPropertyType().withAbstractRing(openGisObjectFactory.createLinearRing(linearRing)));
    Polygon polygon = polygonConverter.convertFrom(polygonType, new TypeBuilder<Polygon>() {
    }.build(), new MappingContext(new HashMap<>()));
    assertThat(polygon).isNotNull();
    assertThat(polygon.getExteriorRing().getCoordinates()).hasSize(values.size() / 2);
    assertThat(polygon.getNumInteriorRing()).isEqualTo(1);
    assertCoordinatesMatch(polygon.getExteriorRing(), values, "Exterior ring");
    assertInteriorRingsMatch(polygon, Arrays.asList(values));
}
Also used : MappingContext(ma.glasnost.orika.MappingContext) TypeBuilder(ma.glasnost.orika.metadata.TypeBuilder) HashMap(java.util.HashMap) LinearRingType(net.opengis.gml._3.LinearRingType) AbstractRingPropertyType(net.opengis.gml._3.AbstractRingPropertyType) ArrayList(java.util.ArrayList) DirectPositionListType(net.opengis.gml._3.DirectPositionListType) PolygonType(net.opengis.gml._3.PolygonType) Polygon(org.locationtech.jts.geom.Polygon) 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