AnsweredAssumed Answered

Poor performance when creating polylines

Question asked by RehmSoftware on Jun 7, 2017
Latest reply on Jun 27, 2017 by RehmSoftware



I'm currently testing the performance of ArcGis Pro regarding how fast it is to create and draw polylines or polygons (the reason is that I'm comparing the performance to AutoCAD in order to find out whether we could port our software product to the ArcGis Pro platform).

I came up with a sample code that draws about 10.000 triangles on an existing feature layer. But I was rather underwhelmed by the performance as it took about 24 seconds on my machine (i7-3930k, 24GB RAM, nVidia GTX 650 Ti). The same task in AutoCAD only took 0.1 seconds...


But since I'm new to programming with ArcGis I might have made a stupid mistake that slows down my code a lot. So I'd be happy if someone with more knowledge could look over it and give me some hints whether I'm doing something wrong.


This is my code:


using System;

using System.Collections.Generic;

using System.Diagnostics;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using ArcGIS.Core.Data;

using ArcGIS.Core.Geometry;

using ArcGIS.Desktop.Core;

using ArcGIS.Desktop.Editing;

using ArcGIS.Desktop.Framework;

using ArcGIS.Desktop.Framework.Contracts;

using ArcGIS.Desktop.Framework.Dialogs;

using ArcGIS.Desktop.Framework.Threading.Tasks;

using ArcGIS.Desktop.Mapping;


namespace ProAppModule1 {

    internal class createPolylines : Button {

        protected override async void OnClick() {

            var sw = new Stopwatch();


            await this.DrawPolylines();


            MessageBox.Show(String.Format("Time elapsed: {0:t}", sw.Elapsed));



        private Task<bool> DrawPolylines() {

            var activeMapView = MapView.Active;

            var extent = activeMapView.Extent;


            //Draw about 10000 triangles. Use sqrt to have the same number of triangles in width and height even though we'll end up with more than 10000 triangles in the end

            int numTriangles = 10000;

            int rows, cols;

            rows = cols = (int)Math.Ceiling(Math.Sqrt(numTriangles));


            double triangleWidth = extent.Width / cols;

            double triangleHeight = extent.Height / rows;


            var polylineFeatureLayer = this.GetFeatureLayerByName(activeMapView.Map, "My_Polyline");

            return QueuedTask.Run(() => {

                var featureClass = polylineFeatureLayer.GetTable() as FeatureClass;

                var polylineDefinition = featureClass.GetDefinition() as FeatureClassDefinition;

                var spatialReference = polylineDefinition.GetSpatialReference();


                var createOperation = new EditOperation();

                createOperation.Name = "Draw Polylines";

                createOperation.SelectNewFeatures = false;


                var coordinates = new Coordinate[4];

                double x = extent.XMin;

                double y = extent.YMin;

                for (int i = 0; i < rows; ++i) {

                    for (int j = 0; j < cols; ++j) {

                        coordinates[0] = new Coordinate(x, y, 0.0);

                        coordinates[1] = new Coordinate(x + triangleWidth, y, 0.0);

                        coordinates[2] = new Coordinate(x + triangleWidth, y + triangleHeight, 0.0);

                        coordinates[3] = coordinates[0];


                        var polyline = PolylineBuilder.CreatePolyline(coordinates, spatialReference);

                        createOperation.Create(polylineFeatureLayer, polyline);

                        x += triangleWidth;



                    x = extent.XMin;

                    y += triangleHeight;



                return createOperation.ExecuteAsync();




        private FeatureLayer GetFeatureLayerByName(Map map, string layerName) {

            var featureLayers = map.GetLayersAsFlattenedList().OfType<FeatureLayer>();

            foreach (var layer in featureLayers) {

                if (layer.Name.Equals(layerName, StringComparison.CurrentCultureIgnoreCase))

                    return layer;



            return null;




Thanks in advance!