Polygon Class |
Namespace: Esri.ArcGISRuntime.Geometry
The Polygon type exposes the following members.
Name | Description | |
---|---|---|
![]() ![]() | Polygon(IEnumerableMapPoint) |
Initializes a new instance of the Polygon class.
|
![]() ![]() | Polygon(IEnumerableIEnumerableMapPoint) |
Initializes a new instance of the Polygon class.
|
![]() | Polygon(IEnumerableSegment) |
Initializes a new instance of the Polygon class.
|
![]() | Polygon(IEnumerableIEnumerableSegment) |
Initializes a new instance of the Polygon class.
|
![]() ![]() | Polygon(IEnumerableMapPoint, SpatialReference) |
Initializes a new instance of the Polygon class.
|
![]() | Polygon(IEnumerableIEnumerableMapPoint, SpatialReference) |
Initializes a new instance of the Polygon class.
|
![]() | Polygon(IEnumerableSegment, SpatialReference) |
Initializes a new instance of the Polygon class.
|
![]() | Polygon(IEnumerableIEnumerableSegment, SpatialReference) |
Initializes a new instance of the Polygon class.
|
Name | Description | |
---|---|---|
![]() | Dimension | Gets the number of dimensions for the geometry. (Overrides GeometryDimension.) |
![]() | Extent |
Gets the minimum enclosing Envelope of the instance
(Inherited from Multipart.) |
![]() | GeometryType |
Gets the geometry type.
(Overrides GeometryGeometryType.) |
![]() | HasCurves | Gets a value indicating whether the geometry has any curves. (Inherited from Geometry.) |
![]() | HasM |
Gets a value indicating if the geometry has M
(Inherited from Multipart.) |
![]() | HasZ |
Gets a value indicating if the geometry has Z.
(Inherited from Multipart.) |
![]() | IsEmpty |
Gets a value indicating whether or not the geometry is empty.
(Inherited from Multipart.) |
![]() ![]() | Parts |
Gets the parts in the geometry
(Inherited from Multipart.) |
![]() ![]() | SpatialReference | Gets the spatial reference of this geometry. (Inherited from Geometry.) |
Name | Description | |
---|---|---|
![]() | Equals | Checks if two geometries are approximately same, within some tolerance. (Inherited from Geometry.) |
![]() | IsEqual |
Compares two Polygon for equality. This will check for a matching SpatialReference
and the content of Parts match. The order of parts must match too.
(Overrides GeometryIsEqual(Geometry).) |
![]() | ToJson | Converts this geometry into an ArcGIS JSON representation. (Inherited from Geometry.) |
![]() | ToPolyline |
Returns a Polyline representation of this polygon.
|
![]() | ToString | (Overrides ObjectToString.) |
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 Buffer(Geometry, Double) 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.
Polygon is similar to Polyline in that they are both composed of a series of connected segments. Like a polyline, the polygon class is a Multipart, which provides members for iterating the segments and map points of each part in a polyline. Unlike parts in a polyline, however, each part of a polygon defines a closed area, so the end map point of the last segment in the part is always in the same location as the start map 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 map point as the last map point. Polygons parts are always interpreted as enclosed areas by the ArcGIS Runtime. However, you may need to simplify a polygon created with Runtime before storing it in a geodatabase or using it in geometry operations that rely on topological consistency.
To build a polygon one point at a time, or modify an existing polygon, use a ref@PolygonBuilder.
Note: Interior rings to make donut polygons should be counter-clockwise in direction to be topology correct. If there is ever a doubt about the topological correctness of a polygon, call the Simplify(Geometry) method 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.
WPF
Example Name: AddGraphicsWithSymbols
Use a symbol style to display a graphic on a graphics overlay.
// Copyright 2018 Esri. // // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. // You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific // language governing permissions and limitations under the License. using Esri.ArcGISRuntime.Geometry; using Esri.ArcGISRuntime.Mapping; using Esri.ArcGISRuntime.Symbology; using Esri.ArcGISRuntime.UI; using System.Drawing; namespace ArcGISRuntime.WPF.Samples.AddGraphicsWithSymbols { [ArcGISRuntime.Samples.Shared.Attributes.Sample( name: "Add graphics with symbols", category: "GraphicsOverlay", description: "Use a symbol style to display a graphic on a graphics overlay.", instructions: "Observe the graphics on the map.", tags: new[] { "SimpleFillSymbol", "SimpleLineSymbol", "SimpleMarkerSymbol" })] public partial class AddGraphicsWithSymbols { // Create the graphics overlay private readonly GraphicsOverlay _overlay = new GraphicsOverlay(); public AddGraphicsWithSymbols() { InitializeComponent(); Initialize(); } private void Initialize() { // Create the map Map myMap = new Map(BasemapType.Oceans, 56.075844, -2.681572, 14); // Add the map to the map view MyMapView.Map = myMap; // Add the graphics overlay to the map view MyMapView.GraphicsOverlays.Add(_overlay); // Call functions to create the graphics CreatePoints(); CreatePolygon(); CreatePolyline(); CreateText(); // Update the extent to encompass all of the symbols SetExtent(); } private void CreatePoints() { // Create a red circle simple marker symbol SimpleMarkerSymbol redCircleSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.FromArgb(0xFF, 0xFF, 0x00, 0x00), 10); // Create graphics and add them to graphics overlay Graphic graphic = new Graphic(new MapPoint(-2.72, 56.065, SpatialReferences.Wgs84), redCircleSymbol); _overlay.Graphics.Add(graphic); graphic = new Graphic(new MapPoint(-2.69, 56.065, SpatialReferences.Wgs84), redCircleSymbol); _overlay.Graphics.Add(graphic); graphic = new Graphic(new MapPoint(-2.66, 56.065, SpatialReferences.Wgs84), redCircleSymbol); _overlay.Graphics.Add(graphic); graphic = new Graphic(new MapPoint(-2.63, 56.065, SpatialReferences.Wgs84), redCircleSymbol); _overlay.Graphics.Add(graphic); } private void CreatePolyline() { // Create a purple simple line symbol SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.FromArgb(0xFF, 0x80, 0x00, 0x80), 4); // Create a new point collection for polyline Esri.ArcGISRuntime.Geometry.PointCollection points = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84) { // Create and add points to the point collection new MapPoint(-2.715, 56.061), new MapPoint(-2.6438, 56.079), new MapPoint(-2.638, 56.079), new MapPoint(-2.636, 56.078), new MapPoint(-2.636, 56.077), new MapPoint(-2.637, 56.076), new MapPoint(-2.715, 56.061) }; // Create the polyline from the point collection Polyline polyline = new Polyline(points); // Create the graphic with polyline and symbol Graphic graphic = new Graphic(polyline, lineSymbol); // Add graphic to the graphics overlay _overlay.Graphics.Add(graphic); } private void CreatePolygon() { // Create a green simple line symbol SimpleLineSymbol outlineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.FromArgb(0xFF, 0x00, 0x50, 0x00), 1); // Create a green mesh simple fill symbol SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.DiagonalCross, Color.FromArgb(0xFF, 0x00, 0x50, 0x00), outlineSymbol); // Create a new point collection for polygon Esri.ArcGISRuntime.Geometry.PointCollection points = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84) { // Create and add points to the point collection new MapPoint(-2.6425, 56.0784), new MapPoint(-2.6430, 56.0763), new MapPoint(-2.6410, 56.0759), new MapPoint(-2.6380, 56.0765), new MapPoint(-2.6380, 56.0784), new MapPoint(-2.6410, 56.0786) }; // Create the polyline from the point collection Polygon polygon = new Polygon(points); // Create the graphic with polyline and symbol Graphic graphic = new Graphic(polygon, fillSymbol); // Add graphic to the graphics overlay _overlay.Graphics.Add(graphic); } private void CreateText() { // Create two text symbols TextSymbol bassRockTextSymbol = new TextSymbol("Black Rock", Color.Blue, 10, Esri.ArcGISRuntime.Symbology.HorizontalAlignment.Left, Esri.ArcGISRuntime.Symbology.VerticalAlignment.Bottom); TextSymbol craigleithTextSymbol = new TextSymbol("Craigleith", Color.Blue, 10, Esri.ArcGISRuntime.Symbology.HorizontalAlignment.Right, Esri.ArcGISRuntime.Symbology.VerticalAlignment.Top); // Create two points MapPoint bassPoint = new MapPoint(-2.64, 56.079, SpatialReferences.Wgs84); MapPoint craigleithPoint = new MapPoint(-2.72, 56.076, SpatialReferences.Wgs84); // Create two graphics from the points and symbols Graphic bassRockGraphic = new Graphic(bassPoint, bassRockTextSymbol); Graphic craigleithGraphic = new Graphic(craigleithPoint, craigleithTextSymbol); // Add graphics to the graphics overlay _overlay.Graphics.Add(bassRockGraphic); _overlay.Graphics.Add(craigleithGraphic); } private void SetExtent() { // Get all of the graphics contained in the graphics overlay GraphicCollection myGraphicCollection = _overlay.Graphics; // Create a new envelope builder using the same spatial reference as the graphics EnvelopeBuilder myEnvelopeBuilder = new EnvelopeBuilder(SpatialReferences.Wgs84); // Loop through each graphic in the graphic collection foreach (Graphic oneGraphic in myGraphicCollection) { // Union the extent of each graphic in the envelope builder myEnvelopeBuilder.UnionOf(oneGraphic.Geometry.Extent); } // Expand the envelope builder by 30% myEnvelopeBuilder.Expand(1.3); // Adjust the viewable area of the map to encompass all of the graphics in the // graphics overlay plus an extra 30% margin for better viewing MyMapView.SetViewpointAsync(new Viewpoint(myEnvelopeBuilder.Extent)); } } }
<UserControl x:Class="ArcGISRuntime.WPF.Samples.AddGraphicsWithSymbols.AddGraphicsWithSymbols" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <Grid> <esri:MapView x:Name="MyMapView"/> </Grid> </UserControl>
Hyperlink to Example | Description |
---|---|
AddGraphicsWithSymbols | Use a symbol style to display a graphic on a graphics overlay. |
BufferList | Generate multiple individual buffers or a single unioned buffer around multiple points. |
ChangeViewpoint | Set the map view to a new viewpoint. |
ConvexHullList | Generate convex hull polygon(s) from multiple input geometries. |
CreateFeatureCollectionLayer | Create a Feature Collection Layer from a Feature Collection Table, and add it to a map. |
CreateGeometries | Create simple geometry types. |
CutGeometry | Cut a geometry along a polyline. |
DisplayWfs | Display a layer from a WFS service, requesting only features for the current extent. |
FindPlace | Find places of interest near a location or within a specific area. |
FindServiceArea | Find the service area within a network from a given point. |
FindServiceAreasForMultipleFacilities | Find the service areas of several facilities from a feature service. |
IdentifyGraphics | Display an alert message when a graphic is clicked. |
NearestVertex | Find the closest vertex and coordinate of a geometry to a point. |
RouteAroundBarriers | Find a route that reaches all stops without crossing any barriers. |
SpatialOperations | Find the union, intersection, or difference of two geometries. |
SpatialRelationships | Determine spatial relationships between two geometries. |