Search in sources :

Example 31 with Point

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

the class GeoUtilTest method testTransformEpsg4326UTM.

@Test
public void testTransformEpsg4326UTM() throws FactoryException, TransformException, GeoFormatException {
    double lon = 33.45;
    double lat = 25.22;
    double easting = 545328.48;
    double northing = 2789384.24;
    CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:32636");
    GeometryFactory geometryFactory = new GeometryFactory();
    Coordinate utmCoordinate = new Coordinate(easting, northing);
    Point utmPoint = geometryFactory.createPoint(utmCoordinate);
    Envelope envelope = JTS.toEnvelope(utmPoint);
    Geometry utmGeometry = JTS.toGeometry(envelope);
    Geometry lonLatGeom = GeospatialUtil.transformToEPSG4326LonLatFormat(utmGeometry, sourceCRS);
    assertThat(lonLatGeom.getCoordinates()[0].x, closeTo(lon, .00001));
    assertThat(lonLatGeom.getCoordinates()[0].y, closeTo(lat, .00001));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Point(com.vividsolutions.jts.geom.Point) Envelope(com.vividsolutions.jts.geom.Envelope) Test(org.junit.Test)

Example 32 with Point

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

the class GeoUtilTest method testTransformEpsg4326LonLatNullSrs.

@Test
public void testTransformEpsg4326LonLatNullSrs() throws GeoFormatException {
    GeometryFactory gf = new GeometryFactory();
    Coordinate coord = new Coordinate(25.22, 33.45);
    Point point = gf.createPoint(coord);
    Geometry geom = GeospatialUtil.transformToEPSG4326LonLatFormat(point, (String) null);
    assertThat(geom, is(point));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) Point(com.vividsolutions.jts.geom.Point) Test(org.junit.Test)

Example 33 with Point

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

the class GeoUtilTest method testTransformEpsg4326LonLatBadSrs.

@Test(expected = GeoFormatException.class)
public void testTransformEpsg4326LonLatBadSrs() throws GeoFormatException {
    GeometryFactory gf = new GeometryFactory();
    Coordinate coord = new Coordinate(25.22, 33.45);
    Point point = gf.createPoint(coord);
    Geometry geom = GeospatialUtil.transformToEPSG4326LonLatFormat(point, "ESPG:Bad");
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) Point(com.vividsolutions.jts.geom.Point) Test(org.junit.Test)

Example 34 with Point

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

the class GeoUtilTest method testTransformEpsg4326EpsgNoSourceCRS.

@Test
public void testTransformEpsg4326EpsgNoSourceCRS() throws FactoryException, TransformException, GeoFormatException {
    double lon = 33.45;
    double lat = 25.22;
    CoordinateReferenceSystem sourceCRS = null;
    GeometryFactory geometryFactory = new GeometryFactory();
    Coordinate coordinate = new Coordinate(lon, lat);
    Point utmPoint = geometryFactory.createPoint(coordinate);
    Envelope envelope = JTS.toEnvelope(utmPoint);
    Geometry utmGeometry = JTS.toGeometry(envelope);
    Geometry lonLatGeom = GeospatialUtil.transformToEPSG4326LonLatFormat(utmGeometry, sourceCRS);
    assertThat(lonLatGeom.getCoordinates()[0].x, closeTo(lon, .00001));
    assertThat(lonLatGeom.getCoordinates()[0].y, closeTo(lat, .00001));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Point(com.vividsolutions.jts.geom.Point) Envelope(com.vividsolutions.jts.geom.Envelope) Test(org.junit.Test)

Example 35 with Point

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

the class DynamicSchemaResolver method createCenterPoint.

private String createCenterPoint(List<Serializable> values) {
    WKTReader reader = new WKTReader(GEOMETRY_FACTORY);
    List<Geometry> geometries = new ArrayList<>();
    for (Serializable serializable : values) {
        String wkt = serializable.toString();
        try {
            geometries.add(reader.read(wkt));
        } catch (ParseException e) {
            LOGGER.debug("Failed to read WKT, skipping: {}", wkt, e);
        }
    }
    if (geometries.isEmpty()) {
        return null;
    }
    Point centerPoint;
    if (geometries.size() > 1) {
        GeometryCollection geoCollection = GEOMETRY_FACTORY.createGeometryCollection(geometries.toArray(new Geometry[geometries.size()]));
        centerPoint = geoCollection.getCentroid();
    } else {
        centerPoint = geometries.get(0).getCentroid();
    }
    return centerPoint.getY() + "," + centerPoint.getX();
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) ParseException(com.vividsolutions.jts.io.ParseException) Point(com.vividsolutions.jts.geom.Point) WKTReader(com.vividsolutions.jts.io.WKTReader)

Aggregations

Point (com.vividsolutions.jts.geom.Point)48 Coordinate (com.vividsolutions.jts.geom.Coordinate)21 Geometry (com.vividsolutions.jts.geom.Geometry)15 Test (org.junit.Test)12 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)11 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)10 Polygon (com.vividsolutions.jts.geom.Polygon)9 LineString (com.vividsolutions.jts.geom.LineString)7 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)5 Envelope (com.vividsolutions.jts.geom.Envelope)4 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)4 ParseException (com.vividsolutions.jts.io.ParseException)4 ArrayList (java.util.ArrayList)4 GeojsonPoint (org.n52.io.geojson.old.GeojsonPoint)4 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)3 StringReader (java.io.StringReader)3 SolrQuery (org.apache.solr.client.solrj.SolrQuery)3 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)3 JtsPoint (org.locationtech.spatial4j.shape.jts.JtsPoint)3