Select to view content in your preferred language

Fastest way to obtain a single feature by ObjectID from FeatureClass

770
5
Jump to solution
02-25-2025 12:01 AM
RadekMandovec
Occasional Contributor

Hi,

there was a simple method IFeatureClass.GetFeature in ArcObjects. There is nothing like that in ArcGIS Pro SDK. What is the fastest way to get a feature from FeatureClass? Should I use inspector like this:

 var inspector = new Inspector();
 inspector.Load(featClass, objectId);

 or is there some other (maybe better) method how to retrieve a single feature and work with it?

0 Kudos
1 Solution

Accepted Solutions
CharlesMacleod
Esri Regular Contributor

The fastest way is via a recycling rowcursor with specific fields identified in the SubFields clause. Using the ObjectIDs property rather than a where clause is, imo, more convenient and may be marginally faster. Your mileage may vary. A non-recycling row cursor will, of course, be slower.

WRT Inspector - it is typically used with your UIs for purposes of editing - and comes with a built-in attribute grid [accessed via Inspector.CreateEmbeddableControl()] it populates for exactly that purpose. 

Data in the inspector is always read-write (unless restricted via a join or similar). Inspector will always automatically retrieve all attributes from a feature layer or feature class. Additionally, If loading data (from a feature layer) with joins, then all joined attribute values are loaded also. Inspector handles subtypes and domains and related default values.

You can find more info/details here: https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Editing 

View solution in original post

0 Kudos
5 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

Take a look to another thread.

0 Kudos
RadekMandovec
Occasional Contributor

Hi,

I have looked at the thread before, but loading each feature by inspector is very very slow. If I compare times when I use RowCursor versus Inspector there is a huge difference. If I take a feature class, which has 303 925 features, create a list of oids and then loop through the list - it takes 1 minute 20 seconds for RowCursor method, but it takes unbelievable 43 minutes 22 seconds for Inspector method!!! This is the reason, why I am asking for recommended way, which is not clearly to retrieve a feature by Inspector. I do not attach the sample data, becuse you can try on any feature class.

Here is code snipet for Inspector:

foreach (var oid in oidList)
{
    var inspector = new Inspector();
    inspector.Load(featureClass, oid);
}

and here for RowCursor:

 foreach (var oid in oidList)
 {
     var pQueryFilter = new QueryFilter { WhereClause = "OBJECTID" + " = " + oid };
     using (RowCursor rowCursor = featureClass.Search(pQueryFilter, false))
     {
         while (rowCursor.MoveNext())
         {
             using (Row row = rowCursor.Current)
             {
                 Feature feature = (Feature)row;
             }
         }
     }
 }

 

0 Kudos
GKmieliauskas
Esri Regular Contributor

@UmaHarano , @CharlesMacleod@Aashis can you help?

0 Kudos
CharlesMacleod
Esri Regular Contributor

The fastest way is via a recycling rowcursor with specific fields identified in the SubFields clause. Using the ObjectIDs property rather than a where clause is, imo, more convenient and may be marginally faster. Your mileage may vary. A non-recycling row cursor will, of course, be slower.

WRT Inspector - it is typically used with your UIs for purposes of editing - and comes with a built-in attribute grid [accessed via Inspector.CreateEmbeddableControl()] it populates for exactly that purpose. 

Data in the inspector is always read-write (unless restricted via a join or similar). Inspector will always automatically retrieve all attributes from a feature layer or feature class. Additionally, If loading data (from a feature layer) with joins, then all joined attribute values are loaded also. Inspector handles subtypes and domains and related default values.

You can find more info/details here: https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Editing 

0 Kudos
RadekMandovec
Occasional Contributor

Hi Charles, 

thank you very much for clarifying the problem!

Just to inform everybody - I tried all 3 approaches for abovementioned feature class  with following results:

  1. whereclause without subfield, nonrecycling cursor - 1min18sec
  2. whereclause with subfield, nonrecycling cursor - 1min12sec
  3. whereclause with subfield, recycling cursor - 1min11sec

So the best way how to retrieve a feature by OID for me is to use whereclause with subfield and nonrecycling cursor (recycling cursor is little bit faster, but it shouldn't be used for modifying feature)

0 Kudos