Java Code Examples for com.esri.core.geometry.GeometryCursor#next()
The following examples show how to use
com.esri.core.geometry.GeometryCursor#next() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeoFunctions.java From presto with Apache License 2.0 | 6 votes |
@Description("Returns the 2D Euclidean area of a geometry") @ScalarFunction("ST_Area") @SqlType(DOUBLE) public static double stArea(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); // The Esri geometry library does not support area for geometry collections. We compute the area // of collections by summing the area of the individual components. GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType()); if (type == GeometryType.GEOMETRY_COLLECTION) { double area = 0.0; GeometryCursor cursor = geometry.getEsriGeometryCursor(); while (true) { com.esri.core.geometry.Geometry esriGeometry = cursor.next(); if (esriGeometry == null) { return area; } area += esriGeometry.calculateArea2D(); } } return geometry.getEsriGeometry().calculateArea2D(); }
Example 2
Source File: GeoFunctions.java From presto with Apache License 2.0 | 6 votes |
@Description("Returns true if the input geometry is well formed") @ScalarFunction("ST_IsValid") @SqlType(BOOLEAN) public static boolean stIsValid(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { GeometryCursor cursor = deserialize(input).getEsriGeometryCursor(); while (true) { com.esri.core.geometry.Geometry geometry = cursor.next(); if (geometry == null) { return true; } if (!OperatorSimplifyOGC.local().isSimpleOGC(geometry, null, true, null, null)) { return false; } } }
Example 3
Source File: GeometryUtils.java From presto with Apache License 2.0 | 6 votes |
public static int getPointCount(OGCGeometry ogcGeometry) { GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor(); int points = 0; while (true) { com.esri.core.geometry.Geometry geometry = cursor.next(); if (geometry == null) { return points; } if (geometry.isEmpty()) { continue; } if (geometry instanceof Point) { points++; } else { points += ((MultiVertexGeometry) geometry).getPointCount(); } } }
Example 4
Source File: OGCGeometry.java From geometry-api-java with Apache License 2.0 | 6 votes |
public static OGCGeometry createFromEsriCursor(GeometryCursor gc, SpatialReference sr, boolean skipEmpty) { ArrayList<OGCGeometry> geoms = new ArrayList<OGCGeometry>(10); Geometry emptyGeom = null; for (Geometry g = gc.next(); g != null; g = gc.next()) { emptyGeom = g; if (!skipEmpty || !g.isEmpty()) geoms.add(createFromEsriGeometry(g, sr)); } if (geoms.size() == 1) { return geoms.get(0); } else if (geoms.size() == 0) return createFromEsriGeometry(emptyGeom, sr); else return new OGCConcreteGeometryCollection(geoms, sr); }
Example 5
Source File: PagesSpatialIndexSupplier.java From presto with Apache License 2.0 | 5 votes |
private static void accelerateGeometry(OGCGeometry ogcGeometry, Operator relateOperator) { // Recurse into GeometryCollections GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor(); while (true) { com.esri.core.geometry.Geometry esriGeometry = cursor.next(); if (esriGeometry == null) { break; } relateOperator.accelerateGeometry(esriGeometry, null, Geometry.GeometryAccelerationDegree.enumMild); } }
Example 6
Source File: GeoFunctions.java From presto with Apache License 2.0 | 5 votes |
@Description("Converts a Geometry object to a SphericalGeography object") @ScalarFunction("to_spherical_geography") @SqlType(SPHERICAL_GEOGRAPHY_TYPE_NAME) public static Slice toSphericalGeography(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { // "every point in input is in range" <=> "the envelope of input is in range" Envelope envelope = deserializeEnvelope(input); if (!envelope.isEmpty()) { checkLatitude(envelope.getYMin()); checkLatitude(envelope.getYMax()); checkLongitude(envelope.getXMin()); checkLongitude(envelope.getXMax()); } OGCGeometry geometry = deserialize(input); if (geometry.is3D()) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Cannot convert 3D geometry to a spherical geography"); } GeometryCursor cursor = geometry.getEsriGeometryCursor(); while (true) { com.esri.core.geometry.Geometry subGeometry = cursor.next(); if (subGeometry == null) { break; } if (!GEOMETRY_TYPES_FOR_SPHERICAL_GEOGRAPHY.contains(subGeometry.getType())) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Cannot convert geometry of this type to spherical geography: " + subGeometry.getType()); } } return input; }
Example 7
Source File: GeoFunctions.java From presto with Apache License 2.0 | 5 votes |
@Description("Returns the reason for why the input geometry is not valid. Returns null if the input is valid.") @ScalarFunction("geometry_invalid_reason") @SqlType(VARCHAR) @SqlNullable public static Slice invalidReason(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { GeometryCursor cursor = deserialize(input).getEsriGeometryCursor(); NonSimpleResult result = new NonSimpleResult(); while (true) { com.esri.core.geometry.Geometry geometry = cursor.next(); if (geometry == null) { return null; } if (!OperatorSimplifyOGC.local().isSimpleOGC(geometry, null, true, result, null)) { String reasonText = NON_SIMPLE_REASONS.getOrDefault(result.m_reason, result.m_reason.name()); if (!(geometry instanceof MultiVertexGeometry)) { return utf8Slice(reasonText); } MultiVertexGeometry multiVertexGeometry = (MultiVertexGeometry) geometry; if (result.m_vertexIndex1 >= 0 && result.m_vertexIndex2 >= 0) { Point point1 = multiVertexGeometry.getPoint(result.m_vertexIndex1); Point point2 = multiVertexGeometry.getPoint(result.m_vertexIndex2); return utf8Slice(format("%s at or near (%s %s) and (%s %s)", reasonText, point1.getX(), point1.getY(), point2.getX(), point2.getY())); } if (result.m_vertexIndex1 >= 0) { Point point = multiVertexGeometry.getPoint(result.m_vertexIndex1); return utf8Slice(format("%s at or near (%s %s)", reasonText, point.getX(), point.getY())); } return utf8Slice(reasonText); } } }
Example 8
Source File: GeometryUtils.java From presto with Apache License 2.0 | 5 votes |
public static Envelope getEnvelope(OGCGeometry ogcGeometry) { GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor(); Envelope overallEnvelope = new Envelope(); while (true) { Geometry geometry = cursor.next(); if (geometry == null) { return overallEnvelope; } Envelope envelope = new Envelope(); geometry.queryEnvelope(envelope); overallEnvelope.merge(envelope); } }
Example 9
Source File: GeometryUtils.java From presto with Apache License 2.0 | 5 votes |
public static boolean disjoint(Envelope envelope, OGCGeometry ogcGeometry) { GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor(); while (true) { Geometry geometry = cursor.next(); if (geometry == null) { return true; } if (!GeometryEngine.disjoint(geometry, envelope, null)) { return false; } } }
Example 10
Source File: GeometryUtils.java From presto with Apache License 2.0 | 5 votes |
public static boolean contains(OGCGeometry ogcGeometry, Envelope envelope) { GeometryCursor cursor = ogcGeometry.getEsriGeometryCursor(); while (true) { Geometry geometry = cursor.next(); if (geometry == null) { return false; } if (GeometryEngine.contains(geometry, envelope, null)) { return true; } } }
Example 11
Source File: OGCConcreteGeometryCollection.java From geometry-api-java with Apache License 2.0 | 5 votes |
public OGCConcreteGeometryCollection(GeometryCursor geoms, SpatialReference sr) { List<OGCGeometry> ogcGeoms = new ArrayList<OGCGeometry>(10); for (Geometry g = geoms.next(); g != null; g = geoms.next()) { ogcGeoms.add(createFromEsriGeometry(g, sr)); } geometries = ogcGeoms; esriSR = sr; }
Example 12
Source File: OGCConcreteGeometryCollection.java From geometry-api-java with Apache License 2.0 | 5 votes |
@Override public OGCGeometry envelope() { GeometryCursor gc = getEsriGeometryCursor(); Envelope env = new Envelope(); for (Geometry g = gc.next(); g != null; g = gc.next()) { Envelope e = new Envelope(); g.queryEnvelope(e); env.merge(e); } Polygon polygon = new Polygon(); polygon.addEnvelope(env, false); return new OGCPolygon(polygon, esriSR); }
Example 13
Source File: OGCConcreteGeometryCollection.java From geometry-api-java with Apache License 2.0 | 5 votes |
private static List<Geometry> toList(GeometryCursor cursor) { List<Geometry> geometries = new ArrayList<Geometry>(); for (Geometry geometry = cursor.next(); geometry != null; geometry = cursor.next()) { geometries.add(geometry); } return geometries; }
Example 14
Source File: OGCConcreteGeometryCollection.java From geometry-api-java with Apache License 2.0 | 4 votes |
@Override public OGCGeometry convexHull() { GeometryCursor cursor = OperatorConvexHull.local().execute( getEsriGeometryCursor(), false, null); MultiPoint mp = new MultiPoint(); Polygon polygon = new Polygon(); VertexDescription vd = null; for (Geometry geom = cursor.next(); geom != null; geom = cursor.next()) { vd = geom.getDescription(); if (geom.isEmpty()) continue; if (geom.getType() == Geometry.Type.Polygon) { polygon.add((MultiPath) geom, false); } else if (geom.getType() == Geometry.Type.Polyline) { mp.add((MultiVertexGeometry) geom, 0, -1); } else if (geom.getType() == Geometry.Type.Point) { mp.add((Point) geom); } else { throw new GeometryException("internal error"); } } Geometry resultGeom = null; if (!mp.isEmpty()) { resultGeom = OperatorConvexHull.local().execute(mp, null); } if (!polygon.isEmpty()) { if (resultGeom != null && !resultGeom.isEmpty()) { Geometry[] geoms = { resultGeom, polygon }; resultGeom = OperatorConvexHull.local().execute( new SimpleGeometryCursor(geoms), true, null).next(); } else { resultGeom = OperatorConvexHull.local().execute(polygon, null); } } if (resultGeom == null) { Point pt = new Point(); if (vd != null) pt.assignVertexDescription(vd); return new OGCPoint(pt, getEsriSpatialReference()); } return OGCGeometry.createFromEsriGeometry(resultGeom, getEsriSpatialReference(), false); }