Geometry Class

  • Geometry
  • class Esri::ArcGISRuntime::Geometry

    Base class for all classes that represent geometric shapes. More...

    Public Functions

    Geometry()
    Geometry(const Esri::ArcGISRuntime::Geometry &other)
    Geometry(Esri::ArcGISRuntime::Geometry &&other)
    virtual ~Geometry() override
    Esri::ArcGISRuntime::GeometryDimension dimension() const
    bool equalsWithTolerance(const Esri::ArcGISRuntime::Geometry &other, double tolerance) const
    Esri::ArcGISRuntime::Envelope extent() const
    Esri::ArcGISRuntime::GeometryType geometryType() const
    bool hasCurves() const
    bool hasM() const
    bool hasZ() const
    bool isEmpty() const
    Esri::ArcGISRuntime::SpatialReference spatialReference() const
    bool operator!=(const Esri::ArcGISRuntime::Geometry &other) const
    Esri::ArcGISRuntime::Geometry &operator=(const Esri::ArcGISRuntime::Geometry &other)
    Esri::ArcGISRuntime::Geometry &operator=(Esri::ArcGISRuntime::Geometry &&other)
    bool operator==(const Esri::ArcGISRuntime::Geometry &other) const

    Reimplemented Public Functions

    virtual QString toJson() const override
    virtual QJsonObject unknownJson() const override
    virtual QJsonObject unsupportedJson() const override

    Static Public Members

    Esri::ArcGISRuntime::Geometry fromJson(const QString &json)

    Detailed Description

    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 this 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, PolygonBuilder). A geometry builder can represent the state of a geometry under construction while allowing modifications, thus enabling editing workflows. You can also use the GeometryEditor to create new geometries, and change existing geometries, by interacting directly with a MapView.

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

    GeometryEngine, provides a wide range of methods that read the content of geometries and modify that content to create new geometries. For example, there are methods to GeometryEngine::project(), GeometryEngine::moveGeodetic(), GeometryEngine::cut(), GeometryEngine::densify(), and GeometryEngine::generalize() geometries.

    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 GeoView to which it was added. If the coordinates are in a different spatial reference, the graphics may not display in the correct 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 is 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, spatialReference must be set.

    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.

    See also GeometryEngine, GeometryBuilder, and GeometryEditor.

    Member Function Documentation

    Geometry::Geometry()

    Default constructor. Creates an empty Geometry.

    Geometry::Geometry(const Esri::ArcGISRuntime::Geometry &other)

    Copy constructor from other Geometry.

    Geometry::Geometry(Esri::ArcGISRuntime::Geometry &&other)

    Move constructor from other Geometry.

    [override virtual] Geometry::~Geometry()

    Destructor.

    Esri::ArcGISRuntime::GeometryDimension Geometry::dimension() const

    Returns the number of dimensions for the geometry.

    Every non-empty Geometry has an inherent dimension (sometimes called the topological dimensionality) that indicates the general class of the Geometry.

    Returns GeometryDimension::Unknown if an error occurs.

    bool Geometry::equalsWithTolerance(const Esri::ArcGISRuntime::Geometry &other, double tolerance) const

    Returns if two geometries are approximately the same within the given tolerance.

    • other - The second geometry.
    • tolerance - The tolerance.

    This function performs a lightweight comparison of two geometries that 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. The single tolerance value is used even if the x, y, z or m units differ. This function 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.

    Returns true if the difference of each is within the tolerance and all other properties of the geometries are exactly equal (such as spatial reference and vertex count). Returns false if an error occurs.

    For topological equality, use a relational operator such as GeometryEngine::equals().

    Esri::ArcGISRuntime::Envelope Geometry::extent() const

    Returns the minimum enclosing bounding-box (or Envelope) that covers the geometry.

    [static] Esri::ArcGISRuntime::Geometry Geometry::fromJson(const QString &json)

    Converts a JSON string to an object.

    • json - The JSON string.

    Esri::ArcGISRuntime::GeometryType Geometry::geometryType() const

    Returns the type of geometry.

    This indicates the type of geometrical shape it can represent, such as Envelope, Point or Polygon.

    Returns GeometryType::Unknown if an error occurs.

    bool Geometry::hasCurves() const

    Returns true if this geometry contains curve segments, false otherwise.

    ArcGIS software 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, such as Mobile Map Packages (MMPK) or geometry JSON. When connecting to ArcGIS feature services that support curves (see ArcGISFeatureServiceInfo::isSupportsTrueCurve), this API retrieves densified versions of curve feature geometries by default.

    If a polygon or polyline geometry contains curve segments, this property returns true. 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. You can also choose to return true curves from feature services by using ArcGISRuntimeEnvironment::serviceCurveGeometryMode.

    See also GeometryBuilder::hasCurves, ImmutablePart::hasCurves, CubicBezierSegment, and EllipticArcSegment.

    bool Geometry::hasM() const

    Returns true if the geometry has m values (measure values), false otherwise.

    M is a vertex value that is stored with the geometry. These values typically represent non-spatial measurements or attributes.

    bool Geometry::hasZ() const

    Returns true if the geometry has z-coordinate values, false otherwise.

    Only 3D geometries contain z-coordinate values. These values typically represent elevation, height, or depth.

    bool Geometry::isEmpty() const

    Returns true if the geometry is empty, false otherwise.

    A geometry is empty if it does not have valid geographic coordinates, even if the SpatialReference is specified. An empty Geometry is a valid object that has no location in space.

    Esri::ArcGISRuntime::SpatialReference Geometry::spatialReference() const

    Returns the spatial reference for this geometry.

    This can be nullptr if the geometry is not associated with a SpatialReference.

    [override virtual] QString Geometry::toJson() const

    Reimplements: JsonSerializable::toJson() const.

    Converts a geometry into an ArcGIS json geometry representation.

    Returns this Geometry represented as a JSON String.

    [override virtual] QJsonObject Geometry::unknownJson() const

    Reimplements: JsonSerializable::unknownJson() const.

    Returns unknown data from the source JSON.

    Unknown JSON is a dictionary of values not defined in the ArcGIS specification used to create this object but found in the source JSON. If the object is written back to JSON, any unknown JSON data is not persisted. The ArcGIS specification may be for a web map, web scene, REST API, and so on.

    See also JsonSerializable.

    [override virtual] QJsonObject Geometry::unsupportedJson() const

    Reimplements: JsonSerializable::unsupportedJson() const.

    Returns the unsupported data from the source JSON.

    Unsupported JSON is a dictionary of values defined in the ArcGIS specification used to create this object but not currently used in this API. If the object is written back to JSON, any unsupported JSON data is persisted. The ArcGIS specification may be from a web map, web scene, REST API, and so on.

    See also JsonSerializable.

    [since Esri::ArcGISRuntime 200.2] bool Geometry::operator!=(const Esri::ArcGISRuntime::Geometry &other) const

    Inequality operator. Returns true if this object and other are not equal.

    This function was introduced in Esri::ArcGISRuntime 200.2.

    See also Geometry::operator==.

    Esri::ArcGISRuntime::Geometry &Geometry::operator=(const Esri::ArcGISRuntime::Geometry &other)

    Assignment operator from other Geometry.

    Esri::ArcGISRuntime::Geometry &Geometry::operator=(Esri::ArcGISRuntime::Geometry &&other)

    Move operator from other Geometry.

    bool Geometry::operator==(const Esri::ArcGISRuntime::Geometry &other) const

    Returns if two geometries are exactly equal. The types of geometry, order of points, all values, and the SpatialReference must all be equal.

    • other - The second geometry.

    This method provides a strict comparison of two geometries to ensure that they are identical. For a slightly more relaxed comparison (one that does not take coordinate order into account), use GeometryEngine::equals().

    Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.