use of org.locationtech.jts.geom.Coordinate in project ddf by codice.
the class AbstractFeatureConverterWfs20 method swapCoordinates.
private void swapCoordinates(Geometry geo) {
LOGGER.debug("Swapping Lat/Lon Coords to Lon/Lat using Geometry");
geo.apply(new CoordinateFilter() {
@Override
public void filter(Coordinate coordinate) {
double x = coordinate.x;
double y = coordinate.y;
coordinate.y = x;
coordinate.x = y;
}
});
geo.geometryChanged();
}
use of org.locationtech.jts.geom.Coordinate in project ddf by codice.
the class GmdTransformer method setLocationFromPolygon.
private void setLocationFromPolygon(String boundingPolygon, MetacardImpl metacard) {
try {
String[] stringArray = boundingPolygon.split(" ");
List<Coordinate> coordinates = new ArrayList<>();
for (int i = 0; i < stringArray.length - 1; i += 2) {
coordinates.add(new Coordinate(Double.parseDouble(stringArray[i]), Double.parseDouble(stringArray[i + 1])));
}
LinearRing linearRing = factory.createLinearRing(coordinates.toArray(new Coordinate[coordinates.size()]));
String wkt = WKT_WRITER_THREAD_LOCAL.get().write(factory.createPolygon(linearRing, null));
if (wkt != null) {
metacard.setAttribute(Core.LOCATION, wkt);
}
} catch (NumberFormatException nfe) {
LOGGER.debug("Unable to parse double in {}. Metacard location will not be set.", boundingPolygon);
}
}
use of org.locationtech.jts.geom.Coordinate in project ddf by codice.
the class GeoJsonExtensibleTest method verifyBasics.
private void verifyBasics(Metacard metacard) throws ParseException {
assertEquals(DEFAULT_TITLE, metacard.getTitle());
assertEquals(DEFAULT_URI, metacard.getResourceURI().toString());
assertEquals(DEFAULT_TYPE, metacard.getContentTypeName());
assertEquals(DEFAULT_VERSION, metacard.getContentTypeVersion());
assertEquals("<xml></xml>", metacard.getMetadata());
assertEquals(DEFAULT_CREATED_DATE, metacard.getCreatedDate().toInstant().toString());
assertEquals(DEFAULT_MODIFIED_DATE, metacard.getModifiedDate().toInstant().toString());
assertEquals(DEFAULT_EXPIRATION_DATE, metacard.getExpirationDate().toInstant().toString());
assertEquals(DEFAULT_EFFECTIVE_DATE, metacard.getEffectiveDate().toInstant().toString());
assertArrayEquals(DEFAULT_BYTES, metacard.getThumbnail());
assertEquals(DEFAULT_TEMPERATURE, metacard.getAttribute(TEMPERATURE_KEY).getValue());
assertEquals(MetacardImpl.BASIC_METACARD.getName(), metacard.getMetacardType().getName());
WKTReader reader = new WKTReader();
Geometry geometry = reader.read(metacard.getLocation());
Coordinate[] coords = geometry.getCoordinates();
assertThat(coords[0].x, is(30.0));
assertThat(coords[0].y, is(10.0));
assertThat(coords[1].x, is(10.0));
assertThat(coords[1].y, is(30.0));
assertThat(coords[2].x, is(40.0));
assertThat(coords[2].y, is(40.0));
}
use of org.locationtech.jts.geom.Coordinate in project ddf by codice.
the class GeoUtilTest method testTransformEpsg4326LonLat.
@Test
public void testTransformEpsg4326LonLat() throws GeoFormatException {
GeometryFactory gf = new GeometryFactory();
Coordinate coord = new Coordinate(25.22, 33.45);
Point point = gf.createPoint(coord);
Geometry convertedGeometry = GeospatialUtil.transformToEPSG4326LonLatFormat(point, GeospatialUtil.EPSG_4326);
assertThat(convertedGeometry.getCoordinates()[0].x, is(33.45));
assertThat(convertedGeometry.getCoordinates()[0].y, is(25.22));
}
use of org.locationtech.jts.geom.Coordinate in project ddf by codice.
the class GeoUtilTest method testTransformEpsg4326EpsgMatch.
@Test
public void testTransformEpsg4326EpsgMatch() throws FactoryException, TransformException, GeoFormatException {
double lon = 33.45;
double lat = 25.22;
CoordinateReferenceSystem sourceCRS = CRS.decode(GeospatialUtil.EPSG_4326);
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));
}
Aggregations