Class GeometryBuilder

  • Direct Known Subclasses:
    EnvelopeBuilder, MultipartBuilder, MultipointBuilder, PointBuilder

    public abstract class GeometryBuilder
    extends java.lang.Object
    Base class for builders that allow immutable geometries to be defined incrementally. Each type of Geometry has a corresponding type of builder - for example, PolygonBuilder creates Polygons.

    Create a new empty builder in order to build up the shape of a Geometry step by step. Alternatively for editing workflows, initialize the builder by passing the existing Geometry to be edited into the builder constructor, then make the required changes. In both cases, call toGeometry() to return a new immutable geometry based on the current state of the geometry in the builder. The state of a builder can be completely overwritten by calling replaceGeometry(Geometry).

    The SpatialReference of a builder is either set explicitly by specifying a SpatialReference object in some constructors, or is set implicitly from other constructor arguments. Once set, SpatialReference cannot be changed. When building geometries, the SpatialReference of any objects or coordinates added to the builder must be compatible with the SpatialReference of the builder; added items are not reprojected. The SpatialReference of added items may be null, in which case the object is assumed to have the same SpatialReference as the builder it is added to.

    A number of other methods provide information about the geometry currently being constructed. A new builder will be empty. The hasZ() and hasM() methods indicate if the builder allows adding z- and m- values for each coordinate in the geometry.

    Since:
    100.0.0
    See Also:
    Geometry, GeometryBuilderType
    • Method Detail

      • create

        public static GeometryBuilder create​(Geometry geometry)
        Creates a geometry builder using the given geometry as a starting point for further modifications.

        Prior to v100.12, only geometries without curves could be used; passing in a geometry where Geometry.hasCurves() is true would throw an exception.

        From v100.12, geometries with curves are supported.

        Parameters:
        geometry - the geometry to use as the starting point for further modifications
        Returns:
        the new geometry builder
        Throws:
        java.lang.IllegalArgumentException - if geometry is null
        Since:
        100.1.0
        See Also:
        hasCurves()
      • create

        public static GeometryBuilder create​(GeometryType geometryType,
                                             SpatialReference spatialReference)
        Creates a geometry builder which builds geometries of the given type.
        Parameters:
        geometryType - the builder's geometry type
        spatialReference - the builder's spatial reference; may be null
        Returns:
        the new geometry builder
        Throws:
        java.lang.IllegalArgumentException - if geometryType is null
        Since:
        100.1.0
      • getSpatialReference

        public SpatialReference getSpatialReference()
        Gets the SpatialReference of this instance. Once set, the SpatialReference of a GeometryBuilder cannot be changed. Ensure that all objects set into the builder have a compatible SpatialReference; objects with incompatible SpatialReferences may cause exceptions.
        Returns:
        the spatial reference of this instance
        Since:
        100.0.0
        See Also:
        hasCurves()
      • getExtent

        public Envelope getExtent()
        Gets an Envelope representing the current extent of the Geometry being constructed.
        Returns:
        the current extent of the geometry being constructed
        Since:
        100.0.0
      • hasCurves

        public boolean hasCurves()
        Gets a value indicating whether the geometry builder currently contains any curve segments.

        The ArcGIS Platform supports polygon and polyline geometries that contain curve segments (where Segment.isCurve() is true, sometimes known as true curves or nonlinear segments). Curves may be present in certain types of data - for example Mobile Map Packages (MMPKs), or geometry JSON.

        Prior to 100.12, only LineSegment instances were supported when creating new geometries using a MultipartBuilder. Attempting to add curve geometries to a MultipartBuilder would cause an error.

        From 100.12, you can use curves in a MultipartBuilder. New segment types CubicBezierSegment and EllipticArcSegment represent different types of curve that can be added to polygon and polyline geometries.

        Returns:
        true if this GeometryBuilder contains curved segments; false otherwise
        Since:
        100.12.0
        See Also:
        Part.hasCurves(), Geometry.hasCurves(), Segment.isCurve()
      • getBuilderType

        public GeometryBuilderType getBuilderType()
        Gets the subtype of this builder instance. This indicates which type of geometries the builder can create; each type of builder creates a single GeometryType.
        Returns:
        the builder subtype
        Since:
        100.0.0
      • hasZ

        public boolean hasZ()
        Indicates if this builder 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 constructed Geometry. Geometries with z values are created by using setters or constructors that take a z value as a parameter.

        Returns:
        true if this builder contains z values, false otherwise
        Since:
        100.0.0
        See Also:
        Geometry.hasZ()
      • hasM

        public boolean hasM()
        Indicates if this builder 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 constructed Geometry. Geometries with m values are created by using setters or constructors that take an m value as a parameter.

        Returns:
        true if this builder has m values, false otherwise
        Since:
        100.0.0
        See Also:
        Geometry.hasM()
      • isEmpty

        public boolean isEmpty()
        Indicates if any coordinates have been added to this builder. An empty builder may have a valid SpatialReference set, but contains no coordinates.
        Returns:
        true if no coordinates have been added to this instance, false otherwise
        Since:
        100.0.0
        See Also:
        Geometry.isEmpty()
      • isSketchValid

        public boolean isSketchValid()
        Check if a geometry builder contains sufficient points to show a valid graphical sketch.

        This can be used as an initial lightweight check to see if the current state of a builder will produce a non-empty geometry; for example, it may be used to enable or disable functionality in an editing user interface. The exact requirements vary depending on the type of geometry produced by the builder:

        Note that this is not equivalent to topological simplicity, which is enforced by GeometryEngine.simplify(Geometry) and checked using GeometryEngine.isSimple(Geometry). Geometries must be topologically simple to be successfully saved in a geodatabase, or used in some service operations.

        Does not check the spatial reference. Will return false if an error occurs.

        Prior to v100.8, only one part of a multipart polygon or polyline was required to have the minimum number (2 for a polyline, 3 for a polygon) of points, and only LineSegment instances were supported in builders.

        Prior to v100.12, a PolygonBuilder required at least three valid Points in each part, and at least one part.

        Returns:
        true if toGeometry() would return a geometry that is a valid sketch, false otherwise
        Since:
        100.0.0
      • replaceGeometry

        public void replaceGeometry​(Geometry geometry)
        Replaces the geometry currently stored in this builder with the new geometry. This method can be used as an alternative to creating a new builder instance from an existing geometry.

        This does not update the spatial reference of the builder. If the geometry is null, the builder is cleared.

        Prior to v100.12, only geometries without curves could be used; passing in a geometry where Geometry.hasCurves() is true would throw an exception.

        From v100.12, geometries with curves are supported.

        Parameters:
        geometry - the new geometry to replace the existing geometry with
        Since:
        100.0.0
      • toGeometry

        public abstract Geometry toGeometry()
        Returns a new Geometry based on the current state of this builder. This method can be called as many times as required for any specific instance; it does not affect the state of the builder, and returns a new Geometry each time.
        Returns:
        a new Geometry based on the current state of this builder
        Since:
        100.0.0