Search in sources :

Example 76 with Coordinate

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();
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) CoordinateFilter(org.locationtech.jts.geom.CoordinateFilter)

Example 77 with Coordinate

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);
    }
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) ArrayList(java.util.ArrayList) LinearRing(org.locationtech.jts.geom.LinearRing)

Example 78 with Coordinate

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));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate) WKTReader(org.locationtech.jts.io.WKTReader)

Example 79 with Coordinate

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));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) Point(org.locationtech.jts.geom.Point) Test(org.junit.Test)

Example 80 with Coordinate

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));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Point(org.locationtech.jts.geom.Point) Envelope(org.locationtech.jts.geom.Envelope) Test(org.junit.Test)

Aggregations

Coordinate (org.locationtech.jts.geom.Coordinate)348 Test (org.junit.Test)145 Geometry (org.locationtech.jts.geom.Geometry)69 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)65 LineString (org.locationtech.jts.geom.LineString)57 Point (org.locationtech.jts.geom.Point)57 Polygon (org.locationtech.jts.geom.Polygon)47 LinearRing (org.locationtech.jts.geom.LinearRing)45 AbstractArcTest (eu.esdihumboldt.util.geometry.interpolation.AbstractArcTest)37 ArcByCenterPoint (eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)32 ArrayList (java.util.ArrayList)32 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)27 Test (org.junit.jupiter.api.Test)26 Arc (eu.esdihumboldt.util.geometry.interpolation.model.Arc)20 MultiPoint (org.locationtech.jts.geom.MultiPoint)20 ArcByPointsImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByPointsImpl)17 ArcByCenterPointImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByCenterPointImpl)16 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)15 ArcByPoints (eu.esdihumboldt.util.geometry.interpolation.model.ArcByPoints)14 HashMap (java.util.HashMap)13