I have what I believe to be a very simple question, but I cannot find an answer for it. Is there a method of getting a single feature from an object id (OID)? In ArcObjects this can be accomplished by simply calling GetFeature() on a feature class object and passing in an object id. An example would be IFeature feature = featClass.GetFeature(100).
You can search by ObjectId using QueryFilter.
public void SearchFC(FeatureClass featureClass, IReadOnlyList<long> objectIDs)
{
QueryFilter queryFilter = new QueryFilter()
{
ObjectIDs = objectIDs
};
using (RowCursor rowCursor = featureClass.Search(queryFilter))
{
while (rowCursor.MoveNext())
{
using (Feature feature = rowCursor.Current as Feature)
{
// use feature
}
}
}
}
Yeah, that is the direction that I figured that I would have to go. I ended up writing a function that uses a QueryFilter:
internal Task<int> GetMaxCellNumber()
{
return QueuedTask.Run<int>(() =>
{
FeatureClass featClass = GridLayer.GetFeatureClass();
int num = featClass.GetCount();
List<long> oids = new List<long>();
oids.Add(checked(num - 1));
IReadOnlyList<long> objectIDs = oids.AsReadOnly();
QueryFilter queryFilter = new QueryFilter()
{
ObjectIDs = objectIDs
};
RowCursor cursor = featClass.Search(queryFilter);
Row row = null;
if (cursor.MoveNext())
row = cursor.Current;
if (row == null)
return 0;
return (int)row["Cell_Num"];
});
}
Does this seem like a good solution or can it be made simpler? It just seems a little clunky.
I also am looking for this one-liner as I know this was so easy to use in ArcObjects. Creating a filter and cursor object seems to bloating when comparing it to good ol' featClass.GetFeature(oid) 😐
Hi,
You can use Inspector class Load method. There is Load method overload Load(Table,Int64) where parameters are table/featureclass and objectid. Then you can read attributes and geometry using inspector object.