use of org.hisp.dhis.organisationunit.FeatureType 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 geometry the GeoJSON coordinates of the MultiPolygon
*/
public static boolean checkPointWithMultiPolygon(double longitude, double latitude, Geometry geometry) {
try {
boolean contains = false;
Point point = getGeoJsonPoint(longitude, latitude);
FeatureType featureType = FeatureType.getTypeFromName(geometry.getGeometryType());
if (point != null && point.isValid()) {
if (featureType == FeatureType.POLYGON) {
Polygon polygon = (Polygon) geometry;
contains = polygon.contains(point);
} else if (featureType == FeatureType.MULTI_POLYGON) {
MultiPolygon multiPolygon = (MultiPolygon) geometry;
contains = multiPolygon.contains(point);
}
}
return contains;
} catch (Exception ex) {
return false;
}
}
Aggregations