Select to view content in your preferred language

Get Feature Symbol

812
5
02-08-2012 08:00 AM
GeorgeFaraj
Frequent Contributor
I am using this code to get the symbol associated with a feature:
IFeature feature = geoFeatureLayer.FeatureClass.GetFeature( geoFeatureLayer.FeatureClass.FeatureClassID );
geoFeatureLayer.Renderer.get_SymbolByFeature( feature );


Of course, now I have encountered a layer where "FeatureClassID = -1" and this code crashes with "ROW_NOT_FOUND."
The help says: "...IFeatureClass::FeatureClassID will always return -1 for Coverage and Shapefile feature classes."
I (sort of) understand that but how should I get the Symbol for that kind of feature?  Suggestions?
0 Kudos
5 Replies
NeilClemmons
Honored Contributor
GetFeature() takes the ObjectId of the feature you want it to return.
0 Kudos
GeorgeFaraj
Frequent Contributor
GetFeature() takes the ObjectId of the feature you want it to return.


But it bombs if the ObjectId is -1. What do I do if my ObjectId = -1?
0 Kudos
NeilClemmons
Honored Contributor
It is not possible for a feature to have an ObjectId of -1.
0 Kudos
GeorgeFaraj
Frequent Contributor
It is not possible for a feature to have an ObjectId of -1.


Where do I get the ObjectId? The help says, "Since IFeatureClass inherits from IObjectClass, you can also get the feature class ID from IObjectClass:: ObjectClassID." But that is -1 also
0 Kudos
NeilClemmons
Honored Contributor
You're confusing the id of a feature class with the id of a feature.  They aren't the same thing.  The id of a feature class uniquely identifies the feature class within the geodatabase.  This is why shapefiles and CAD files have a feature class id of -1 (which isn't a valid value for a geodatabase feature class id); they don't belong to a geodatabase.  These ids are used mainly by the geodatabase itself; you will rarely, if ever, need to use the id of a feature class for anything.  The id of a feature uniquely identifies that feature within a feature class.  For geodatabase feature classes, the feature id field is named ObjectId by default.  For shapefiles it is usually named FID.  You can see the feature ids by adding the feature class as a layer to ArcMap and opening the attribute table.  It is this feature id that you will need to pass into GetFeature to return a particular feature from the feature class.  You can then pass the feature into the SymbolByFeature method to get the symbol that is used to draw the feature in the map view.
0 Kudos