Search in sources :

Example 6 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project ddf by codice.

the class TestWfs10JTStoGML200Converter method testGeometryToPolygonGML.

@Test
public void testGeometryToPolygonGML() throws JAXBException, SAXException, IOException, ParseException, NullPointerException {
    Polygon polygon = (Polygon) getGeometryFromWkt(POLYGON);
    assertThat(polygon == null, is(Boolean.FALSE));
    String polygonGML = Wfs10JTStoGML200Converter.convertGeometryToGML(polygon).replaceAll("\n", "");
    assertThat(StringUtils.isEmpty(polygonGML), is(Boolean.FALSE));
    Diff diff = XMLUnit.compareXML(polygonGML, POLYGON_GML);
    assertTrue(XMLUNIT_SIMILAR, diff.similar());
    assertTrue(XMLUNIT_IDENTICAL, diff.identical());
}
Also used : Diff(org.custommonkey.xmlunit.Diff) 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 7 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project ddf by codice.

the class WfsFilterDelegate method createGeometryOperand.

private JAXBElement<? extends AbstractGeometryType> createGeometryOperand(String wkt) {
    String convertedWkt = wkt;
    Geometry wktGeometry = null;
    try {
        wktGeometry = getGeometryFromWkt(convertedWkt);
    } catch (ParseException e) {
        throw new IllegalArgumentException("Unable to parse WKT Geometry [" + convertedWkt + "]", e);
    }
    if (wktGeometry instanceof Polygon) {
        if (isGeometryOperandSupported(Wfs10Constants.POLYGON)) {
            return createPolygon(convertedWkt);
        } else {
            throw new IllegalArgumentException("The Polygon operand is not supported.");
        }
    } else if (wktGeometry instanceof Point) {
        if (isGeometryOperandSupported(Wfs10Constants.POINT)) {
            return createPoint(convertedWkt);
        } else {
            throw new IllegalArgumentException("The Point operand is not supported.");
        }
    } else if (wktGeometry instanceof LineString) {
        if (isGeometryOperandSupported(Wfs10Constants.LINESTRING)) {
            return createLineString(wktGeometry);
        } else {
            throw new IllegalArgumentException("The LineString operand is not supported.");
        }
    } else if (wktGeometry instanceof MultiPoint) {
        if (isGeometryOperandSupported(Wfs10Constants.MULTI_POINT)) {
            return createMultiPoint(wktGeometry);
        } else {
            throw new IllegalArgumentException("The MultiPoint operand is not supported.");
        }
    } else if (wktGeometry instanceof MultiLineString) {
        if (isGeometryOperandSupported(Wfs10Constants.MULTI_LINESTRING)) {
            return createMultiLineString(wktGeometry);
        } else {
            throw new IllegalArgumentException("The MultiLineString operand is not supported.");
        }
    } else if (wktGeometry instanceof MultiPolygon) {
        if (isGeometryOperandSupported(Wfs10Constants.MULTI_POLYGON)) {
            return createMultiPolygon(wktGeometry);
        } else {
            throw new IllegalArgumentException("The MultiPolygon operand is not supported.");
        }
    } else if (wktGeometry instanceof GeometryCollection) {
        if (isGeometryOperandSupported(Wfs10Constants.GEOMETRY_COLLECTION)) {
            return createGeometryCollection(wktGeometry);
        } else {
            throw new IllegalArgumentException("The GeometryCollection operand is not supported.");
        }
    }
    throw new IllegalArgumentException("Unable to create Geometry from WKT String");
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) ParseException(com.vividsolutions.jts.io.ParseException) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 8 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project GeoGig by boundlessgeo.

the class GeoGigFeatureSourceTest method testGetBoundsQuery.

@Test
public void testGetBoundsQuery() throws Exception {
    ReferencedEnvelope bounds;
    Filter filter;
    filter = ff.id(Collections.singleton(ff.featureId(RepositoryTestCase.idP2)));
    bounds = pointsSource.getBounds(new Query(pointsName, filter));
    assertEquals(boundsOf(points2), bounds);
    ReferencedEnvelope queryBounds = boundsOf(points1, points2);
    Polygon geometry = JTS.toGeometry(queryBounds);
    filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
    bounds = pointsSource.getBounds(new Query(pointsName, filter));
    assertEquals(boundsOf(points1, points2), bounds);
    ReferencedEnvelope transformedQueryBounds;
    CoordinateReferenceSystem queryCrs = CRS.decode("EPSG:3857");
    transformedQueryBounds = queryBounds.transform(queryCrs, true);
    geometry = JTS.toGeometry(transformedQueryBounds);
    geometry.setUserData(queryCrs);
    filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
    bounds = pointsSource.getBounds(new Query(pointsName, filter));
    assertEquals(boundsOf(points1, points2), bounds);
    filter = ECQL.toFilter("sp = 'StringProp2_3' OR ip = 2000");
    bounds = linesSource.getBounds(new Query(linesName, filter));
    assertEquals(boundsOf(lines3, lines2), bounds);
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Query(org.geotools.data.Query) Filter(org.opengis.filter.Filter) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Polygon(com.vividsolutions.jts.geom.Polygon) Test(org.junit.Test)

Example 9 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project GeoGig by boundlessgeo.

the class GeoGigFeatureSourceTest method testGetCount.

@Test
public void testGetCount() throws Exception {
    assertEquals(3, pointsSource.getCount(Query.ALL));
    assertEquals(3, linesSource.getCount(Query.ALL));
    Filter filter;
    filter = ff.id(Collections.singleton(ff.featureId(RepositoryTestCase.idP2)));
    assertEquals(1, pointsSource.getCount(new Query(pointsName, filter)));
    ReferencedEnvelope queryBounds = boundsOf(points1, points2);
    Polygon geometry = JTS.toGeometry(queryBounds);
    filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
    assertEquals(2, pointsSource.getCount(new Query(pointsName, filter)));
    ReferencedEnvelope transformedQueryBounds;
    CoordinateReferenceSystem queryCrs = CRS.decode("EPSG:3857");
    transformedQueryBounds = queryBounds.transform(queryCrs, true);
    geometry = JTS.toGeometry(transformedQueryBounds);
    geometry.setUserData(queryCrs);
    filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
    assertEquals(2, pointsSource.getCount(new Query(pointsName, filter)));
    filter = ECQL.toFilter("sp = 'StringProp2_3' OR ip = 2000");
    assertEquals(2, linesSource.getCount(new Query(linesName, filter)));
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Query(org.geotools.data.Query) Filter(org.opengis.filter.Filter) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Polygon(com.vividsolutions.jts.geom.Polygon) Test(org.junit.Test)

Example 10 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project dhis2-core by dhis2.

the class GeoUtils method checkPointWithMultiPolygon.

/**
     * Check if the point coordinate falls within the polygon/MultiPolygon Shape
     *
     * @param longitude the longitude.
     * @param latitude the latitude.
     * @param multiPolygonJson the GeoJSON coordinates of the MultiPolygon
     * @param featureType the featureType of the MultiPolygon.
     */
public static boolean checkPointWithMultiPolygon(double longitude, double latitude, String multiPolygonJson, FeatureType featureType) {
    try {
        boolean contains = false;
        GeometryJSON gtjson = new GeometryJSON();
        Point point = getGeoJsonPoint(longitude, latitude);
        if (point != null && point.isValid()) {
            if (featureType == FeatureType.POLYGON) {
                Polygon polygon = gtjson.readPolygon(new StringReader("{\"type\":\"Polygon\", \"coordinates\":" + multiPolygonJson + "}"));
                contains = polygon.contains(point);
            } else if (featureType == FeatureType.MULTI_POLYGON) {
                MultiPolygon multiPolygon = gtjson.readMultiPolygon(new StringReader("{\"type\":\"MultiPolygon\", \"coordinates\":" + multiPolygonJson + "}"));
                contains = multiPolygon.contains(point);
            }
        }
        return contains;
    } catch (Exception ex) {
        return false;
    }
}
Also used : GeometryJSON(org.geotools.geojson.geom.GeometryJSON) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) StringReader(java.io.StringReader) Point(com.vividsolutions.jts.geom.Point) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) IOException(java.io.IOException)

Aggregations

Polygon (com.vividsolutions.jts.geom.Polygon)112 LinearRing (com.vividsolutions.jts.geom.LinearRing)51 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)34 Test (org.junit.Test)32 Coordinate (com.vividsolutions.jts.geom.Coordinate)30 Point (com.vividsolutions.jts.geom.Point)27 PackedCoordinateSequence (com.vividsolutions.jts.geom.impl.PackedCoordinateSequence)27 ArrayList (java.util.ArrayList)26 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)24 Resource (org.openrdf.model.Resource)24 Statement (org.openrdf.model.Statement)24 URI (org.openrdf.model.URI)24 Value (org.openrdf.model.Value)24 ValueFactory (org.openrdf.model.ValueFactory)24 ContextStatementImpl (org.openrdf.model.impl.ContextStatementImpl)24 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)24 Geometry (com.vividsolutions.jts.geom.Geometry)22 LineString (com.vividsolutions.jts.geom.LineString)22 List (java.util.List)20 PersistenceManager (javax.jdo.PersistenceManager)15