Package com.esri.core.geometry
Class GeometryEngine
java.lang.Object
com.esri.core.geometry.GeometryEngine
Provides services that operate on geometry instances. The methods of GeometryEngine class call corresponding OperatorXXX classes.
Consider using OperatorXXX classes directly as they often provide more functionality and better performance. For example, some Operators accept
GeometryCursor class that could be implemented to wrap a feature cursor and make it feed geometries directly into an Operator.
Also, some operators provide a way to accelerate an operation by using Operator.accelerateGeometry method.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Polygon[]
buffer
(Geometry[] geometries, SpatialReference spatialReference, double[] distances, boolean toUnionResults) Calculates a buffer polygon for each geometry at each of the corresponding specified distances.static Polygon
buffer
(Geometry geometry, SpatialReference spatialReference, double distance) Calculates a buffer polygon of the geometry as specified by the distance input.static Geometry
clip
(Geometry geometry, Envelope envelope, SpatialReference spatialReference) Calculates the clipped geometry from a target geometry using an envelope.static boolean
contains
(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference) Indicates if one geometry contains another geometry.static Geometry
convexHull
(Geometry geometry) Calculates the convex hull geometry.static Geometry[]
convexHull
(Geometry[] geometries, boolean b_merge) Calculates the convex hull.static boolean
crosses
(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference) Indicates if one geometry crosses another geometry.static Geometry[]
cut
(Geometry cuttee, Polyline cutter, SpatialReference spatialReference) Calculates the cut geometry from a target geometry using a polyline.static Geometry
difference
(Geometry geometry1, Geometry substractor, SpatialReference spatialReference) Creates the difference of two geometries.static boolean
disjoint
(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference) See OperatorDisjoint.static double
distance
(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference) Calculates the 2D planar distance between two geometries.static boolean
equals
(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference) Indicates if two geometries are equal.static double
geodesicDistanceOnWGS84
(Point ptFrom, Point ptTo) A geodesic distance is the shortest distance between any two points on the earth's surface when the earth's surface is approximated by a spheroid.static MapGeometry
geoJsonToGeometry
(String json, int importFlags, Geometry.Type type) Imports the MapGeometry from its JSON representation.static Geometry
geometryFromEsriShape
(byte[] esriShapeBuffer, Geometry.Type geometryType) Imports geometry from the ESRI shape file format.static Geometry
geometryFromWkt
(String wkt, int importFlags, Geometry.Type geometryType) Imports a geometry from a WKT string.static byte[]
geometryToEsriShape
(Geometry geometry) Exports geometry to the ESRI shape file format.static String
geometryToGeoJson
(int wkid, Geometry geometry) Exports the specified geometry instance to its GeoJSON representation.static String
geometryToGeoJson
(Geometry geometry) static String
geometryToGeoJson
(SpatialReference spatialReference, Geometry geometry) Exports the specified geometry instance to it's JSON representation.static String
geometryToJson
(int wkid, Geometry geometry) Exports the specified geometry instance to it's JSON representation.static String
geometryToJson
(SpatialReference spatialReference, Geometry geometry) Exports the specified geometry instance to it's JSON representation.static String
geometryToWkt
(Geometry geometry, int exportFlags) Exports a geometry to a string in WKT format.static Proximity2DResult
getNearestCoordinate
(Geometry geometry, Point inputPoint, boolean bTestPolygonInterior) Finds the coordinate of the geometry which is closest to the specified point.static Proximity2DResult
getNearestVertex
(Geometry geometry, Point inputPoint) Finds nearest vertex on the geometry which is closed to the specified point.static Proximity2DResult[]
getNearestVertices
(Geometry geometry, Point inputPoint, double searchRadius, int maxVertexCountToReturn) Finds all vertices in the given distance from the specified point, sorted from the closest to the furthest.(package private) static Geometry[]
intersect
(Geometry[] inputGeometries, Geometry geometry, SpatialReference spatialReference) Constructs the set-theoretic intersection between an array of geometries and another geometry.static Geometry
intersect
(Geometry geometry1, Geometry intersector, SpatialReference spatialReference) Creates a geometry through intersection between two geometries.(package private) static boolean
isSimple
(Geometry geometry, SpatialReference spatialReference) Checks if the Geometry is simple.static MapGeometry
jsonToGeometry
(JsonReader json) Imports the MapGeometry from its JSON representation.static MapGeometry
jsonToGeometry
(com.fasterxml.jackson.core.JsonParser json) Imports the MapGeometry from its JSON representation.static MapGeometry
jsonToGeometry
(String json) Imports the MapGeometry from its JSON representation.static boolean
overlaps
(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference) Indicates if one geometry overlaps another geometry.static boolean
relate
(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference, String relation) Indicates if the given relation holds for the two geometries.static Geometry
simplify
(Geometry geometry, SpatialReference spatialReference) Performs the simplify operation on the geometry.static Geometry
symmetricDifference
(Geometry leftGeometry, Geometry rightGeometry, SpatialReference spatialReference) Creates the symmetric difference of two geometries.static boolean
touches
(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference) Indicates if one geometry touches another geometry.static Geometry
union
(Geometry[] geometries, SpatialReference spatialReference) Constructs a new geometry by union an array of geometries.static boolean
within
(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference) Indicates if one geometry is within another geometry.
-
Field Details
-
factory
-
-
Constructor Details
-
GeometryEngine
public GeometryEngine()
-
-
Method Details
-
jsonToGeometry
Imports the MapGeometry from its JSON representation. M and Z values are not imported from JSON representation. See OperatorImportFromJson.- Parameters:
json
- The JSON representation of the geometry (with spatial reference).- Returns:
- The MapGeometry instance containing the imported geometry and its spatial reference.
-
jsonToGeometry
Imports the MapGeometry from its JSON representation. M and Z values are not imported from JSON representation. See OperatorImportFromJson.- Parameters:
json
- The JSON representation of the geometry (with spatial reference).- Returns:
- The MapGeometry instance containing the imported geometry and its spatial reference.
-
jsonToGeometry
Imports the MapGeometry from its JSON representation. M and Z values are not imported from JSON representation. See OperatorImportFromJson.- Parameters:
json
- The JSON representation of the geometry (with spatial reference).- Returns:
- The MapGeometry instance containing the imported geometry and its spatial reference.
-
geometryToJson
Exports the specified geometry instance to it's JSON representation. See OperatorExportToJson.- Parameters:
wkid
- The spatial reference Well Known ID to be used for the JSON representation.geometry
- The geometry to be exported to JSON.- Returns:
- The JSON representation of the specified Geometry.
- See Also:
-
geometryToJson
Exports the specified geometry instance to it's JSON representation. M and Z values are not imported from JSON representation. See OperatorExportToJson.- Parameters:
spatialReference
- The spatial reference of associated object.geometry
- The geometry.- Returns:
- The JSON representation of the specified geometry.
-
geometryToGeoJson
-
geoJsonToGeometry
Imports the MapGeometry from its JSON representation. M and Z values are not imported from JSON representation. See OperatorImportFromJson.- Parameters:
json
- The JSON representation of the geometry (with spatial reference).- Returns:
- The MapGeometry instance containing the imported geometry and its spatial reference.
-
geometryToGeoJson
Exports the specified geometry instance to its GeoJSON representation. See OperatorExportToGeoJson.- Parameters:
wkid
- The spatial reference Well Known ID to be used for the GeoJSON representation.geometry
- The geometry to be exported to GeoJSON.- Returns:
- The GeoJSON representation of the specified geometry.
- See Also:
-
geometryToGeoJson
Exports the specified geometry instance to it's JSON representation. See OperatorImportFromGeoJson.- Parameters:
spatialReference
- The spatial reference of associated object.geometry
- The geometry.- Returns:
- The GeoJSON representation of the specified geometry.
-
geometryFromEsriShape
Imports geometry from the ESRI shape file format. See OperatorImportFromESRIShape.- Parameters:
esriShapeBuffer
- The buffer containing geometry in the ESRI shape file format.geometryType
- The required type of the Geometry to be imported. Use Geometry.Type.Unknown if the geometry type needs to be determined from the buffer content.- Returns:
- The geometry or null if the buffer contains null shape.
- Throws:
GeometryException
- when the geometryType is not Geometry.Type.Unknown and the buffer contains geometry that cannot be converted to the given geometryType. or the buffer is corrupt. Another exception possible is IllegalArgumentsException.
-
geometryToEsriShape
Exports geometry to the ESRI shape file format. See OperatorExportToESRIShape.- Parameters:
geometry
- The geometry to export. (null value is not allowed)- Returns:
- Array containing the exported ESRI shape file.
-
geometryFromWkt
Imports a geometry from a WKT string. See OperatorImportFromWkt.- Parameters:
wkt
- The string containing the geometry in WKT format.importFlags
- Use theWktImportFlags
interface.geometryType
- The required type of the Geometry to be imported. Use Geometry.Type.Unknown if the geometry type needs to be determined from the WKT context.- Returns:
- The geometry.
- Throws:
GeometryException
- when the geometryType is not Geometry.Type.Unknown and the WKT contains a geometry that cannot be converted to the given geometryType.IllegalArgumentException
- if an error is found while parsing the WKT string.
-
geometryToWkt
Exports a geometry to a string in WKT format. See OperatorExportToWkt.- Parameters:
geometry
- The geometry to export. (null value is not allowed)exportFlags
- Use theWktExportFlags
interface.- Returns:
- A String containing the exported geometry in WKT format.
-
union
Constructs a new geometry by union an array of geometries. All inputs must be of the same type of geometries and share one spatial reference. See OperatorUnion.- Parameters:
geometries
- The geometries to union.spatialReference
- The spatial reference of the geometries.- Returns:
- The geometry object representing the resultant union.
-
difference
public static Geometry difference(Geometry geometry1, Geometry substractor, SpatialReference spatialReference) Creates the difference of two geometries. The dimension of geometry2 has to be equal to or greater than that of geometry1. See OperatorDifference.- Parameters:
geometry1
- The geometry being subtracted.substractor
- The geometry object to subtract from.spatialReference
- The spatial reference of the geometries.- Returns:
- The geometry of the differences.
-
symmetricDifference
public static Geometry symmetricDifference(Geometry leftGeometry, Geometry rightGeometry, SpatialReference spatialReference) Creates the symmetric difference of two geometries. See OperatorSymmetricDifference.- Parameters:
leftGeometry
- is one of the Geometry instances in the XOR operation.rightGeometry
- is one of the Geometry instances in the XOR operation.spatialReference
- The spatial reference of the geometries.- Returns:
- Returns the result of the symmetric difference.
-
equals
public static boolean equals(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference) Indicates if two geometries are equal. See OperatorEquals.- Parameters:
geometry1
- Geometry.geometry2
- Geometry.spatialReference
- The spatial reference of the geometries.- Returns:
- TRUE if both geometry objects are equal.
-
disjoint
public static boolean disjoint(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference) See OperatorDisjoint. -
intersect
static Geometry[] intersect(Geometry[] inputGeometries, Geometry geometry, SpatialReference spatialReference) Constructs the set-theoretic intersection between an array of geometries and another geometry. See OperatorIntersection (also for dimension specific intersection).- Parameters:
inputGeometries
- An array of geometry objects.geometry
- The geometry object.- Returns:
- Any array of geometry objects showing the intersection.
-
intersect
public static Geometry intersect(Geometry geometry1, Geometry intersector, SpatialReference spatialReference) Creates a geometry through intersection between two geometries. See OperatorIntersection.- Parameters:
geometry1
- The first geometry.intersector
- The geometry to intersect the first geometry.spatialReference
- The spatial reference of the geometries.- Returns:
- The geometry created through intersection.
-
within
public static boolean within(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference) Indicates if one geometry is within another geometry. See OperatorWithin.- Parameters:
geometry1
- The base geometry that is tested for within relationship to the other geometry.geometry2
- The comparison geometry that is tested for the contains relationship to the other geometry.spatialReference
- The spatial reference of the geometries.- Returns:
- TRUE if the first geometry is within the other geometry.
-
contains
public static boolean contains(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference) Indicates if one geometry contains another geometry. See OperatorContains.- Parameters:
geometry1
- The geometry that is tested for the contains relationship to the other geometry..geometry2
- The geometry that is tested for within relationship to the other geometry.spatialReference
- The spatial reference of the geometries.- Returns:
- TRUE if geometry1 contains geometry2.
-
crosses
public static boolean crosses(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference) Indicates if one geometry crosses another geometry. See OperatorCrosses.- Parameters:
geometry1
- The geometry to cross.geometry2
- The geometry being crossed.spatialReference
- The spatial reference of the geometries.- Returns:
- TRUE if geometry1 crosses geometry2.
-
touches
public static boolean touches(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference) Indicates if one geometry touches another geometry. See OperatorTouches.- Parameters:
geometry1
- The geometry to touch.geometry2
- The geometry to be touched.spatialReference
- The spatial reference of the geometries.- Returns:
- TRUE if geometry1 touches geometry2.
-
overlaps
public static boolean overlaps(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference) Indicates if one geometry overlaps another geometry. See OperatorOverlaps.- Parameters:
geometry1
- The geometry to overlap.geometry2
- The geometry to be overlapped.spatialReference
- The spatial reference of the geometries.- Returns:
- TRUE if geometry1 overlaps geometry2.
-
relate
public static boolean relate(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference, String relation) Indicates if the given relation holds for the two geometries. See OperatorRelate.- Parameters:
geometry1
- The first geometry for the relation.geometry2
- The second geometry for the relation.spatialReference
- The spatial reference of the geometries.relation
- The DE-9IM relation.- Returns:
- TRUE if the given relation holds between geometry1 and geometry2.
-
distance
public static double distance(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference) Calculates the 2D planar distance between two geometries. See OperatorDistance.- Parameters:
geometry1
- Geometry.geometry2
- Geometry.spatialReference
- The spatial reference of the geometries. This parameter is not used and can be null.- Returns:
- The distance between the two geometries.
-
clip
public static Geometry clip(Geometry geometry, Envelope envelope, SpatialReference spatialReference) Calculates the clipped geometry from a target geometry using an envelope. See OperatorClip.- Parameters:
geometry
- The geometry to be clipped.envelope
- The envelope used to clip.spatialReference
- The spatial reference of the geometries.- Returns:
- The geometry created by clipping.
-
cut
Calculates the cut geometry from a target geometry using a polyline. For Polylines, all left cuts will be grouped together in the first Geometry, Right cuts and coincident cuts are grouped in the second Geometry, and each undefined cut, along with any uncut parts, are output as separate Polylines. For Polygons, all left cuts are grouped in the first Polygon, all right cuts are in the second Polygon, and each undefined cut, along with any left-over parts after cutting, are output as a separate Polygon. If there were no cuts then the array will be empty. An undefined cut will only be produced if a left cut or right cut was produced, and there was a part left over after cutting or a cut is bounded to the left and right of the cutter. See OperatorCut.- Parameters:
cuttee
- The geometry to be cut.cutter
- The polyline to cut the geometry.spatialReference
- The spatial reference of the geometries.- Returns:
- An array of geometries created from cutting.
-
buffer
public static Polygon[] buffer(Geometry[] geometries, SpatialReference spatialReference, double[] distances, boolean toUnionResults) Calculates a buffer polygon for each geometry at each of the corresponding specified distances. It is assumed that all geometries have the same spatial reference. There is an option to union the returned geometries. See OperatorBuffer.- Parameters:
geometries
- An array of geometries to be buffered.spatialReference
- The spatial reference of the geometries.distances
- The corresponding distances for the input geometries to be buffered.toUnionResults
- TRUE if all geometries buffered at a given distance are to be unioned into a single polygon.- Returns:
- The buffer of the geometries.
-
buffer
Calculates a buffer polygon of the geometry as specified by the distance input. The buffer is implemented in the xy-plane. See OperatorBuffer- Parameters:
geometry
- Geometry to be buffered.spatialReference
- The spatial reference of the geometry.distance
- The specified distance for buffer. Same units as the spatial reference.- Returns:
- The buffer polygon at the specified distances.
-
convexHull
Calculates the convex hull geometry. See OperatorConvexHull.- Parameters:
geometry
- The input geometry.- Returns:
- Returns the convex hull. For a Point - returns the same point. For an Envelope - returns the same envelope. For a MultiPoint - If the point count is one, returns the same multipoint. If the point count is two, returns a polyline of the points. Otherwise computes and returns the convex hull polygon. For a Segment - returns a polyline consisting of the segment. For a Polyline - If consists of only one segment, returns the same polyline. Otherwise computes and returns the convex hull polygon. For a Polygon - If more than one path, or if the path isn't already convex, computes and returns the convex hull polygon. Otherwise returns the same polygon.
-
convexHull
Calculates the convex hull. See OperatorConvexHull- Parameters:
geometries
- The input geometry array.b_merge
- Put true if you want the convex hull of all the geometries in the array combined. Put false if you want the convex hull of each geometry in the array individually.- Returns:
- Returns an array of convex hulls. If b_merge is true, the result will be a one element array consisting of the merged convex hull.
-
getNearestCoordinate
public static Proximity2DResult getNearestCoordinate(Geometry geometry, Point inputPoint, boolean bTestPolygonInterior) Finds the coordinate of the geometry which is closest to the specified point. See OperatorProximity2D.- Parameters:
geometry
- The geometry to consider.inputPoint
- The point to find the nearest coordinate in the geometry for.- Returns:
- Proximity2DResult containing the nearest coordinate.
-
getNearestVertex
Finds nearest vertex on the geometry which is closed to the specified point. See OperatorProximity2D.- Parameters:
geometry
- The geometry to consider.inputPoint
- The point to find the nearest vertex of the geometry for.- Returns:
- Proximity2DResult containing the nearest vertex.
-
getNearestVertices
public static Proximity2DResult[] getNearestVertices(Geometry geometry, Point inputPoint, double searchRadius, int maxVertexCountToReturn) Finds all vertices in the given distance from the specified point, sorted from the closest to the furthest. See OperatorProximity2D.- Parameters:
geometry
- The geometry to consider.inputPoint
- The point to start from.searchRadius
- The search radius.maxVertexCountToReturn
- The maximum number number of vertices to return.- Returns:
- Proximity2DResult containing the array of nearest vertices.
-
simplify
Performs the simplify operation on the geometry. See OperatorSimplify and See OperatorSimplifyOGC.- Parameters:
geometry
- The geometry to be simplified.spatialReference
- The spatial reference of the geometry to be simplified.- Returns:
- The simplified geometry.
-
isSimple
Checks if the Geometry is simple. See OperatorSimplify.- Parameters:
geometry
- The geometry to be checked.spatialReference
- The spatial reference of the geometry.- Returns:
- TRUE if the geometry is simple.
-
geodesicDistanceOnWGS84
A geodesic distance is the shortest distance between any two points on the earth's surface when the earth's surface is approximated by a spheroid. The function returns the shortest distance between two points on the WGS84 spheroid.- Parameters:
ptFrom
- The "from" point: long, lat in degrees.ptTo
- The "to" point: long, lat in degrees.- Returns:
- The geodesic distance between two points in meters.
-