Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 3 down vote accepted

You should pass an objectID to IFeatureClass.GetFeature, not a ClassID.

share|improve this answer
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. – Chaz Feb 8 '12 at 19:56
A featureclass contains a collection of features. When you draw a map the map calls ILayer.Draw. For a featurelayer it will loop through each feature in the featureclass and for each feature get its symbol and draw it. You can use a FeatureCursor to get features. – Kirk Kuykendall Feb 8 '12 at 20:07
Aaaah! Doh! I need a feature so I grab the first one that a featureCursor returns and that works! Thanks. – Chaz Feb 8 '12 at 22:07
don't forget to call ReleaseComObject on the cursor when done with it. – Kirk Kuykendall Feb 8 '12 at 22:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.