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 have a FeatureLayer and I want to enumerate all the symbols used in it. Simple way - it is to call SymbolByFeature for each features. Something approximately likes:

Dim l as IFeatureLayer
Dim c as IFeatureCursor
Dim r as IFeatureRender
Dim f as IFeature
Dim s as ISymbol

Set r = IGeoFeatureLayer(l).Renderer
Set c = l.Search(0, True)
Set f = c.NextFeature

Do Until f is Nothing
  Set s = r.SymbolByFeature(f)
  [...]  ' check whether this symbol is in collection and add it if necessary
  Set f = c.NextFeature
Loop

The problem with this method is that it too long, especially when there is a lot of features in the feature layer.
Question: Is there a faster way to get a collection of all the symbols in a feature layer?

share|improve this question
    
What kind of IFeatureRenderer are you using? –  Kirk Kuykendall May 17 '11 at 13:44
    
@Kirk - It can be arbitrary –  Loom May 17 '11 at 13:52

2 Answers 2

up vote 4 down vote accepted

This is my solution (in C++)

esriCarto::IFeatureLayerPtr l = get_layer(); // it is taken from somewhere
esriCarto::ILegendInfoPtr info = l;

for (long i = 0; i < info->LegendGroupCount; ++i) {
    esriCarto::ILegendGroupPtr group = info->GetLegendGroup(i);

    for (long j = 0; j != group->ClassCount; ++j) {
            esriCarto::ILegendClassPtr c = group->GetClass(j);
            some_function_to_add_symbol(c->Symbol);
    }
}
share|improve this answer
1  
+1 yes, this looks much simpler. Keep in mind for a uniqevaluerenderer there might be a symbol for "all other values" even though there might not be any features that actually have that symbol. –  Kirk Kuykendall May 18 '11 at 16:28

You could put in if statements to handle each different coclass that implements IFeatureRenderer. e.g. For IUniqueValueRenderer, you can loop through each value, and get the symbol associated with the value. For ISimpleRenderer, just get the single symbol, etc.

share|improve this answer
    
Thank you. This approach works, but it is too wordy. I would like some more generic way. –  Loom May 17 '11 at 14:23

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.