Class Geometry

  • All Implemented Interfaces:
    JsonSerializable
    Direct Known Subclasses:
    Envelope, Multipart, Multipoint, Point

    public abstract class Geometry
    extends Object
    implements JsonSerializable
    Base class for all classes that represent geometric shapes.

    Geometry is the base class for two-dimensional (x,y) or three-dimensional (x,y,z) geometries. Objects that inherit from the Geometry class may also include a measure (m value) for each vertex. The Geometry class provides functionality common to all types of geometry. Point, Multipoint, Polyline, Polygon, and Envelope all inherit from Geometry and represent different types of shapes.

    Geometry represents real-world objects by defining a shape at a specific geographic location. It is used throughout the API to represent the shapes of features and graphics, layer extents, viewpoints, and GPS locations. It is also used, for example, to define inputs and outputs for spatial analysis and geoprocessing operations and to measure distances and areas.

    All types of geometry:

    • Have a SpatialReference indicating the coordinate system used by its coordinates.
    • Can be empty, indicating that they have no specific location or shape.
    • May have z values and/or m values to define elevation and measures respectively.
    • Can be converted to and from JSON to be persisted or to be exchanged directly with REST services.

    Immutability

    Most geometries are created and not changed for their lifetime. Examples include features created to be stored in a geodatabase or read from a non-editable layer, and features returned from tasks such as a spatial query, geocode operation, network trace, or geoprocessing task. Immutable geometries (geometries that cannot be changed) offer some important benefits to your app. They are inherently thread-safe, help prevent inadvertent changes, and allow for certain performance optimizations.

    Instead of changing the properties of existing geometries, you can create and update geometries using the various subclasses of GeometryBuilder (for example, PolylineBuilder, which can represent the state of a geometry under construction while allowing modifications, thus enabling editing workflows.

    Additionally, GeometryEngine offers a range of topological and spatial transformations that read the content of existing geometries and create new geometries, for example, project, move, scale, rotate, buffer, union, and so on. Relational tests such as intersects and overlaps are also available on GeometryEngine.

    Coordinate units

    The coordinates that define a geometry are only meaningful in the context of the geometry's SpatialReference. The vertices and spatial reference together allow your app to translate a real-world object from its location on the Earth to its location on your map or scene.

    In some cases, a geometry's spatial reference may not be set. For example, a Graphic that does not have a spatial reference is drawn using the same spatial reference as the MapView to which it was added. If the coordinates are in a different spatial reference, the graphics may not display in the correction location, or at all.

    When using GeometryBuilder to create a Polyline or Polygon from a collection of Point, you don't need to set the spatial reference of every point before you add it to the builder, as it will be assigned the spatial reference of the builder itself. In most other cases, such as when using a geometry in geometry operations or when editing a feature table, getSpatialReference() must return a valid spatial reference.

    Spatial reference and projection

    Changing the coordinates of a geometry to have the same shape and location represented using a different SpatialReference is known as "projection" or sometimes as "reprojection". Because geometries are immutable, they do not have any member methods that project, transform, or otherwise modify their content.

    Since:
    100.0.0
    See Also:
    GeometryBuilder, GeometryEngine, MapView.setViewpointGeometryAsync(com.esri.arcgisruntime.geometry.Geometry), Feature.getGeometry(), Graphic.getGeometry(), MapView.setViewpointGeometryAsync(Geometry)
    • Constructor Detail

      • Geometry

        public Geometry()
    • Method Detail

      • fromJson

        public static Geometry fromJson​(String json)
        Creates a new Geometry from an ArcGIS JSON geometry representation.

        See the ArcGIS REST API help topic on Geometry objects for more information.

        Parameters:
        json - a string containing an ArcGIS JSON representation of a geometry
        Returns:
        a new Geometry constructed from the json string, or null if a geometry couldn't be constructed
        Throws:
        IllegalArgumentException - if json is null or empty
        Since:
        100.0.0
      • fromJson

        public static Geometry fromJson​(String json,
                                        SpatialReference spatialReference)
        Creates a new Geometry from an ArcGIS JSON geometry representation, and the given SpatialReference.

        Geometry can be serialized and de-serialized to and from JSON. The ArcGIS REST API documentation describes the JSON representation of geometry objects. You can use this encoding and decoding mechanism to exchange geometries with REST Web services or to store them in text files.

        Any SpatialReference defined in the JSON representation will be ignored in favor of the spatialReference parameter of this method.

        Parameters:
        json - a string containing an ArcGIS JSON representation of a geometry
        spatialReference - a SpatialReference to assign to the new geometry
        Returns:
        a new Geometry constructed from the json string, or null if a geometry couldn't be constructed
        Throws:
        IllegalArgumentException - if json is null or empty
        Since:
        100.0.0
      • getSpatialReference

        public SpatialReference getSpatialReference()
        Gets the SpatialReference of this Geometry. The SpatialReference of a Geometry defines how the coordinates of the Geometry correspond to locations in the real world.
        Returns:
        the SpatialReference of this Geometry
        Since:
        100.0.0
      • getDimension

        public GeometryDimension getDimension()
        Gets the dimension of this Geometry, relating to the number of spatial dimensions in which the geometry may have a size.
        Returns:
        the dimension of this Geometry
        Since:
        100.0.0
      • getExtent

        public Envelope getExtent()
        Gets an Envelope representing the spatial extent of this Geometry, the smallest Envelope that completely contains the Geometry.

        If the Geometry has z values and m values, these will be reflected in the properties of the returned Envelope. For an empty Geometry, the extent Envelope will also be empty. For a Point geometry, the extent will have zero width and height.

        Returns:
        the extent of this Geometry
        Since:
        100.0.0
      • getGeometryType

        public GeometryType getGeometryType()
        Gets the type of this Geometry, indicating the subclass, and the type of geometrical shape it can represent.
        Returns:
        the type of this Geometry
        Since:
        100.0.0
      • hasM

        public boolean hasM()
        Indicates if this Geometry has m values. M values are often referred to as measures, and are used in linear referencing workflows on linear datasets. NaN is a valid m value.

        If true, m values are stored for each vertex of the Geometry. Geometries with m values are created by using setters or constructors that take an m value as a parameter.

        Feature classes define whether their geometries have m values or not. When developing an editing workflow, you must ensure that this value matches that of the feature class in which the Geometry will be stored. The removeZ, removeM, and removeZAndM methods of GeometryEngine can be used to create new geometries without z- and m value from existing geometries that have the values. See the ArcGIS Desktop help topic Defining feature class properties for more information.

        Returns:
        true if this Geometry has m values; false otherwise
        Since:
        100.0.0
        See Also:
        hasZ(), GeometryEngine.removeM(Geometry), GeometryEngine.removeZ(Geometry), GeometryEngine.removeZAndM(Geometry)
      • hasZ

        public boolean hasZ()
        Indicates if this Geometry has z values. Z values are generally used as a z coordinate, indicating height or elevation. NaN is a valid z value.

        If true, z values are stored for each vertex of the Geometry. Geometries with z values are created by using setters or constructors that take a z value as a parameter.

        Feature classes define whether their geometries have z values or not. When developing an editing workflow, you must ensure that this value matches that of the feature class in which the Geometry will be stored. The removeZ, removeM, and removeZAndM methods of GeometryEngine can be used to create new geometries without z value and m value from existing geometries that have the values. See the ArcGIS Desktop help topic Defining feature class properties for more information.

        Returns:
        true if this Geometry has z values; false otherwise
        Since:
        100.0.0
        See Also:
        hasM(), GeometryEngine.removeM(Geometry), GeometryEngine.removeZ(Geometry), GeometryEngine.removeZAndM(Geometry)
      • hasCurves

        public boolean hasCurves()
        Indicates if this Geometry contains Segments that represent true curves.

        The ArcGIS Platform supports polygon and polyline geometries that contain curve segments (sometimes known as true curves or nonlinear segments). Curves may be present in certain types of data - for example Mobile Map Packages (MMPK), or geometry JSON. When connecting to ArcGIS feature services that support curves, ArcGIS Runtime retrieves densified versions of curve feature geometries.

        If a polygon or polyline geometry contains curve segments, this property returns true. Prior to v100.12, it was not possible to access curve segments, and only LineSegment instances would be returned when iterating through the segments in a Polygon or Polyline object, irrespective of this property; In editing workflows, use this method to determine if this geometry contains curve information which would be lost if used in an editing workflow.

        From v100.12, you can use curve segments when using a MultipartBuilder to create or edit polygon and polyline geometries, and also get curve segments when iterating through the segments of existing Multipart geometries when this property returns true.

        Returns:
        true if this Geometry contains curved segments; false otherwise
        Since:
        100.0.0
        See Also:
        GeometryBuilder.hasCurves(), ImmutablePart.hasCurves(), Segment.isCurve(), CubicBezierSegment, EllipticArcSegment
      • isEmpty

        public boolean isEmpty()
        Indicates if this Geometry is empty. An empty Geometry is a valid object, but has no location in space.

        For an empty Geometry, hasZ() and hasM() return false, and getExtent() returns an empty Envelope.

        Returns:
        true if this Geometry is empty; false otherwise
        Since:
        100.0.0
      • toJson

        public String toJson()
        Returns an ArcGIS JSON geometry representation of this Geometry.

        See the ArcGIS REST API help topic on Geometry objects for more information.

        Specified by:
        toJson in interface JsonSerializable
        Returns:
        a string containing the JSON representation of this geometry
        Since:
        100.0.0
      • getUnknownJson

        public Map<String,​Object> getUnknownJson()
        A Geometry never has any unknown JSON so this returns an empty Map.
        Specified by:
        getUnknownJson in interface JsonSerializable
        Returns:
        an empty unmodifiable Map
        Since:
        100.0.0
      • getUnsupportedJson

        public Map<String,​Object> getUnsupportedJson()
        A Geometry never has any unsupported JSON so this returns an empty Map.
        Specified by:
        getUnsupportedJson in interface JsonSerializable
        Returns:
        an empty unmodifiable Map
        Since:
        100.0.0
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • equals

        public boolean equals​(Object obj)

        This method is more stringent than the GeometryEngine.equals(Geometry, Geometry) method, as in addition to these checks, this method checks that each vertex in a Multipoint or Multipart geometry is in the same order; parts of Multiparts must also begin and end at the same Point.

        Overrides:
        equals in class Object
      • equals

        public boolean equals​(Geometry geometry,
                              double tolerance)
        Checks if a given geometry is equal to this one within a given tolerance.

        This method performs a lightweight comparison of the geometries, such as might be useful when writing test code. It uses the tolerance to compare each of x, y, and any other values the geometries possess (such as z or m) independently in the manner: abs(value1 - value2) <= tolerance.

        Returns true if the difference of each is within the tolerance and all other properties of the geometries are exactly equal (spatial reference, vertex count, etc.). A single tolerance is used even if the units for the horizontal coordinates and other values differ, for example horizontal coordinates in degrees and vertical coordinates in meters.

        This method does not respect modular arithmetic of spatial references which wrap around, so longitudes of -180 and +180 degrees are considered to differ by 360 degrees.

        Parameters:
        geometry - the geometry to check
        tolerance - the tolerance
        Returns:
        true if the geometries are equal, within the tolerance, otherwise false
        Since:
        100.1.0
        See Also:
        equals(Object)