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