require(["esri/geometry/Polygon"], function(Polygon) { /* code goes here */ });
Class: esri/geometry/Polygon
Inheritance: Polygon Geometry Accessor
Subclasses: Circle
Since: ArcGIS API for JavaScript 4.0

A polygon contains an array of rings and a spatialReference. Each ring is represented as an array points. The first and last points of a ring must be the same. A polygon also has boolean-valued hasM and hasZ fields.

Known Limitations

If working in a SceneView, polygons are only supported when their vertices are defined in clockwise order.

See also:

Constructors

new Polygon(properties)

Parameter:
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
NameTypeSummary
Object

The cache is used to store values computed from geometries that need to cleared or recomputed upon mutation.

more details
more details
Point

The centroid of the polygon.

more details
more details
String

The name of the class.

more details
more details
Extent

The extent of the geometry.

more details
more details
Boolean

Indicates if the geometry has M values.

more details
more details
Boolean

Indicates if the geometry has Z (elevation) values.

more details
more details
Boolean

Checks to see if polygon rings cross each other and indicates if the polygon is self-intersecting, which means the ring of the polygon crosses itself.

more details
more details
Number[][][]

An array of rings.

more details
more details
SpatialReference

The spatial reference of the geometry.

more details
more details
String

For Polygon, the type is always polygon.

more details
more details

Property Details

cacheObjectreadonly

The cache is used to store values computed from geometries that need to cleared or recomputed upon mutation. An example is the extent of a polygon. The default value is null.

centroidPoint

The centroid of the polygon. For a polygon with multiple rings, it represents the centroid of the largest ring.

declaredClassStringreadonly

The name of the class. The declared class name is formatted as esri.folder.className.

extentExtentreadonly

The extent of the geometry. For points, the extent is null.

Indicates if the geometry has M values.

Indicates if the geometry has Z (elevation) values.

Z-values defined in a geographic or metric coordinate system are expressed in meters. However, in local scenes that use a projected coordinate system, vertical units are assumed to be the same as the horizontal units specified by the service.

isSelfIntersectingBoolean

Checks to see if polygon rings cross each other and indicates if the polygon is self-intersecting, which means the ring of the polygon crosses itself.

An array of rings. Each ring is a two-dimensional array of numbers representing the coordinates of each vertex in the ring in the spatial reference of the view. The first vertex of each ring should always be the same as the last vertex. Each vertex is an array of two, three, or four numbers. The table below shows the various structures of a vertex array.

CaseVertex array
without z and without m[x, y]
without z and with m[x, y, m]
with z and without m[x, y, z]
with z and with m[x, y, z, m]
Example:
//3D polygon rings with m-values (note that the second ring does not have m-values defined for it)
var rings = [
 [  // first ring
  [-97.06138,32.837,35.1,4.8],
  [-97.06133,32.836,35.2,4.1],
  [-97.06124,32.834,35.3,4.2],
  [-97.06138,32.837,35.1,4.8]  // same as first vertex
 ], [  // second ring
  [-97.06326,32.759,35.4],
  [-97.06298, 2.755,35.5],
  [-97.06153,32.749,35.6],
  [-97.06326,32.759,35.4]  // same as first vertex
 ]
];

var polygon = new Polygon({
  hasZ: true,
  hasM: true,
  rings: rings,
  spatialReference: { wkid: 4326 }
});

spatialReferenceSpatialReference autocast

The spatial reference of the geometry.

Default Value: WGS84 (wkid: 4326)

typeStringreadonly

For Polygon, the type is always polygon.

Method Overview

NameReturn TypeSummary
Polygon

Adds a ring to the Polygon.

more details
more details
Polygon

Creates a deep clone of Polygon object.

more details
more details
Boolean

Checks on the client if the input point is inside the polygon.

more details
more details
Polygon

Converts the given Extent to a Polygon instance.

more details
more details
*

Creates a new instance of this class and initializes it with values from a JSON object generated from a product in the ArcGIS platform.

more details
more details
Point

Returns a point specified by a ring and point in the path.

more details
more details
Polygon

Inserts a new point into the polygon.

more details
more details
Boolean

Checks if a Polygon ring is clockwise.

more details
more details
Point[]

Removes a point from the polygon at the given pointIndex within the ring identified by ringIndex.

more details
more details
Point[]

Removes a ring from the Polygon.

more details
more details
Polygon

Updates a point in the polygon.

more details
more details
Object

Converts an instance of this class to its ArcGIS Portal JSON representation.

more details
more details

Method Details

addRing(ring){Polygon}

Adds a ring to the Polygon. The ring can be one of the following: an array of numbers or an array of points. When added the index of the ring is incremented by one.

Parameter:

A polygon ring. The first and last coordinates/points in the ring must be the same. This can either be defined as an array of Point geometries or an array of XY coordinates.

Returns:
TypeDescription
PolygonReturns the polygon with the new ring included.

clone(){Polygon}

Creates a deep clone of Polygon object.

Returns:
TypeDescription
PolygonA new instance of a Polygon object equal to the object used to call .clone().

contains(point){Boolean}

Checks on the client if the input point is inside the polygon. A point on the polygon line is considered inside.

Parameter:
point Point

The point to test whether it is contained within the testing polygon.

Returns:
TypeDescription
BooleanReturns true if the point is located inside the polygon.

fromExtent(extent){Polygon}static

Converts the given Extent to a Polygon instance. This is useful for scenarios in which you would like to display an area of interest, which is typically defined by an Extent or bounding box, as a polygon with a fill symbol in the view. Some geoprocessing tools require input geometries to be of a Polygon type and not an Extent.

Parameter:
extent Extent

An extent object to convert to a polygon.

Returns:
TypeDescription
PolygonA polygon instance representing the given extent.
Example:
view.on("click", function(evt){
  var area = Polygon.fromExtent(view.extent);
  var graphic = new Graphic({
    geometry: area,
    symbol: new SimpleFillSymbol()
  });
  view.graphics.add(graphic);
});

fromJSON(json){*}static

Creates a new instance of this class and initializes it with values from a JSON object generated from a product in the ArcGIS platform. The object passed into the input json parameter often comes from a response to a query operation in the REST API or a toJSON() method from another ArcGIS product. See the Using fromJSON() topic in the Guide for details and examples of when and how to use this function.

Parameter:
json Object

A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects.

Returns:
TypeDescription
*Returns a new instance of this class.

getPoint(ringIndex, pointIndex){Point}

Returns a point specified by a ring and point in the path.

Parameters:
ringIndex Number

The index of the ring containing the desired point.

pointIndex Number

The index of the desired point within the ring.

Returns:
TypeDescription
PointReturns the point at the specified ring index and point index.

insertPoint(ringIndex, pointIndex, point){Polygon}

Inserts a new point into the polygon.

Parameters:
ringIndex Number

The index of the ring in which to insert the point.

pointIndex Number

The index of the point to insert within the ring.

point Point

The point geometry to insert.

Returns:
TypeDescription
PolygonReturns the updated polygon.

isClockwise(ring){Boolean}

Checks if a Polygon ring is clockwise.

Parameter:

A polygon ring. The first and last coordinates/points in the ring must be the same. This can either be defined as an array of Point geometries or an array of XY coordinates.

Returns:
TypeDescription
BooleanReturns true if the ring is clockwise and false for counterclockwise.

removePoint(ringIndex, pointIndex){Point[]}

Removes a point from the polygon at the given pointIndex within the ring identified by ringIndex.

Parameters:
ringIndex Number

The index of the ring containing the point to remove.

pointIndex Number

The index of the point to remove within the ring.

Returns:
TypeDescription
Point[]Returns the geometry of the removed point.

removeRing(index){Point[]}

Removes a ring from the Polygon. The index specifies which ring to remove.

Parameter:
index Number

The index of the ring to remove.

Returns:
TypeDescription
Point[]Returns array of points representing the removed ring.

setPoint(ringIndex, pointIndex, point){Polygon}

Updates a point in the polygon.

Parameters:
ringIndex Number

The index of the ring containing the point to update.

pointIndex Number

The index of the point to update within the ring.

point Point

The new point geometry.

Returns:
TypeDescription
PolygonReturns the updated polygon.

toJSON(){Object}inherited

Converts an instance of this class to its ArcGIS Portal JSON representation. See the Using fromJSON() topic in the Guide for more information.

Returns:
TypeDescription
ObjectThe ArcGIS Portal JSON representation of an instance of this class.

API Reference search results

NameTypeModule

There were no match results from your search criteria.