Search in sources :

Example 56 with Polygon

use of org.locationtech.jts.geom.Polygon in project teiid by teiid.

the class JTS2OlingoBridge method convert.

public Geospatial convert(Geometry geometry) {
    if (geometry instanceof Point) {
        Point point = (Point) geometry;
        org.apache.olingo.commons.api.edm.geo.Point result = new org.apache.olingo.commons.api.edm.geo.Point(dimension, srid);
        result.setX(point.getX());
        result.setY(point.getY());
        return result;
    } else if (geometry instanceof LineString) {
        LineString lineString = (LineString) geometry;
        return convertLineString(lineString.getCoordinates());
    } else if (geometry instanceof Polygon) {
        Polygon polygon = (Polygon) geometry;
        return convertPolygon(polygon);
    } else if (geometry instanceof MultiPoint) {
        MultiPoint multipoint = (MultiPoint) geometry;
        List<org.apache.olingo.commons.api.edm.geo.Point> points = convertLineStringToPoints(multipoint.getCoordinates());
        org.apache.olingo.commons.api.edm.geo.MultiPoint result = new org.apache.olingo.commons.api.edm.geo.MultiPoint(dimension, srid, points);
        return result;
    } else if (geometry instanceof MultiLineString) {
        MultiLineString multiLineString = (MultiLineString) geometry;
        List<org.apache.olingo.commons.api.edm.geo.LineString> lineStrings = new ArrayList<>(multiLineString.getNumGeometries());
        for (int i = 0; i < multiLineString.getNumGeometries(); i++) {
            LineString lineString = (LineString) multiLineString.getGeometryN(i);
            lineStrings.add(convertLineString(lineString.getCoordinates()));
        }
        org.apache.olingo.commons.api.edm.geo.MultiLineString result = new org.apache.olingo.commons.api.edm.geo.MultiLineString(dimension, srid, lineStrings);
        return result;
    } else if (geometry instanceof MultiPolygon) {
        MultiPolygon multiPolygon = (MultiPolygon) geometry;
        List<org.apache.olingo.commons.api.edm.geo.Polygon> polygons = new ArrayList<>(multiPolygon.getNumGeometries());
        for (int i = 0; i < multiPolygon.getNumGeometries(); i++) {
            Polygon polygon = (Polygon) multiPolygon.getGeometryN(i);
            polygons.add(convertPolygon(polygon));
        }
        org.apache.olingo.commons.api.edm.geo.MultiPolygon result = new org.apache.olingo.commons.api.edm.geo.MultiPolygon(dimension, srid, polygons);
        return result;
    } else if (geometry instanceof GeometryCollection) {
        GeometryCollection geometryCollection = (GeometryCollection) geometry;
        List<org.apache.olingo.commons.api.edm.geo.Geospatial> geometries = new ArrayList<>(geometryCollection.getNumGeometries());
        for (int i = 0; i < geometryCollection.getNumGeometries(); i++) {
            Geometry geo = geometryCollection.getGeometryN(i);
            geometries.add(convert(geo));
        }
        org.apache.olingo.commons.api.edm.geo.GeospatialCollection result = new org.apache.olingo.commons.api.edm.geo.GeospatialCollection(dimension, srid, geometries);
        return result;
    } else {
        throw new AssertionError(geometry.getClass());
    }
}
Also used : MultiPoint(org.locationtech.jts.geom.MultiPoint) MultiLineString(org.locationtech.jts.geom.MultiLineString) ArrayList(java.util.ArrayList) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) ArrayList(java.util.ArrayList) List(java.util.List) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Geospatial(org.apache.olingo.commons.api.edm.geo.Geospatial) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) Geometry(org.locationtech.jts.geom.Geometry) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) MultiPolygon(org.locationtech.jts.geom.MultiPolygon)

Example 57 with Polygon

use of org.locationtech.jts.geom.Polygon in project h2database by h2database.

the class TestSpatial method testSpatialValues.

private void testSpatialValues() throws SQLException {
    deleteDb("spatial");
    Connection conn = getConnection(URL);
    Statement stat = conn.createStatement();
    stat.execute("create memory table test" + "(id int primary key, polygon geometry)");
    stat.execute("insert into test values(1, " + "'POLYGON ((1 1, 1 2, 2 2, 1 1))')");
    ResultSet rs = stat.executeQuery("select * from test");
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    assertEquals("POLYGON ((1 1, 1 2, 2 2, 1 1))", rs.getString(2));
    GeometryFactory f = new GeometryFactory();
    Polygon polygon = f.createPolygon(new Coordinate[] { new Coordinate(1, 1), new Coordinate(1, 2), new Coordinate(2, 2), new Coordinate(1, 1) });
    assertTrue(polygon.equals(rs.getObject(2)));
    rs.close();
    rs = stat.executeQuery("select id, cast(polygon as varchar) from test");
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    assertEquals("POLYGON ((1 1, 1 2, 2 2, 1 1))", rs.getObject(2));
    assertTrue(polygon.equals(rs.getObject(2, Geometry.class)));
    rs.close();
    rs = stat.executeQuery("select * from test where polygon = " + "'POLYGON ((1 1, 1 2, 2 2, 1 1))'");
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    stat.executeQuery("select * from test where polygon > " + "'POLYGON ((1 1, 1 2, 2 2, 1 1))'");
    stat.executeQuery("select * from test where polygon < " + "'POLYGON ((1 1, 1 2, 2 2, 1 1))'");
    stat.execute("drop table test");
    conn.close();
    deleteDb("spatial");
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) Statement(java.sql.Statement) Connection(java.sql.Connection) SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet) Polygon(org.locationtech.jts.geom.Polygon)

Example 58 with Polygon

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

the class QuadTreeCls method disjoint.

/**
 * Apart a and B do not intersect, a and B are polygons
 * @param polygonA polygon
 * @param polygonB polygon
 * @return true Polygons apart,false Polygons are inseparable
 */
public static boolean disjoint(Geometry polygonA, List<Point2D.Double> polygonB) {
    Polygon polyB = getPolygonByPointList(polygonB);
    boolean result = polygonA.disjoint(polyB);
    return result;
}
Also used : Polygon(org.locationtech.jts.geom.Polygon)

Example 59 with Polygon

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

the class QuadTreeCls method intersects.

/**
 * intersect - A intersects B Indicates that polygon a intersects polygon B
 * @param polygonA polygon
 * @param polygonB polygon
 * @return true Polygon a intersects polygon B,false Polygon a does not intersect polygon B
 */
public static boolean intersects(Geometry polygonA, List<Point2D.Double> polygonB) {
    Polygon polyB = getPolygonByPointList(polygonB);
    boolean result = polygonA.intersects(polyB);
    return result;
}
Also used : Polygon(org.locationtech.jts.geom.Polygon)

Example 60 with Polygon

use of org.locationtech.jts.geom.Polygon in project arctic-sea by 52North.

the class GeoJSONEncoder method encode.

protected ObjectNode encode(MultiPolygon geometry, int parentSrid) {
    Preconditions.checkNotNull(geometry);
    ObjectNode json = jsonFactory.objectNode();
    ArrayNode list = json.put(JSONConstants.TYPE, JSONConstants.MULTI_POLYGON).putArray(JSONConstants.COORDINATES);
    for (int i = 0; i < geometry.getNumGeometries(); ++i) {
        list.add(encodeCoordinates((Polygon) geometry.getGeometryN(i)));
    }
    encodeCRS(json, geometry, parentSrid);
    return json;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Aggregations

Polygon (org.locationtech.jts.geom.Polygon)179 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)89 Coordinate (org.locationtech.jts.geom.Coordinate)78 LinearRing (org.locationtech.jts.geom.LinearRing)55 Point (org.locationtech.jts.geom.Point)54 Test (org.junit.Test)51 Geometry (org.locationtech.jts.geom.Geometry)48 LineString (org.locationtech.jts.geom.LineString)48 ArrayList (java.util.ArrayList)37 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)30 MultiPoint (org.locationtech.jts.geom.MultiPoint)29 MultiLineString (org.locationtech.jts.geom.MultiLineString)19 List (java.util.List)15 Test (org.junit.jupiter.api.Test)15 GeometryCollection (org.locationtech.jts.geom.GeometryCollection)12 WKTReader (org.locationtech.jts.io.WKTReader)12 HashMap (java.util.HashMap)9 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)8 ParseException (org.locationtech.jts.io.ParseException)7 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)5