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;
}
}
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);
}
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);
}
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;
}
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());
}
Aggregations