Class Polygon

  • All Implemented Interfaces:
    JsonSerializable

    public final class Polygon
    extends Multipart
    A multipart shape used to represent an area.

    Polygon geometries represent the shape and location of areas, for example, a country, island, or a lake. They can be used as the geometry of features and graphics, or as input or output of tasks or geoprocessing operations, such as the output of a drive-time analysis or a GeometryEngine.buffer(Iterable, Iterable, boolean) operation.

    Each part of a multipart polygon is a series of connected segments forming a closed ring. Each part must not cross any other part but may lie completely inside or outside another part. For example, a polygon representing the state of Hawaii would comprise eight disjoint parts, one representing each island. A polygon representing the country of South Africa, which completely surrounds the enclave of Lesotho, would comprise two parts, one contained inside the other.

    Like Polyline, the Polygon class is a Multipart, which provides members for iterating the segments and points of each part in a polygon. Unlike parts in a Polyline, however, each part of a polygon defines a closed area, so the end point of the last segment in the part is always in the same location as the start point of the first segment, forming a closed boundary.

    When defining a polygon part, there is no need to explicitly close it by repeating the start point as the last point. Polygon's parts are always interpreted as enclosed areas by ArcGIS Runtime.

    Interior rings created to make donut polygons should be counter-clockwise in direction to have the correct topology.

    If there is ever a doubt about the topological correctness of a polygon, call GeometryEngine.simplify(Geometry) to correct any issues. This is especially true if you pass a polygon to ArcGIS Server for a geoprocessing task to avoid any ArcGIS Server errors being thrown. You can also call GeometryEngine#simplify(Geometry) to rectify polygons that may be self-intersecting, have rings which are partially contained in each other, or contain incorrect ring orientations.

    Polygon is immutable. To build a new polygon one point at a time, or modify an existing polygon, use a PolygonBuilder.

    A Polygon can be used as the geometry of a Feature or Graphic. To obtain the geometry, use Feature.getGeometry() or Graphic.getGeometry().

    Since:
    100.0.0
    See Also:
    Geometry, PolygonBuilder
    • Constructor Detail

      • Polygon

        public Polygon​(PointCollection points)
        Creates a new immutable Polygon containing a copy of the Points in the given PointCollection. The SpatialReference of the new Polygon will match that of the given PointCollection.
        Parameters:
        points - the PointCollection used to initialize the new Polygon
        Since:
        100.0.0
      • Polygon

        public Polygon​(PointCollection points,
                       SpatialReference spatialReference)
        Creates a new Polygon containing a copy of the Points in the given PointCollection, and with the given SpatialReference.

        This overload can be used to create a new Polygon with a specific SpatialReference from an existing PointCollection that has a null SpatialReference (the points are assigned the given SpatialReference-they are not projected).

        Parameters:
        points - the PointCollection containing points copied to the new Polygon
        spatialReference - the SpatialReference of the new Polygon
        Throws:
        ArcGISRuntimeException - if the SpatialReference of points does not match the spatialReference
        Since:
        100.0.0
      • Polygon

        public Polygon​(Part part)
        Creates a new immutable Polygon containing a copy of the given Part. The SpatialReference of the new Polygon will match that of the given Part.
        Parameters:
        part - the Part used to initialize the new Polygon
        Since:
        100.0.0
      • Polygon

        public Polygon​(Part part,
                       SpatialReference spatialReference)
        Creates a new Polygon containing a copy of the given Part, and with the given SpatialReference.
        Parameters:
        part - the Part to copy to the new Polygon
        spatialReference - the SpatialReference of the new Polygon
        Throws:
        ArcGISRuntimeException - if the SpatialReference of part does not match the spatialReference
        Since:
        100.0.0
      • Polygon

        public Polygon​(PartCollection parts)
        Creates a new immutable Polygon containing a copy of the given PartCollection. The SpatialReference of the new Polygon will match that of the given PartCollection.
        Parameters:
        parts - the PartCollection used to initialize the new Polygon
        Since:
        100.0.0
      • Polygon

        public Polygon​(PartCollection parts,
                       SpatialReference spatialReference)
        Creates a new Polygon containing a copy of the given PartCollection, and with the given SpatialReference.
        Parameters:
        parts - the PartCollection to be copied to the new Polygon
        spatialReference - the SpatialReference of the new Polygon
        Throws:
        ArcGISRuntimeException - if the SpatialReference of part does not match spatialReference
        Since:
        100.0.0
    • Method Detail

      • toPolyline

        public Polyline toPolyline()
        Returns a new Polyline representing the boundary of this Polygon.
        Returns:
        a new Polyline
        Since:
        100.0.0