Search in sources :

Example 6 with MultiPolygon

use of com.vividsolutions.jts.geom.MultiPolygon 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)

Example 7 with MultiPolygon

use of com.vividsolutions.jts.geom.MultiPolygon in project series-rest-api by 52North.

the class GeoJSONDecoder method decodeMultiPolygon.

protected MultiPolygon decodeMultiPolygon(JsonNode node, GeometryFactory fac) throws GeoJSONException {
    JsonNode coordinates = requireCoordinates(node);
    Polygon[] polygons = new Polygon[coordinates.size()];
    for (int i = 0; i < coordinates.size(); ++i) {
        polygons[i] = decodePolygonCoordinates(coordinates.get(i), fac);
    }
    return fac.createMultiPolygon(polygons);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Example 8 with MultiPolygon

use of com.vividsolutions.jts.geom.MultiPolygon in project series-rest-api by 52North.

the class GeoJSONTest method testMultiPolygonWithZCoordinate.

@Test
public void testMultiPolygonWithZCoordinate() throws GeoJSONException, IOException {
    MultiPolygon geometry = randomMultiPolygon(CRSUtils.EPSG_WGS84);
    geometry.apply(new RandomZCoordinateFilter());
    geometry.geometryChanged();
    readWriteTest(geometry);
}
Also used : MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Test(org.junit.Test)

Example 9 with MultiPolygon

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

the class Wfs20JTStoGML321Converter method convertToMultiSurfaceType.

/**
     * Converts a @link com.vividsolutions.jts.geom.MultiPolygon to a @link net.opengis.gml.v_3_2_1.MultiSurfaceType
     * Note:  MultiPolygon maps to gml MultiSurfaceType
     *
     * @param multiPolygon
     * @return MultiSurfaceType
     */
public static MultiSurfaceType convertToMultiSurfaceType(MultiPolygon multiPolygon, String srsName) {
    MultiSurfaceType multiSurfaceType = GML320_OBJECT_FACTORY.createMultiSurfaceType();
    for (int i = 0; i < multiPolygon.getNumGeometries(); i++) {
        Polygon poly = (Polygon) multiPolygon.getGeometryN(i);
        PolygonType polygonType = convertToPolygonType(poly, srsName);
        JAXBElement<PolygonType> polygonTypeJAXBElement = GML320_OBJECT_FACTORY.createPolygon(polygonType);
        SurfacePropertyType surfacePropertyType = GML320_OBJECT_FACTORY.createSurfacePropertyType();
        surfacePropertyType.setAbstractSurface(polygonTypeJAXBElement);
        multiSurfaceType.getSurfaceMember().add(surfacePropertyType);
    }
    multiSurfaceType.setSrsName(srsName);
    return multiSurfaceType;
}
Also used : MultiSurfaceType(net.opengis.gml.v_3_2_1.MultiSurfaceType) SurfacePropertyType(net.opengis.gml.v_3_2_1.SurfacePropertyType) PolygonType(net.opengis.gml.v_3_2_1.PolygonType) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Example 10 with MultiPolygon

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

the class TestWfs10JTStoGML200Converter method testGeometryToMultiPolygonGML.

@Test
public void testGeometryToMultiPolygonGML() throws JAXBException, SAXException, IOException, ParseException, NullPointerException {
    MultiPolygon multiPolygon = (MultiPolygon) getGeometryFromWkt(MULTIPOLYGON);
    assertThat(multiPolygon == null, is(Boolean.FALSE));
    String multiPolygonGML = Wfs10JTStoGML200Converter.convertGeometryToGML(multiPolygon).replaceAll("\n", "");
    assertThat(StringUtils.isEmpty(multiPolygonGML), is(Boolean.FALSE));
    Diff diff = XMLUnit.compareXML(multiPolygonGML, MULTIPOLYGON_GML);
    assertTrue(XMLUNIT_IDENTICAL, diff.identical());
    assertTrue(XMLUNIT_SIMILAR, diff.similar());
}
Also used : MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Diff(org.custommonkey.xmlunit.Diff) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) Test(org.junit.Test)

Aggregations

MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)10 Polygon (com.vividsolutions.jts.geom.Polygon)7 Point (com.vividsolutions.jts.geom.Point)6 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)5 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)3 LineString (com.vividsolutions.jts.geom.LineString)3 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)3 Geometry (com.vividsolutions.jts.geom.Geometry)2 MultiSurfaceType (net.opengis.gml.v_3_2_1.MultiSurfaceType)2 PolygonType (net.opengis.gml.v_3_2_1.PolygonType)2 Test (org.junit.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ParseException (com.vividsolutions.jts.io.ParseException)1 WKTReader (com.vividsolutions.jts.io.WKTReader)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1