com.esri.core.geometry
Class GeometryEngine

java.lang.Object
  extended by com.esri.core.geometry.GeometryEngine

public class GeometryEngine
extends Object

Provides services that operate on geometry instances.


Constructor Summary
GeometryEngine()
           
 
Method Summary
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.
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)
           
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 Geometry geometryFromEsriShape(byte[] esriShapeBuffer, Geometry.Type geometryType)
          Imports geometry from the ESRI shape file format.
static MapGeometry geometryFromGeoJson(String geoJson, int importFlags, Geometry.Type geometryType)
          Imports a geometry from a geoJson string.
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(Geometry geometry)
           
static String geometryToGeoJson(int wkid, Geometry geometry)
          Exports the specified geometry instance to its GeoJSON representation.
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.
static Geometry intersect(Geometry geometry1, Geometry intersector, SpatialReference spatialReference)
          Creates a geometry through intersection between two geometries.
static MapGeometry jsonToGeometry(org.codehaus.jackson.JsonParser 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeometryEngine

public GeometryEngine()
Method Detail

jsonToGeometry

public static MapGeometry jsonToGeometry(org.codehaus.jackson.JsonParser json)
Imports the MapGeometry from its JSON representation. M and Z values are not imported from JSON representation.

Parameters:
json - The JSON representation of the geometry (with spatial reference).
Returns:
The MapGeometry instance containing the imported geometry and its spatial reference.

geometryToJson

public static String geometryToJson(int wkid,
                                    Geometry geometry)
Exports the specified geometry instance to it's JSON representation.

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(SpatialReference spatialiReference, Geometry geometry)

geometryToJson

public static String geometryToJson(SpatialReference spatialReference,
                                    Geometry geometry)
Exports the specified geometry instance to it's JSON representation. M and Z values are not imported from JSON representation.

Parameters:
spatialReference - The spatial reference of associated object.
geometry - The geometry.
Returns:
The JSON representation of the specified geometry.

geometryToGeoJson

public static String geometryToGeoJson(Geometry geometry)

geometryToGeoJson

public static String geometryToGeoJson(int wkid,
                                       Geometry geometry)
Exports the specified geometry instance to its GeoJSON representation.

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(SpatialReference spatialReference, Geometry geometry)

geometryToGeoJson

public static String geometryToGeoJson(SpatialReference spatialReference,
                                       Geometry geometry)
Exports the specified geometry instance to it's JSON representation.

Parameters:
spatialReference - The spatial reference of associated object.
geometry - The geometry.
Returns:
The GeoJSON representation of the specified geometry.

geometryFromEsriShape

public static Geometry geometryFromEsriShape(byte[] esriShapeBuffer,
                                             Geometry.Type geometryType)
Imports geometry from the ESRI shape file format.

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

public static byte[] geometryToEsriShape(Geometry geometry)
Exports geometry to the ESRI shape file format.

Parameters:
geometry - The geometry to export. (null value is not allowed)
Returns:
Array containing the exported ESRI shape file.

geometryFromWkt

public static Geometry geometryFromWkt(String wkt,
                                       int importFlags,
                                       Geometry.Type geometryType)
Imports a geometry from a WKT string.

Parameters:
wkt - The string containing the geometry in WKT format.
importFlags - Use the WktImportFlags 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.
IllegalArgument - exception if an error is found while parsing the WKT string.

geometryFromGeoJson

public static MapGeometry geometryFromGeoJson(String geoJson,
                                              int importFlags,
                                              Geometry.Type geometryType)
                                       throws org.json.JSONException
Imports a geometry from a geoJson string.

Parameters:
geoJson - The string containing the geometry in geoJson format.
importFlags - Use the GeoJsonImportFlags 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 geoJson context.
Returns:
The geometry.
Throws:
GeometryException - when the geometryType is not Geometry.Type.Unknown and the geoJson contains a geometry that cannot be converted to the given geometryType.
IllegalArgument - exception if an error is found while parsing the geoJson string.
org.json.JSONException

geometryToWkt

public static String geometryToWkt(Geometry geometry,
                                   int exportFlags)
Exports a geometry to a string in WKT format.

Parameters:
geometry - The geometry to export. (null value is not allowed)
exportFlags - Use the WktExportFlags interface.
Returns:
A String containing the exported geometry in WKT format.

union

public static Geometry union(Geometry[] geometries,
                             SpatialReference spatialReference)
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.

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.

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.

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.

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)

intersect

public static Geometry intersect(Geometry geometry1,
                                 Geometry intersector,
                                 SpatialReference spatialReference)
Creates a geometry through intersection between two geometries.

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.

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.

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.

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.

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.

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.

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.

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.

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

public static Geometry[] cut(Geometry cuttee,
                             Polyline cutter,
                             SpatialReference spatialReference)
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.

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.

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

public static Polygon buffer(Geometry geometry,
                             SpatialReference spatialReference,
                             double distance)
Calculates a buffer polygon of the geometry as specified by the distance input. The buffer is implemented in the xy-plane.

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

public static Geometry convexHull(Geometry geometry)
Calculates the convex hull geometry.

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

public static Geometry[] convexHull(Geometry[] geometries,
                                    boolean b_merge)
Calculates the convex hull.

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.

Parameters:
inputPoint - The point to find the nearest coordinate in the geometry for.
geometry - The geometry to consider.
Returns:
Proximity2DResult containing the nearest coordinate.

getNearestVertex

public static Proximity2DResult getNearestVertex(Geometry geometry,
                                                 Point inputPoint)
Finds nearest vertex on the geometry which is closed to the specified point.

Parameters:
inputPoint - The point to find the nearest vertex of the geometry for.
geometry - The geometry to consider.
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.

Parameters:
inputPoint - The point to start from.
geometry - The geometry to consider.
searchRadius - The search radius.
maxVertexCountToReturn - The maximum number number of vertices to return.
Returns:
Proximity2DResult containing the array of nearest vertices.

simplify

public static Geometry simplify(Geometry geometry,
                                SpatialReference spatialReference)
Performs the simplify operation on the geometry.

Parameters:
geometry - The geometry to be simplified.
spatialReference - The spatial reference of the geometry to be simplified.
Returns:
The simplified geometry.

geodesicDistanceOnWGS84

public 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. 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.


Copyright © 2013. All Rights Reserved.