<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Faster way to programmatically add points to a new layer ? in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1121587#M7400</link>
    <description>&lt;P&gt;Q1: Is there a faster mechanism to create a point layer in ArcGis Pro from a custom formatted data file in a .net add-in?&lt;/P&gt;&lt;P&gt;Currently :&lt;BR /&gt;I am loading data point programmatically from a custom file format, firstly into a data structure,&lt;BR /&gt;I create a FeatureLayer in CurrentProject.DefaultGeodatabasePath [which seems to add to current map automatically]&lt;BR /&gt;I then iterate the points data, creating with MapPointBuilder.CreateMapPoint() and adding with an EditOperation, and then commit using createOperation.ExecuteAsync()&lt;BR /&gt;Then apply a renderer&lt;/P&gt;&lt;P&gt;All good, BUT the commit operation is very slow : eg 10k points takes 20-30 secs, &lt;STRONG&gt;100k points takes 3-5 minutes&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Q2 : Often this is an ephemeral/temp display layer - do i still need to create in the geoDB, or can i create in some faster, memory-only, map-only mechanism ?&lt;BR /&gt;For reference on the same machine , our stats package would load and display 100k points on a map in 6-7 secs, QGIS plugin using the same mechanism would load &amp;amp; display 10k points in under 2 secs and the 100k points file in 10-11 secs&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Abbreviated Code :&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;FeatureLayer pointFeatureLayer = [... create empty Feature layer using : Geoprocessing.ExecuteToolAsync("CreateFeatureclass_management",...]

AddFields(); // using Geoprocessing.ExecuteToolAsync("management.AddFields",.....

// add points &amp;amp; attributes :

var createOperation = new EditOperation();
createOperation.SelectNewFeatures = false;

[foreach source point record ]
{
  featureAttribs = [..get point attribute values..]

  // create the geometry &amp;amp; add the attribute values
  MapPoint newMapPoint = null;

  Coordinate3D newCoordinate = new Coordinate3D(x, y, z);
  newMapPoint = MapPointBuilder.CreateMapPoint(newCoordinate, sref);

  // add the geometry as an attribute
  featureAttribs.Add("Shape", newMapPoint);

  // queue feature creation
  createOperation.Create(pointFeatureLayer, featureAttribs);
}

// then commit :

Task&amp;lt;bool&amp;gt; res = createOperation.ExecuteAsync();

[ create and apply CIMUniqueValueRenderer ]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Dec 2021 05:50:09 GMT</pubDate>
    <dc:creator>jackpearson1</dc:creator>
    <dc:date>2021-12-01T05:50:09Z</dc:date>
    <item>
      <title>Faster way to programmatically add points to a new layer ?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1121587#M7400</link>
      <description>&lt;P&gt;Q1: Is there a faster mechanism to create a point layer in ArcGis Pro from a custom formatted data file in a .net add-in?&lt;/P&gt;&lt;P&gt;Currently :&lt;BR /&gt;I am loading data point programmatically from a custom file format, firstly into a data structure,&lt;BR /&gt;I create a FeatureLayer in CurrentProject.DefaultGeodatabasePath [which seems to add to current map automatically]&lt;BR /&gt;I then iterate the points data, creating with MapPointBuilder.CreateMapPoint() and adding with an EditOperation, and then commit using createOperation.ExecuteAsync()&lt;BR /&gt;Then apply a renderer&lt;/P&gt;&lt;P&gt;All good, BUT the commit operation is very slow : eg 10k points takes 20-30 secs, &lt;STRONG&gt;100k points takes 3-5 minutes&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Q2 : Often this is an ephemeral/temp display layer - do i still need to create in the geoDB, or can i create in some faster, memory-only, map-only mechanism ?&lt;BR /&gt;For reference on the same machine , our stats package would load and display 100k points on a map in 6-7 secs, QGIS plugin using the same mechanism would load &amp;amp; display 10k points in under 2 secs and the 100k points file in 10-11 secs&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Abbreviated Code :&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;FeatureLayer pointFeatureLayer = [... create empty Feature layer using : Geoprocessing.ExecuteToolAsync("CreateFeatureclass_management",...]

AddFields(); // using Geoprocessing.ExecuteToolAsync("management.AddFields",.....

// add points &amp;amp; attributes :

var createOperation = new EditOperation();
createOperation.SelectNewFeatures = false;

[foreach source point record ]
{
  featureAttribs = [..get point attribute values..]

  // create the geometry &amp;amp; add the attribute values
  MapPoint newMapPoint = null;

  Coordinate3D newCoordinate = new Coordinate3D(x, y, z);
  newMapPoint = MapPointBuilder.CreateMapPoint(newCoordinate, sref);

  // add the geometry as an attribute
  featureAttribs.Add("Shape", newMapPoint);

  // queue feature creation
  createOperation.Create(pointFeatureLayer, featureAttribs);
}

// then commit :

Task&amp;lt;bool&amp;gt; res = createOperation.ExecuteAsync();

[ create and apply CIMUniqueValueRenderer ]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Dec 2021 05:50:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1121587#M7400</guid>
      <dc:creator>jackpearson1</dc:creator>
      <dc:date>2021-12-01T05:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Faster way to programmatically add points to a new layer ?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1121701#M7404</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;The faster way is to create shapefile and write to it without EditOperation.&lt;/P&gt;&lt;P&gt;It could be done using&amp;nbsp;CreateRowBuffer from FeatureClass. More info here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-Geodatabase" target="_self"&gt;https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-Geodatabase&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Dec 2021 15:09:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1121701#M7404</guid>
      <dc:creator>GKmieliauskas</dc:creator>
      <dc:date>2021-12-01T15:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Faster way to programmatically add points to a new layer ?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1121752#M7405</link>
      <description>&lt;P&gt;If this custom file format is something you use frequently, you might want to consider writing a PlugIn datasource (&lt;A href="https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Plugin-Datasources" target="_self"&gt;Conceptual Doc&lt;/A&gt;, &lt;A href="https://github.com/esri/arcgis-pro-sdk/wiki/ProGuide-Plugin-Datasources" target="_self"&gt;Guide&lt;/A&gt;). This would allow you to read and display the data in the map without needing to copy it into another format.&lt;/P&gt;&lt;P&gt;If you want to stick with the current copying idea, shapefiles are good, but an in-memory database is probably better. &amp;nbsp;Instructions for creating an in-memory database are &lt;A href="https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-DDL#memory-geodatabases" target="_self"&gt;here&lt;/A&gt;. Once the database is created, you can &lt;A href="https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-DDL#tables-and-feature-classes" target="_self"&gt;create a feature class&lt;/A&gt;, and then copy data into it. If you go the route of using an in-memory database, keep in mind that they are destroyed when closing ArcGIS Pro. So if you create a layer from an in-memory database, that layer will come in broken if you save it in a map and restart Pro.&lt;/P&gt;&lt;P&gt;I hope this helps,&lt;/P&gt;&lt;P&gt;--Rich&lt;/P&gt;</description>
      <pubDate>Wed, 01 Dec 2021 17:10:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1121752#M7405</guid>
      <dc:creator>RichRuh</dc:creator>
      <dc:date>2021-12-01T17:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: Faster way to programmatically add points to a new layer ?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1123709#M7442</link>
      <description>&lt;P&gt;Thanks for those suggestions - shapefiles i think have some limitations, will look at in-mem database : It is not clear to me from documentation whether i can use existing geoprocessing-style code with an in-mem geodB, or whether i need to move all code over to the DDL API ?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2021 09:02:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1123709#M7442</guid>
      <dc:creator>jackpearson1</dc:creator>
      <dc:date>2021-12-08T09:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: Faster way to programmatically add points to a new layer ?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1123879#M7445</link>
      <description>&lt;P&gt;Jack,&lt;/P&gt;&lt;P&gt;If you just want to stick with&amp;nbsp;geoprocessing, here is &lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/analysis/geoprocessing/basics/the-in-memory-workspace.htm" target="_self"&gt;a link&lt;/A&gt; for using&amp;nbsp;geoprocessing with in-memory&amp;nbsp;geodatabases (you don't even have to create it first).&lt;/P&gt;&lt;P&gt;--Rich&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2021 16:40:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1123879#M7445</guid>
      <dc:creator>RichRuh</dc:creator>
      <dc:date>2021-12-08T16:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: Faster way to programmatically add points to a new layer ?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1124154#M7448</link>
      <description>&lt;P&gt;Thanks Rich - are you aware of any c# examples ? i am struggling to get geoprocessing to work with memory geodb.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 04:17:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1124154#M7448</guid>
      <dc:creator>jackpearson1</dc:creator>
      <dc:date>2021-12-09T04:17:58Z</dc:date>
    </item>
    <item>
      <title>Re: Faster way to programmatically add points to a new layer ?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1124657#M7464</link>
      <description>&lt;P&gt;Jack,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would you mind posting some code snippets so that we can see what (if anything) you are doing wrong?&lt;/P&gt;&lt;P&gt;--Rich&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 22:45:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1124657#M7464</guid>
      <dc:creator>RichRuh</dc:creator>
      <dc:date>2021-12-09T22:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: Faster way to programmatically add points to a new layer ?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1124827#M7465</link>
      <description>&lt;P&gt;I have got this working today actually. Using&amp;nbsp; memory gdb has approximately doubled the performance, which is certainly an improvement. I'll post my working test harness code for reference, but would love to know if you can see how to improve significantly ?&lt;BR /&gt;For example the geoprocessing call to create the empty featureclass seems to be taking longer than QGIS takes to create and display a 100k points layer - surely I am doing something wrong here?&lt;BR /&gt;Also - I would be interested to see what the best practice equivalent would look like in the DDL API ?&lt;BR /&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 13:32:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1124827#M7465</guid>
      <dc:creator>jackpearson1</dc:creator>
      <dc:date>2021-12-10T13:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: Faster way to programmatically add points to a new layer ?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1124828#M7466</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// Works :
        protected async Task MemDB_Geoprocessing()
        {
            string gdbPath = "memory";
            //string gdbPath = CoreModule.CurrentProject.DefaultGeodatabasePath;

            string featureclassName = "testFC";
            string featureclassType = "POINT";
            int spatialRefID = 20351; //Z51
            var activeMap = MapView.Active.Map;

            // 1) Create the Feature class table - use GP tools
            var sr = SpatialReferenceBuilder.CreateSpatialReference(spatialRefID); 
            List&amp;lt;object&amp;gt; geoProcessingArgs = new List&amp;lt;object&amp;gt; { gdbPath, featureclassName, featureclassType, "", "DISABLED", "DISABLED", sr };

            GPExecuteToolFlags flags = GPExecuteToolFlags.None | GPExecuteToolFlags.AddOutputsToMap;  
            IGPResult result = null;
            var t = Task.Run(async () =&amp;gt;
            {
                result = await Geoprocessing.ExecuteToolAsync("CreateFeatureclass_management", Geoprocessing.MakeValueArray(geoProcessingArgs.ToArray()), null, null, null, flags);
            });
            await (t);


            // 2) Set up attribute structure 
            int numFields = 64 / 2; // 64 fields, 1 each of type text, numeric

            var fields = new Dictionary&amp;lt;string, string&amp;gt;();
            for (int fldCnt = 0; fldCnt &amp;lt; numFields; fldCnt++)
            {
                fields.Add($"Field{fldCnt}", $"Text # 255 myDefaultValue"); 
                fields.Add($"Field{fldCnt}_num", $"DOUBLE # # #");
            }

            AddFields(gdbPath + @"\" + featureclassName, fields);


            // 3) Add some test point features to the Feature layer
            var pointFeatureLayer = activeMap.FindLayers(featureclassName)[0] as FeatureLayer;
            var featureAttribs = new Dictionary&amp;lt;string, object&amp;gt;(); 
            Random rnd = new Random();

            var createOp = new EditOperation() { Name = "Generate points", SelectNewFeatures = false };
            long pointCnt = 0;
            for (pointCnt = 0; pointCnt &amp;lt; 50*1000; pointCnt++) // for each new point feature
            {
                featureAttribs.Clear();

                // geometry - random-ish coords
                Coordinate2D newCoordinate = new Coordinate2D(320000 + rnd.Next(-1000, 1000), 7140000 + rnd.Next(-1000, 1000)); 
                featureAttribs.Add("Shape", MapPointBuilder.CreateMapPoint(newCoordinate));

                // attribute values
                for (int fldCnt = 0; fldCnt &amp;lt; numFields; fldCnt++)
                {
                    featureAttribs.Add($"Field{fldCnt}", $"SomeText{fldCnt}");
                    featureAttribs.Add($"Field{fldCnt}_num", fldCnt);
                }

                createOp.Create(pointFeatureLayer, featureAttribs); // queue feature creation

            }

            // commit features
            Task&amp;lt;bool&amp;gt; tRes = createOp.ExecuteAsync(); // execute the batch edit operation
            await (tRes);

            if (!tRes.Result) throw new Exception(createOp.ErrorMessage);


            Task tse = Task.Run(async () =&amp;gt; { await Project.Current.SaveEditsAsync(); });
            await(tse);

            Task tz = Task.Run(async () =&amp;gt; {
                await MapView.Active.ZoomToAsync(pointFeatureLayer, false);  
            });
            await(tz);
        }

        private void AddFields(string tableNamePath, Dictionary&amp;lt;string, string&amp;gt; fields)
        {
            string fieldNames = "";
            List&amp;lt;object&amp;gt; geoProcessingArgs = null;
            foreach (KeyValuePair&amp;lt;string, string&amp;gt; item in fields)
            {
                fieldNames = String.Format("{0}{1} {2}; ", fieldNames, item.Key, item.Value);
            }

            geoProcessingArgs = new List&amp;lt;object&amp;gt;{tableNamePath,fieldNames};

            var t = Task.Run(async () =&amp;gt;
            {
                var result = Geoprocessing.ExecuteToolAsync("management.AddFields", Geoprocessing.MakeValueArray(geoProcessingArgs.ToArray()));
            });
            t.Wait();
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 13:27:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1124828#M7466</guid>
      <dc:creator>jackpearson1</dc:creator>
      <dc:date>2021-12-10T13:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: Faster way to programmatically add points to a new layer ?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1124833#M7467</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;The faster way is not using EditOperation as I wrote in my first post and use in_memory featureclass instead of shapefile,&lt;/P&gt;&lt;P&gt;Another alternative is to use&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-pro-sdk-questions/bulk-load-geodatabase-table-pro-core-sdk/m-p/711327#M28" target="_self"&gt;InsertCursor&lt;/A&gt;&amp;nbsp;.&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/114916"&gt;@RichRuh&lt;/a&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;&amp;nbsp;knows more about results as he commented that post.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 13:42:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1124833#M7467</guid>
      <dc:creator>GKmieliauskas</dc:creator>
      <dc:date>2021-12-10T13:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: Faster way to programmatically add points to a new layer ?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1125498#M7480</link>
      <description>&lt;P&gt;I think the single biggest thing you could do is use the Pro SDK to create your feature class. &amp;nbsp;There is a snippet showing how to do this &lt;A href="https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-Geodatabase#creating-a-feature-class" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;You will need to create a feature layer for this feature class after filling it. &amp;nbsp;Assuming you don't need to have undo/redo work with this data, then I would forego the EditOperation as&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/42133"&gt;@GKmieliauskas&lt;/a&gt;&amp;nbsp;suggests. The order would be:&lt;/P&gt;&lt;P&gt;1. Create the feature class in the in-memory&amp;nbsp;geodatabase&lt;BR /&gt;2. Fill it in with InsertCursor&lt;BR /&gt;3. Create a feature layer and add it to the map&lt;/P&gt;&lt;P&gt;I hope this helps,&lt;/P&gt;&lt;P&gt;--Rich&lt;/P&gt;</description>
      <pubDate>Mon, 13 Dec 2021 18:12:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1125498#M7480</guid>
      <dc:creator>RichRuh</dc:creator>
      <dc:date>2021-12-13T18:12:58Z</dc:date>
    </item>
    <item>
      <title>Re: Faster way to programmatically add points to a new layer ?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1127980#M7517</link>
      <description>&lt;P&gt;Thanks all - i have achieved a fair performance improvement using a combination of memory geodatabase + DDL API + insert cursor.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 13:41:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/faster-way-to-programmatically-add-points-to-a-new/m-p/1127980#M7517</guid>
      <dc:creator>jackpearson1</dc:creator>
      <dc:date>2021-12-21T13:41:04Z</dc:date>
    </item>
  </channel>
</rss>

