Faster way to programmatically add points to a new layer ?

1789
11
11-30-2021 09:50 PM
jackpearson1
New Contributor

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?

Currently :
I am loading data point programmatically from a custom file format, firstly into a data structure,
I create a FeatureLayer in CurrentProject.DefaultGeodatabasePath [which seems to add to current map automatically]
I then iterate the points data, creating with MapPointBuilder.CreateMapPoint() and adding with an EditOperation, and then commit using createOperation.ExecuteAsync()
Then apply a renderer

All good, BUT the commit operation is very slow : eg 10k points takes 20-30 secs, 100k points takes 3-5 minutes

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 ?
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 & display 10k points in under 2 secs and the 100k points file in 10-11 secs

 

Abbreviated Code :

FeatureLayer pointFeatureLayer = [... create empty Feature layer using : Geoprocessing.ExecuteToolAsync("CreateFeatureclass_management",...]

AddFields(); // using Geoprocessing.ExecuteToolAsync("management.AddFields",.....

// add points & attributes :

var createOperation = new EditOperation();
createOperation.SelectNewFeatures = false;

[foreach source point record ]
{
  featureAttribs = [..get point attribute values..]

  // create the geometry & 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<bool> res = createOperation.ExecuteAsync();

[ create and apply CIMUniqueValueRenderer ]

 

0 Kudos
11 Replies
RichRuh
Esri Regular Contributor

I think the single biggest thing you could do is use the Pro SDK to create your feature class.  There is a snippet showing how to do this here.

You will need to create a feature layer for this feature class after filling it.  Assuming you don't need to have undo/redo work with this data, then I would forego the EditOperation as @GKmieliauskas suggests. The order would be:

1. Create the feature class in the in-memory geodatabase
2. Fill it in with InsertCursor
3. Create a feature layer and add it to the map

I hope this helps,

--Rich

0 Kudos
jackpearson1
New Contributor

Thanks all - i have achieved a fair performance improvement using a combination of memory geodatabase + DDL API + insert cursor.

0 Kudos