Assembly: ESRI.ArcGISExplorer (in ESRI.ArcGISExplorer.dll) Version: 2.0.0.1500 (2.0.0.1500)
Syntax
C# |
---|
public sealed class Polygon : Geometry, IXmlSerializable |
Visual Basic (Declaration) |
---|
Public NotInheritable Class Polygon _ Inherits Geometry _ Implements IXmlSerializable |
Remarks
Polygon geometries represent area shapes, and can be used to represent geographical features such as countries, lakes, or land parcels. Polygons may be found as the Geometry in a spatially-enabled Table, or as the Geometry of a Graphic.
A Polygon geometry comprises multiple Point objects; Point objects are used to build up or change a Polygon geometry (for example by using the AddPoint, InsertPoint, RemovePointAt, or SetPoint methods), or to retrieve information about the Polygon (GetPoint). See the example code below for an example of creating a new Polygon and defining its vertices using the AddPoint method.
Polygons may be made up of multiple sections called rings which define holes or multiple different areas of the polygon shape. A Polygon with multiple paths is known as a multipart shape. Overloaded methods are available to work specifically with multipart polygons (for example AddPoint(Int32, Point), InsertPoint(Int32, Int32, Point), RemovePointAt(Int32, Int32), SetPoint(Int32, Int32, Point), and GetPoint(Int32, Int32)). The points of a Polygon are retrieved and set by value; therefore new points are always copied in to the Polygon, not added directly.
If building up a by specifying individual vertices, bear in mind the following:
- The last vertex in every ring of a Polygon should be the same as the first vertex in the same ring; this ensures that every ring is a closed shape. Use the Close()()() method to ensure each ring of a Polygon is closed.
- Each ring in a Polygon should not self-intersect; if a ring self-intersects it can be defined instead as two separate rings.
- The vertices in each ring which defines an outer boundary of Polygon should traverse the ring in a clockwise direction. If the ring defines an inner boundary of the Polygon (a hole), the vertices should traverse the ring in a counter-clockwise direction.
These rules of geometrical correctness can be applied by using the GeometryOperations.Simplify method.
Examples
// Create a new Polygon, allowing the default CoordinateSystem of WGS84. Polygon poly = new Polygon(); // Add a series of points to the Polygon (overloads are available to add multiple Points. poly.AddPoint(new ESRI.ArcGISExplorer.Geometry.Point(2.33434596343321, 48.8628885302916)); poly.AddPoint(new ESRI.ArcGISExplorer.Geometry.Point(2.33269733037166, 48.8603451299656)); poly.AddPoint(new ESRI.ArcGISExplorer.Geometry.Point(2.33659764618658, 48.8594678571346)); poly.AddPoint(new ESRI.ArcGISExplorer.Geometry.Point(2.33960511237599, 48.8591968205275)); poly.AddPoint(new ESRI.ArcGISExplorer.Geometry.Point(2.340578062027, 48.8608773611669)); // Ensure the Polygon is a closed shape. poly.Close(); // Create a Note using the polygon shape. Note louvre = new Note("The Louvre", poly, Symbol.Fill.SolidOutline.Green); // Populate the Note popup information using information about the Polygon. StringBuilder info = new StringBuilder(@"<p><a href=""http://www.louvre.fr"">The Louvre, Paris</a></p>"); for (int i = 0; i < poly.PointCount(); i++) { ESRI.ArcGISExplorer.Geometry.Point pt = poly.GetPoint(i); info.AppendLine(@"<p>" + i.ToString() + ": " + pt.ToString() + @"</p>"); } MapDisplay disp = ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay; louvre.Popup.Content = info.ToString(); // Add the Note to the current Map. disp.Map.ChildItems.Add(louvre);
' Create a new Polygon, allowing the default CoordinateSystem of WGS84. Dim poly As Polygon = New Polygon() ' Add a series of points to the Polygon (overloads are available to add multiple Points. poly.AddPoint(New ESRI.ArcGISExplorer.Geometry.Point(2.33434596343321, 48.8628885302916)) poly.AddPoint(New ESRI.ArcGISExplorer.Geometry.Point(2.33269733037166, 48.8603451299656)) poly.AddPoint(New ESRI.ArcGISExplorer.Geometry.Point(2.33659764618658, 48.8594678571346)) poly.AddPoint(New ESRI.ArcGISExplorer.Geometry.Point(2.33960511237599, 48.8591968205275)) poly.AddPoint(New ESRI.ArcGISExplorer.Geometry.Point(2.340578062027, 48.8608773611669)) ' Ensure the Polygon is a closed shape. poly.Close() ' Create a Note using the polygon shape. Dim louvre As Note = New Note("The Louvre", poly, Symbol.Fill.SolidOutline.Green) ' Populate the Note popup information using information about the Polygon. Dim info As StringBuilder = New StringBuilder("<p><a href=""http://www.louvre.fr"">The Louvre, Paris</a></p>") For i As Integer = 0 To poly.PointCount() - 1 Dim pt As ESRI.ArcGISExplorer.Geometry.Point = poly.GetPoint(i) info.AppendLine("<p>" & i.ToString() & ": " & pt.ToString() & "</p>") Next Dim disp As MapDisplay = ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay louvre.Popup.Content = info.ToString() ' Add the Note to the current Map. disp.Map.ChildItems.Add(louvre)
Inheritance Hierarchy
ESRI.ArcGISExplorer.Geometry..::.Geometry
ESRI.ArcGISExplorer.Geometry..::.Polygon