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?
Solved! Go to Solution.
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
Hi,
Take a look to another thread.
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;
}
}
}
}
@UmaHarano , @CharlesMacleod, @Aashis can you help?
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
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:
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)