7

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.

I've asked this question on the ESRI forums with no solution yet so hopefully someone here can help.

The formatted classification via ArcObjects but no link to field in Symbology properties

    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 =  pTable.RowCount(null) + 1;;
    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[i] = (ISymbol)pLineFillSymbol;
    pClassBreaksRenderer.set_Break(i,classes[i + 1]);
    pClassBreaksRenderer.Label[i] = ((Single)(classes[i])).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();

}
  • 1
    You are setting pClassBreaksRenderer.Field = pTH.Field; so assuming the field is there I can't see why it's not taking... I haven't worked with this class before but I can't see any obvious mistakes. Does the symbology work but the field not get populated? Is the symbology field in the linked table? that would make it more difficult (might need to work with IDisplayTable) perhaps it's as simple as giving the fully qualified name (eg RelatedTable.IDX). – Michael Stimson Jul 29 '15 at 4:58
  • @MichaelMiles-Stimson Thanks for looking at the code. I too thought setting the pClassBreaksRenderer.Field should do it. When I run the code the symbology is set correctly in the TOC and in the Symbology properties breaks window. However, the layer itself doesn't render correctly, which I suspect is due to the lack of Symbology Field. The Symbology Field is in the linked table and shows up in the Symbology Field combobox when selected. I tried using the fully qualified name to no avail. I haven't used IDisplayTable before. – adriank Jul 30 '15 at 5:08
1

This was answered on the ESRI forum but I thought I'd repeat it here. 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.

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.