Click or drag to resize

Polyline Class

A multipart linear shape.
Inheritance Hierarchy

Namespace:  Esri.ArcGISRuntime.Geometry
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.11.0
public class Polyline : Multipart

The Polyline type exposes the following members.

Public methodCode examplePolyline(IEnumerableMapPoint)
Initializes a new instance of the Polyline class.
Public methodPolyline(IEnumerableIEnumerableMapPoint)
Initializes a new instance of the Polyline class.
Public methodPolyline(IEnumerableSegment)
Initializes a new instance of the Polyline class.
Public methodPolyline(IEnumerableIEnumerableSegment)
Initializes a new instance of the Polyline class.
Public methodPolyline(IEnumerableMapPoint, SpatialReference)
Initializes a new instance of the Polyline class.
Public methodPolyline(IEnumerableIEnumerableMapPoint, SpatialReference)
Initializes a new instance of the Polyline class.
Public methodPolyline(IEnumerableSegment, SpatialReference)
Initializes a new instance of the Polyline class.
Public methodPolyline(IEnumerableIEnumerableSegment, SpatialReference)
Initializes a new instance of the Polyline class.
Public propertyDimension
Gets the number of dimensions for the geometry.
(Overrides GeometryDimension.)
Public propertyExtent
Gets the minimum enclosing Envelope of the instance
(Inherited from Multipart.)
Public propertyGeometryType
Gets the geometry type.
(Overrides GeometryGeometryType.)
Public propertyHasCurves
Gets a value indicating whether the geometry has any curves.
(Inherited from Geometry.)
Public propertyHasM
Gets a value indicating if the geometry has M
(Inherited from Multipart.)
Public propertyHasZ
Gets a value indicating if the geometry has Z.
(Inherited from Multipart.)
Public propertyIsEmpty
Gets a value indicating whether or not the geometry is empty.
(Inherited from Multipart.)
Public propertyCode exampleParts
Gets the parts in the geometry
(Inherited from Multipart.)
Public propertyCode exampleSpatialReference
Gets the spatial reference of this geometry.
(Inherited from Geometry.)
Public methodEquals
Checks if two geometries are approximately same, within some tolerance.
(Inherited from Geometry.)
Public methodIsEqual
Compares two Polyline 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).)
Public methodToJson
Converts this geometry into an ArcGIS JSON representation.
(Inherited from Geometry.)
Public methodToString
Returns a String that represents the current Object.
(Overrides ObjectToString.)

Polyline geometries represent the shape and location of linear features such as a street in a road network, a contour line representing an elevation value, or a hiking trail. They can be used to define geometry for features and graphics, or as input or output for tasks or geoprocessing operations, such as the output of a network trace.

A polyline is composed of a series of connected segments, where each segment defines a continuous line between a start and an end map point. You can define a new polyline from a collection of MapPoint's to create a series of straight LineSegment connecting the map points you specified. You can use PolylineBuilder to build a polyline one map point at a time or to modify an existing polyline.

Additionally, polyline can have multiple parts. Each part is a series of connected segments, but the parts can be disjoint. For example, a polyline representing a street that ends and then starts again a block later. Parts can also intersect at one or more vertices. For example, in a polyline representing a river and its tributaries. The polyline class inherits from Multipart, which provides members for iterating the segments and map points of each part in a polyline.

Polylines are based upon the parent Geometry Class. The Geometry Class is immutable which means that you can not change its shape once it is created. If you need to modify a polyline once it has been created, use the PolylineBuilder Class instead. The ToGeometry Method will provide you with the polyline object.



Example Name: ClosestFacility

Find a route to the closest facility from a location.

Code example screen shot.

// 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:
// 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.Tasks.NetworkAnalysis;
using Esri.ArcGISRuntime.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows;

namespace ArcGISRuntime.WPF.Samples.ClosestFacility
        name: "Find closest facility to an incident (interactive)",
        category: "Network analysis",
        description: "Find a route to the closest facility from a location.",
        instructions: "Click near any of the hospitals and a route will be displayed from that clicked location to the nearest hospital.",
        tags: new[] { "incident", "network analysis", "route", "search" })]
    public partial class ClosestFacility
        // Holds locations of hospitals around San Diego.
        private List<Facility> _facilities;

        // Graphics overlays for facilities and incidents.
        private GraphicsOverlay _facilityGraphicsOverlay;

        // Symbol for facilities.
        private PictureMarkerSymbol _facilitySymbol;

        // Overlay for the incident.
        private GraphicsOverlay _incidentGraphicsOverlay;

        // Black cross where user clicked.
        private MapPoint _incidentPoint;

        // Symbol for the incident.
        private SimpleMarkerSymbol _incidentSymbol;

        // Used to display route between incident and facility to mapview.
        private SimpleLineSymbol _routeSymbol;

        // Solves task to find closest route between an incident and a facility.
        private ClosestFacilityTask _task;

        public ClosestFacility()

            // Create the map and graphics overlays.

        private async void Initialize()
            // Hook up the DrawStatusChanged event.
            MyMapView.DrawStatusChanged += OnDrawStatusChanged;

            // Construct the map and set the MapView.Map property.
            Map map = new Map(BasemapStyle.ArcGISLightGray);
            MyMapView.Map = map;

                // Create a ClosestFacilityTask using the San Diego Uri.
                _task = await ClosestFacilityTask.CreateAsync(new Uri(""));

                // List of facilities to be placed around San Diego area.
                _facilities = new List<Facility> {
                    new Facility(new MapPoint(-1.3042129900625112E7, 3860127.9479775648, SpatialReferences.WebMercator)),
                    new Facility(new MapPoint(-1.3042193400557665E7, 3862448.873041752, SpatialReferences.WebMercator)),
                    new Facility(new MapPoint(-1.3046882875518233E7, 3862704.9896770366, SpatialReferences.WebMercator)),
                    new Facility(new MapPoint(-1.3040539754780494E7, 3862924.5938606677, SpatialReferences.WebMercator)),
                    new Facility(new MapPoint(-1.3042571225655518E7, 3858981.773018156, SpatialReferences.WebMercator)),
                    new Facility(new MapPoint(-1.3039784633928463E7, 3856692.5980474586, SpatialReferences.WebMercator)),
                    new Facility(new MapPoint(-1.3049023883956768E7, 3861993.789732541, SpatialReferences.WebMercator))

                // Center the map on the San Diego facilities.
                Envelope fullExtent = GeometryEngine.CombineExtents(_facilities.Select(facility => facility.Geometry));
                await MyMapView.SetViewpointGeometryAsync(fullExtent, 50);

                // Create a symbol for displaying facilities.
                _facilitySymbol = new PictureMarkerSymbol(new Uri(""))
                    Height = 30,
                    Width = 30

                // Incident symbol.
                _incidentSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, Color.FromArgb(255, 0, 0, 0), 30);

                // Route to hospital symbol.
                _routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.FromArgb(255, 0, 0, 255), 5.0f);

                // Create Graphics Overlays for incidents and facilities.
                _incidentGraphicsOverlay = new GraphicsOverlay();
                _facilityGraphicsOverlay = new GraphicsOverlay();

                // Create a graphic and add to graphics overlay for each facility.
                foreach (Facility facility in _facilities)
                    _facilityGraphicsOverlay.Graphics.Add(new Graphic(facility.Geometry, _facilitySymbol));

                // Add each graphics overlay to MyMapView.
            catch (Exception e)
                MessageBox.Show(e.ToString(), "Error");

        private void OnDrawStatusChanged(object sender, DrawStatusChangedEventArgs e)
            if (e.Status == DrawStatus.Completed)
                // Link the action of tapping on the map with the MyMapView_GeoViewTapped method.
                MyMapView.GeoViewTapped += MyMapView_GeoViewTapped;

                // Remove this method from DrawStatusChanged events.
                MyMapView.DrawStatusChanged -= OnDrawStatusChanged;

        private void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e)
            // Clear any prior incident and routes from the graphics.

            // Get the tapped point.
            _incidentPoint = e.Location;

            // Populate the facility parameters than solve using the task.

        private async void PopulateParametersAndSolveRouteAsync()
                // Set facilities and incident in parameters.
                ClosestFacilityParameters closestFacilityParameters = await _task.CreateDefaultParametersAsync();
                closestFacilityParameters.SetIncidents(new List<Incident> { new Incident(_incidentPoint) });

                // Use the task to solve for the closest facility.
                ClosestFacilityResult result = await _task.SolveClosestFacilityAsync(closestFacilityParameters);

                // Get the index of the closest facility to incident. (0) is the index of the incident, [0] is the index of the closest facility.
                int closestFacility = result.GetRankedFacilityIndexes(0)[0];

                // Get route from closest facility to the incident and display to mapview.
                ClosestFacilityRoute route = result.GetRoute(closestFacility, 0);

                // Add graphics for the incident and route.
                _incidentGraphicsOverlay.Graphics.Add(new Graphic(_incidentPoint, _incidentSymbol));
                _incidentGraphicsOverlay.Graphics.Add(new Graphic(route.RouteGeometry, _routeSymbol));
            catch (Esri.ArcGISRuntime.Http.ArcGISWebException exception)
                if (exception.Message.Equals("Unable to complete operation."))
                    System.Windows.MessageBox.Show("Incident not within San Diego area!", "Sample error");
                    System.Windows.MessageBox.Show("An ArcGIS web exception occurred. \n" + exception.Message.ToString(), "Sample error");
<UserControl x:Class="ArcGISRuntime.WPF.Samples.ClosestFacility.ClosestFacility"
        <esri:MapView x:Name="MyMapView" />
        <Border Style="{StaticResource BorderStyle}">
            <TextBlock Text="Tap to find the route to the closest facility." 
                       TextAlignment="Center" FontWeight="SemiBold" />
See Also
Additional Examples
Hyperlink to ExampleDescription
AddGraphicsWithSymbolsUse a symbol style to display a graphic on a graphics overlay.
Animate3DGraphicAn `OrbitGeoElementCameraController` follows a graphic while the graphic's position and rotation are animated.
ClosestFacilityFind a route to the closest facility from a location.
ClosestFacilityStaticFind routes from several locations to the respective closest facility.
CreateFeatureCollectionLayerCreate a Feature Collection Layer from a Feature Collection Table, and add it to a map.
CreateGeometriesCreate simple geometry types.
CutGeometryCut a geometry along a polyline.
DensifyAndGeneralizeA multipart geometry can be densified by adding interpolated points at regular intervals. Generalizing multipart geometry simplifies it while preserving its general shape. Densifying a multipart geometry adds more vertices at regular intervals.
EditFeatureLinkedAnnotationEdit feature attributes which are linked to annotation through an expression.
FindRouteDisplay directions for a route between two points.
FindServiceAreaFind the service area within a network from a given point.
GeodesicOperationsCalculate a geodesic path between two points and measure its distance.
MobileMapSearchAndRouteDisplay maps and use locators to enable search and routing offline using a Mobile Map Package.
NavigateRouteUse a routing service to navigate between points.
NavigateRouteReroutingNavigate between two points and dynamically recalculate an alternate route when the original route is unavailable.
OfflineRoutingSolve a route on-the-fly using offline data.
RouteAroundBarriersFind a route that reaches all stops without crossing any barriers.
ShowLocationHistoryDisplay your location history on the map.
SpatialRelationshipsDetermine spatial relationships between two geometries.
TraceUtilityNetworkDiscover connected features in a utility network using connected, subnetwork, upstream, and downstream traces.