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