Search in sources :

Example 81 with Coordinate

use of org.locationtech.jts.geom.Coordinate in project ddf by codice.

the class WfsFilterDelegate method getCoordinatesFromWkt.

private Coordinate[] getCoordinatesFromWkt(String wkt) {
    Coordinate[] coordinates;
    try {
        Geometry geo = getGeometryFromWkt(wkt);
        coordinates = geo.getCoordinates();
    } catch (ParseException e) {
        throw new IllegalArgumentException(UNABLE_TO_PARSE_WKT_STRING, e);
    }
    return coordinates;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate) ParseException(org.locationtech.jts.io.ParseException)

Example 82 with Coordinate

use of org.locationtech.jts.geom.Coordinate in project ddf by codice.

the class WfsFilterDelegate method createCoordinates.

private CoordinatesType createCoordinates(Geometry geometry) {
    CoordinatesType coords = gml320ObjectFactory.createCoordinatesType();
    Coordinate[] coordinates = geometry.getCoordinates();
    if (coordinates != null && coordinates.length > 0) {
        StringBuffer coordString = new StringBuffer();
        for (Coordinate coordinate : coordinates) {
            coordString.append(coordinate.x).append(",").append(coordinate.y).append(" ");
        }
        coords.setValue(coordString.toString());
        coords.setDecimal(".");
        coords.setCs(",");
        coords.setTs(" ");
        coords.setValue(coordString.toString());
        return coords;
    } else {
        throw new IllegalArgumentException("Unable to parse Geometry coordinates from WKT String");
    }
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) CoordinatesType(net.opengis.gml.v_3_2_1.CoordinatesType)

Example 83 with Coordinate

use of org.locationtech.jts.geom.Coordinate in project ddf by codice.

the class GeoJsonInputTransformerTest method testLineStringGeo.

@Test
public void testLineStringGeo() throws IOException, CatalogTransformerException, ParseException {
    InputStream inputStream = new ByteArrayInputStream(sampleLineStringJsonText().getBytes());
    Metacard metacard = transformer.transform(inputStream);
    verifyBasics(metacard);
    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) Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) Coordinate(org.locationtech.jts.geom.Coordinate) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) WKTReader(org.locationtech.jts.io.WKTReader) Test(org.junit.Test)

Example 84 with Coordinate

use of org.locationtech.jts.geom.Coordinate in project carbondata by apache.

the class QuadTreeCls method getPolygonByPointList.

/**
 * Convert point object to polygon object in Geo
 *
 * @param polygon Area coordinates stored as a list
 * @return JTS Polygon objects
 */
public static Polygon getPolygonByPointList(List<Point2D.Double> polygon) {
    int size = polygon.size();
    if (size < 3) {
        return null;
    } else {
        Coordinate[] rect = new Coordinate[size + 1];
        for (int i = 0; i < size; i++) {
            rect[i] = new Coordinate(polygon.get(i).x, polygon.get(i).y);
        }
        // making a closed polygon by keeping first point and last point same
        rect[size] = new Coordinate(polygon.get(0).x, polygon.get(0).y);
        return geoFactory.createPolygon(rect);
    }
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) Point(org.locationtech.jts.geom.Point)

Example 85 with Coordinate

use of org.locationtech.jts.geom.Coordinate in project thingsboard by thingsboard.

the class GeoUtil method buildPolygonFromCoordinates.

private static Geometry buildPolygonFromCoordinates(List<Coordinate> coordinates) {
    if (coordinates.size() == 2) {
        Coordinate a = coordinates.get(0);
        Coordinate c = coordinates.get(1);
        coordinates.clear();
        Coordinate b = new Coordinate(a.x, c.y);
        Coordinate d = new Coordinate(c.x, a.y);
        coordinates.addAll(List.of(a, b, c, d, a));
    }
    CoordinateSequence coordinateSequence = jtsCtx.getShapeFactory().getGeometryFactory().getCoordinateSequenceFactory().create(coordinates.toArray(new Coordinate[0]));
    return GeometryFixer.fix(jtsCtx.getShapeFactory().getGeometryFactory().createPolygon(coordinateSequence));
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) Coordinate(org.locationtech.jts.geom.Coordinate)

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