Search in sources :

Example 6 with FeatureType

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;
    }
}
Also used : FeatureType(org.hisp.dhis.organisationunit.FeatureType) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Point(org.locationtech.jts.geom.Point) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) IOException(java.io.IOException)

Aggregations

FeatureType (org.hisp.dhis.organisationunit.FeatureType)6 IOException (java.io.IOException)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)1 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)1 Program (org.hisp.dhis.program.Program)1 ProgramInstance (org.hisp.dhis.program.ProgramInstance)1 RelationshipItem (org.hisp.dhis.relationship.RelationshipItem)1 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)1 TrackedEntityProgramOwner (org.hisp.dhis.trackedentity.TrackedEntityProgramOwner)1 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)1 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)1 TrackerErrorReport (org.hisp.dhis.tracker.report.TrackerErrorReport)1 Geometry (org.locationtech.jts.geom.Geometry)1 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)1 Point (org.locationtech.jts.geom.Point)1 Polygon (org.locationtech.jts.geom.Polygon)1