5

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.

Is there a faster way to get a collection of all the symbols in a feature layer?

  • 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
6

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);
    }
}
  • 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
4

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.

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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