Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 2 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
add comment

Your Answer

 
discard

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.