Create geometries

View inAndroidFormsUWPWPFWinUIiOSView on GitHub

Create simple geometry types.

Image of create geometries

Use case

Geometries are used to represent real world features as vector GIS data. Points are used to mark specific XY locations, such as landmarks and other points of interest. Polylines are made up of 2 or more XY vertices and can be used to mark roads, flight paths, or boundaries. Polygons are made up of 3 or more XY vertices and can be used to represent a lake, country, or a park. Geometries can be stored as features in a database, displayed as Graphics in a map, or used for performing spatial analysis with GeometryEngine or a GeoprocessingTask.

How to use the sample

Pan and zoom freely to see the different types of geometries placed onto the map.

How it works

  1. Use the constructors for the various simple Geometry types including Point, Polyline, Multipoint, Polygon, and Envelope.
  2. To display the geometry, create a Graphic passing in the geometry, and a Symbol appropriate for the geometry type.
  3. Add the graphic to a graphics overlay and add the overlay to a map view.

Relevant API

  • Envelope
  • Multipoint
  • Point
  • PointCollection
  • Polygon
  • Polyline

Additional information

A geometry made of multiple points usually takes a PointCollection as an argument or is created through a builder.

Tags

area, boundary, line, marker, path, shape

Sample Code

CreateGeometries.cs
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// 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 Esri.ArcGISRuntime.UI.Controls;
using Foundation;
using UIKit;

namespace ArcGISRuntime.Samples.CreateGeometries
{
    [Register("CreateGeometries")]
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        name: "Create geometries",
        category: "Geometry",
        description: "Create simple geometry types.",
        instructions: "Pan and zoom freely to see the different types of geometries placed onto the map.",
        tags: new[] { "area", "boundary", "line", "marker", "path", "shape" })]
    public class CreateGeometries : UIViewController
    {
        // Hold references to UI controls.
        private MapView _myMapView;

        public CreateGeometries()
        {
            Title = "Create geometries";
        }

        private void Initialize()
        {
            // Create and show a map with a topographic basemap.
            _myMapView.Map = new Map(BasemapStyle.ArcGISTopographic);

            // Create a simple fill symbol - used to render a polygon covering Colorado.
            SimpleFillSymbol theSimpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Cross, System.Drawing.Color.Blue, null);

            // Create a simple line symbol - used to render a polyline border between California and Nevada.
            SimpleLineSymbol theSimpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Blue, 3);

            // Create a simple marker symbol - used to render multi-points for various state capital locations in the Western United States.
            SimpleMarkerSymbol theSimpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Triangle, System.Drawing.Color.Blue, 14);

            // Create a simple marker symbol - used to render a map point where the Esri headquarters is located.
            SimpleMarkerSymbol theSimpleMarkerSymbol2 = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Diamond, System.Drawing.Color.Red, 18);

            // Create a graphics overlay to hold the various graphics.
            GraphicsOverlay theGraphicsOverlays = new GraphicsOverlay();

            // Get the graphic collection from the graphics overlay.
            GraphicCollection theGraphicCollection = theGraphicsOverlays.Graphics;

            // Add a graphic to the graphic collection - polygon with a simple fill symbol.
            theGraphicCollection.Add(new Graphic(CreatePolygon(), theSimpleFillSymbol));

            // Add a graphic to the graphic collection - polyline with a simple line symbol.
            theGraphicCollection.Add(new Graphic(CreatePolyline(), theSimpleLineSymbol));

            // Add a graphic to the graphic collection - map point with a simple marker symbol.
            theGraphicCollection.Add(new Graphic(CreateMapPoint(), theSimpleMarkerSymbol2));

            // Add a graphic to the graphic collection - multi-point with a simple marker symbol.
            theGraphicCollection.Add(new Graphic(CreateMultipoint(), theSimpleMarkerSymbol));

            // Set the map views graphics overlay to the created graphics overlay.
            _myMapView.GraphicsOverlays.Add(theGraphicsOverlays);

            // Zoom to the extent of an envelope with some padding (10 pixels).
            _myMapView.SetViewpointGeometryAsync(CreateEnvelope(), 10);
        }

        private static Envelope CreateEnvelope() => new Envelope(-123.0, 33.5, -101.0, 48.0, SpatialReferences.Wgs84);

        private Polygon CreatePolygon()
        {
            // Create a point collection with coordinates that approximates the boundary of Colorado.
            PointCollection thePointCollection = new PointCollection(SpatialReferences.Wgs84)
            {
                {-109.048, 40.998},
                {-102.047, 40.998},
                {-102.037, 36.989},
                {-109.048, 36.998}
            };

            // Create and return a polygon from the point collection.
            return new Polygon(thePointCollection);
        }

        private Polyline CreatePolyline()
        {
            // Create a point collection with coordinates that approximates the border between California and Nevada.
            PointCollection thePointCollection = new PointCollection(SpatialReferences.Wgs84)
            {
                {-119.992, 41.989},
                {-119.994, 38.994},
                {-114.620, 35.0}
            };

            // Create and return a polyline from the point collection.
            return new Polyline(thePointCollection);
        }

        // Return a map point where the Esri headquarters is located.
        private MapPoint CreateMapPoint() => new MapPoint(-117.195800, 34.056295, SpatialReferences.Wgs84);

        private Multipoint CreateMultipoint()
        {
            // Create a point collection with coordinates representing various state capital locations in the Western United States.
            PointCollection thePointCollection = new PointCollection(SpatialReferences.Wgs84)
            {
                {-121.491014, 38.579065}, // - Sacramento, CA
                {-122.891366, 47.039231}, // - Olympia, WA
                {-123.043814, 44.93326}, // - Salem, OR
                {-119.766999, 39.164885} // - Carson City, NV
            };

            // Create and return a multi-point from the point collection.
            return new Multipoint(thePointCollection);
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            Initialize();
        }

        public override void LoadView()
        {
            // Create the views.
            View = new UIView() { BackgroundColor = ApplicationTheme.BackgroundColor };

            _myMapView = new MapView();
            _myMapView.TranslatesAutoresizingMaskIntoConstraints = false;

            // Add the views.
            View.AddSubviews(_myMapView);

            // Lay out the views.
            NSLayoutConstraint.ActivateConstraints(new[]
            {
                _myMapView.TopAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TopAnchor),
                _myMapView.BottomAnchor.ConstraintEqualTo(View.BottomAnchor),
                _myMapView.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor),
                _myMapView.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor)
            });
        }
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.