Setting Field in Symbology Properties

7135
5
Jump to solution
07-27-2015 09:20 PM
AKitch
by
Occasional Contributor

Hi

I am programmatically rendering a feature layer in ArcMap but I can't set the Field property in the Symbology properties form. This results in the layer having the correct render/breaks/legend settings but the on screen render is wrong. When I open the Symbology tab the Field isn't set. When I do select the field the classification is reset. The focus field is actually from a linked table. Any suggestions? Below is the code I have for rendering the layer.

I'm using ArcGIS 10.2.2; Windows 7;VS2010 Express. Feature layer is in a file geodatabase along with a linked table.

symbology_set_field.png

Regards

Adrian

    public void ClassifyLayer(ref IFeatureLayer pFL, ITable pTable)
    {
        IGeoFeatureLayer pGFLyr = (IGeoFeatureLayer)pFL;
        object dataValues;
        object dataFrequencies;
        ISimpleLineSymbol pLineFillSymbol;
        IClassBreaksUIProperties pClassBreaksUIProperties;
        IFeatureRenderer ifr = pGFLyr.Renderer;
        IClassBreaksRenderer pClassBreaksRenderer = (IClassBreaksRenderer)ifr;
        IDataSampling ds = (IDataSampling)pClassBreaksRenderer;
        ITableHistogram pTH = (ITableHistogram)new TableHistogram();
        pTH.Field = "IDX";
        pTH.Table = pTable;
        ds.MaxSampleSize = 1000000;
        pTH.Sampling = ds;
        IHistogram pHist = (IHistogram)pTH;
        pHist.GetHistogram(out dataValues, out dataFrequencies);
     
        IClassify pClassify  = new QuantileClass();
        double[] classes;
      
        pClassify.SetHistogramData(dataValues, dataFrequencies);
        pClassify.Classify(10);
        classes = (double[])pClassify.ClassBreaks;
        pClassBreaksRenderer.BreakCount = classes.Length - 1;
        pClassBreaksRenderer.Field = pTH.Field;
        pClassBreaksRenderer.MinimumBreak = classes[0];
  
    //Spectrum-Full Bright  
        IMultiPartColorRamp pMultiColourRamp = GetSpectrumRamp(10);
        bool rampcreated = false;
        IEnumColors pColors = pMultiColourRamp.Colors;
        for (int i = 0; i < pClassBreaksRenderer.BreakCount; i++)
        {
            pLineFillSymbol = new SimpleLineSymbol();
            pLineFillSymbol.Color = pColors.Next();
            pClassBreaksRenderer.Symbol = (ISymbol)pLineFillSymbol;
            pClassBreaksRenderer.set_Break(i,classes[i + 1]);
            pClassBreaksRenderer.Label = ((Single)(classes)).ToString() + " - " + ((Single)(classes[i + 1])).ToString();
        }
        pClassBreaksUIProperties = (IClassBreaksUIProperties)pClassBreaksRenderer;
        pClassBreaksUIProperties.Method = pClassify.ClassID;
        pClassBreaksUIProperties.ColorRamp = "Spectrum-Full Bright";
      
        for (int i = 1; i < pClassBreaksRenderer.BreakCount; i++)
        {
            pClassBreaksUIProperties.set_LowBreak(i, pClassBreaksRenderer.Break[i - 1]);
        }
      
        pClassBreaksUIProperties.ShowClassGaps = true;
        pGFLyr.Renderer = (IFeatureRenderer)pClassBreaksRenderer;
        IRendererPropertyPage pRendererPropPage = (IRendererPropertyPage)new GraduatedColorPropertyPage();
        pGFLyr.RendererPropertyPageClassID = pRendererPropPage.ClassID;
        pMxDoc.ActivatedView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pFL, null);
        pMxDoc.UpdateContents();
    }

Message was edited by: Adrian Kitchingman As requested; attempted syntax highlighting for C# though couldn't stop formatting change and extra rows

0 Kudos
1 Solution

Accepted Solutions
AKitch
by
Occasional Contributor

So Duncan it turns out it is an issue with the Joined table. Regardless of defining the field with the layer or table name the symbology fails to find the field. As soon as the joins are removed (and if the focus field is in the rendered layer) then the rendering happens correctly. So to get around this I now have to Join the table on the fly, do my calcs, then remove the join before automatically rendering the layer. In the end the original rendering code works fine and I don't need to use IFeatureRendererUpdate. Thanks for the help. I'll look into how to let support know about the issue.

Regards

View solution in original post

5 Replies
AKitch
by
Occasional Contributor

Really! No one has an answer to this question!?

0 Kudos
DuncanHornby
MVP Notable Contributor

Don't know if this will help but there is an interface called IFeatureRendererUpdate​ have a go at that?

0 Kudos
AKitch
by
Occasional Contributor

Thanks Duncan. At least something to explore. Not much documentation out there on this Interface. Have you (or anyone else) used it?

I attempted to use it but got a:

HRESULT E_FAIL has been returned from a call to a COM component

Here is the added code I attempted which modifies the last few lines of the original code above. Not sure if I'm implementing it correctly.

pGFLyr.Renderer = (IFeatureRenderer)pClassBreaksRenderer;  
IRendererPropertyPage pRendererPropPage = (IRendererPropertyPage)new GraduatedColorPropertyPage();    

pGFLyr.RendererPropertyPageClassID = pRendererPropPage.ClassID;

IFeatureRendererUpdate ifru = (IFeatureRendererUpdate)pGFLyr.Renderer

IFeatureRendererUpdate.Update(pFL)

pMxDoc.ActivatedView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pFL, null);    

pMxDoc.UpdateContents();

Anyone have suggestions on IFeatureRendererUpdate?

0 Kudos
DuncanHornby
MVP Notable Contributor

Adrian,

No I've not used it, it was a stab in the dark and you are right remarkably little documentation on it. It would be good if any of the ESRI developers could shed some light on that Interface?

My only suggestion is confirm that it's an issue with the joined field by copying the field into the dataset so the symbology is not based upon a joined field. If that fails then it suggest something subtle is wrong with the above code. If it succeeds then it's something up with it being a joined field? At that point I would fire it off to ESRI support as it could be a bug?

Duncan

0 Kudos
AKitch
by
Occasional Contributor

So Duncan it turns out it is an issue with the Joined table. Regardless of defining the field with the layer or table name the symbology fails to find the field. As soon as the joins are removed (and if the focus field is in the rendered layer) then the rendering happens correctly. So to get around this I now have to Join the table on the fly, do my calcs, then remove the join before automatically rendering the layer. In the end the original rendering code works fine and I don't need to use IFeatureRendererUpdate. Thanks for the help. I'll look into how to let support know about the issue.

Regards