Search in sources :

Example 6 with GeometryJSON

use of org.geotools.geojson.geom.GeometryJSON in project dhis2-core by dhis2.

the class GeoUtilsTest method testVerifyPointIsWithinMultiPolygon.

@Test
void testVerifyPointIsWithinMultiPolygon() throws IOException {
    String downtownOslo = TestResourceUtils.getFileContent("gis/brasilMultiPolygon.json");
    Geometry g = new GeometryJSON().read(downtownOslo);
    boolean result = GeoUtils.checkPointWithMultiPolygon(-43.96728515625, -16.699340234594537, g);
    assertTrue(result);
    result = GeoUtils.checkPointWithMultiPolygon(-43.681640625, -18.698285474146807, g);
    assertFalse(result);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryJSON(org.geotools.geojson.geom.GeometryJSON) Test(org.junit.jupiter.api.Test)

Example 7 with GeometryJSON

use of org.geotools.geojson.geom.GeometryJSON in project dhis2-core by dhis2.

the class GeoUtilsTest method testVerifyPointIsWithinPolygon.

@Test
void testVerifyPointIsWithinPolygon() throws IOException {
    String downtownOslo = TestResourceUtils.getFileContent("gis/downtownOslo.json");
    Geometry g = new GeometryJSON().read(downtownOslo);
    boolean result = GeoUtils.checkPointWithMultiPolygon(10.746517181396484, 59.91080384720672, g);
    assertTrue(result);
    result = GeoUtils.checkPointWithMultiPolygon(10.755915641784668, 59.9139664757207, g);
    assertFalse(result);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryJSON(org.geotools.geojson.geom.GeometryJSON) Test(org.junit.jupiter.api.Test)

Example 8 with GeometryJSON

use of org.geotools.geojson.geom.GeometryJSON in project dhis2-core by dhis2.

the class GeoUtils method getGeometryFromCoordinatesAndType.

public static Geometry getGeometryFromCoordinatesAndType(FeatureType featureType, String coordinates) throws IOException {
    GeometryJSON geometryJSON = new GeometryJSON();
    if (featureType.equals(FeatureType.NONE) || featureType.equals(FeatureType.SYMBOL)) {
        throw new IllegalArgumentException("Invalid featureType '" + featureType.value() + "'");
    }
    Geometry geometry = geometryJSON.read(String.format("{\"type\": \"%s\", \"coordinates\": %s}", featureType.value(), coordinates));
    geometry.setSRID(SRID);
    return geometry;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryJSON(org.geotools.geojson.geom.GeometryJSON)

Example 9 with GeometryJSON

use of org.geotools.geojson.geom.GeometryJSON in project dhis2-core by dhis2.

the class GeoUtils method getGeoJsonPoint.

/**
 * Get GeometryJSON point.
 *
 * @param longitude the longitude.
 * @param latitude the latitude.
 * @return the GeoJSON representation of the given point.
 */
public static Point getGeoJsonPoint(double longitude, double latitude) throws IOException {
    Point point = new GeometryJSON().readPoint(new StringReader("{\"type\":\"Point\", \"coordinates\":[" + longitude + "," + latitude + "]}"));
    point.setSRID(SRID);
    return point;
}
Also used : GeometryJSON(org.geotools.geojson.geom.GeometryJSON) StringReader(java.io.StringReader) Point(org.locationtech.jts.geom.Point)

Example 10 with GeometryJSON

use of org.geotools.geojson.geom.GeometryJSON in project dhis2-core by dhis2.

the class OrganisationUnitPolygonCoveringCoordinateFilterTest method verifyFilterIncludesOrgUnitFallingInsidePolygon.

@Test
void verifyFilterIncludesOrgUnitFallingInsidePolygon() throws IOException {
    filter = new OrganisationUnitPolygonCoveringCoordinateFilter(10.746517181396484, 59.91080384720672);
    Geometry ouGeometry = new GeometryJSON().read(DOWNTOWN_OSLO);
    organisationUnit.setGeometry(ouGeometry);
    assertTrue(filter.retain(organisationUnit));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryJSON(org.geotools.geojson.geom.GeometryJSON) Test(org.junit.jupiter.api.Test)

Aggregations

GeometryJSON (org.geotools.geojson.geom.GeometryJSON)12 Geometry (org.locationtech.jts.geom.Geometry)6 Test (org.junit.jupiter.api.Test)4 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)2 BufferedWriter (java.io.BufferedWriter)2 IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 StringReader (java.io.StringReader)2 JsonFactory (org.codehaus.jackson.JsonFactory)2 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)1 Point (com.vividsolutions.jts.geom.Point)1 Polygon (com.vividsolutions.jts.geom.Polygon)1 StringWriter (java.io.StringWriter)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Point (org.locationtech.jts.geom.Point)1 ConcaveHull (org.opensphere.geometry.algorithm.ConcaveHull)1 ReversibleLineStringWrapper (org.opentripplanner.common.geometry.ReversibleLineStringWrapper)1 AStar (org.opentripplanner.routing.algorithm.AStar)1 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)1 State (org.opentripplanner.routing.core.State)1