Symblize Point Layer

447
1
07-29-2013 06:05 PM
shaileshgavathe
Occasional Contributor II
All,

I am in a unique situation to symbolize point layer.

For example, I have a point Layer that has following attributes.

Field1, Field2, X, Y, Field3, Field4, Field5
1,1,-71.438467,41.825945,egsq,price rite - eagle square,0,0,0
0,2,-71.438467,41.825945,016495,PRICE RITE EAGLE SQUARE,16495,0,0
0,0,-71.438511,41.826,50
2,0,-71.438041,41.82638,0

I wanted to symbolize based upon Field values with the following criteria.
Field3 = 50 , Then color is Green
Field3 = 0, Then color is blue.

How to achieve this using IUniqueValueRenderer?


I am using following code snippet ...

              #region loop for featurecursor
                while (!(i == n))
                {
                
            
                    //System.Threading.Thread.Sleep(1000);
                    IFeature pFeat = default(IFeature);
                    pFeat = pFeatCursor.NextFeature();
                    ISimpleRenderer simpleRender = default(ISimpleRenderer);
                    simpleRender = new SimpleRenderer();

                    IUniqueValueRenderer pRender = default(IUniqueValueRenderer);
                    pRender = new UniqueValueRenderer();
                    pRender.FieldCount = 1;
                    pRender.set_Field(0, "Field1");
              
                    pRender.FieldDelimiter = ",";
                    pRender.UseDefaultSymbol = false;


                    SimpleMarkerSymbol markerSYmbol = new SimpleMarkerSymbol();
                    IRgbColor color = new RgbColor();
                    int indefOfField = pFeat.Fields.FindField("Field5");

                    int fieldValue = 0;
                    object TPTYpeValue =  pFeat.get_Value(indefOfField);
                    string tpTypeVal = TPTYpeValue.ToString();
                    bool isIntger = int.TryParse(tpTypeVal, out fieldValue);


                    if (isIntger) //Check to see, if it's integer first
                    {

                        if (fieldValue == 0) //If value is 0 then assign Red color
                        {
                           
                            //markerSYmbol.Color = (IColor)color;
                            markerSYmbol.Color = new RgbColorClass {Red = 255, Green = 0, Blue = 0};

                            markerSYmbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle;
                            markerSYmbol.Size = 6;
                        }
                        else
                        {
                            markerSYmbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle;
                            markerSYmbol.Size = 20;
                            markerSYmbol.Color = new RgbColorClass { Red = 0, Green = 0, Blue = 255 };
                        }

                    }
                    else
                    {
                        markerSYmbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle;
                        markerSYmbol.Size = 14;
                        markerSYmbol.Color = new RgbColorClass { Red = 0, Green = 0, Blue = 255 };
                    }

                    string w = null;
                    w = iRedField + "," + iGreenField + "," + iBlueField;
                    ValFound = false;

                    for (uh = 0; uh <= (pRender.ValueCount - 1); uh++)
                    {
                        if (pRender.Value[uh] == w)
                        {
                            NoValFound = true;
                            break;
                        }
                    }
                    if (!ValFound)
                    {
                    

                       ESRI.ArcGIS.Display.ISymbol symbol = (ESRI.ArcGIS.Display.ISymbol)markerSYmbol; // Explicit Cast

                        pRender.AddValue(w, "", symbol);
                        pRender.set_Symbol(w, symbol);


                        //Symbolize Feature
                        simpleRender.Symbol = symbol;

                        ESRI.ArcGIS.Carto.IFeatureRenderer _featRender = (ESRI.ArcGIS.Carto.IFeatureRenderer)simpleRender;
                        pLayer.Renderer = _featRender;

                        //_featRender.SymbolByFeature.Draw = symbol;
                       
                        //pLayer.MaximumScale = 3000.00;
                        //pLayer.MinimumScale = 500000.00;

                        #region LabelFeature

                        stdole.IFontDisp font = new stdole.StdFontClass() as stdole.IFontDisp;
                        font.Name = "Times New Roman";
                        font.Bold = false;
                        font.Size = 10;

                        IAnnotateLayerPropertiesCollection _layerAnnotate;
                        _layerAnnotate = pLayer.AnnotationProperties;

                        IElementCollection placedElement = new ElementCollection();
                        IElementCollection unplacedElement = new ElementCollection();
                        IAnnotateLayerProperties _layerAnnotateProps;
                        _layerAnnotate.QueryItem(0, out _layerAnnotateProps, out placedElement, out unplacedElement);

                        //Min / Max Scale for Layer Labels
                        _layerAnnotateProps.AnnotationMaximumScale = 3000.00;
                        _layerAnnotateProps.AnnotationMinimumScale = 500000.00;

                        ILabelEngineLayerProperties pLayerLabelEngineProps;

                          pLayerLabelEngineProps = (ILabelEngineLayerProperties)_layerAnnotateProps;

                      
                        pLayer.DisplayAnnotation = true;

                        #endregion

                    }

                    i = i + 1;


                }
                #endregion

                IUID pUID = new UIDClass();
                pUID.Value = "{683C994E-A17B-11D1-8816-080009EC732A}";


                //** This makes the layer properties symbology tab show
                //** show the correct interface.
                IRendererPropertyPage pRPpage = new UniqueValuePropertyPageClass();

                pLayer.RendererPropertyPageClassID = pUID as UIDClass; // pRPpage.ClassID;

                //Add Layer to static list to acces in future
               
                k++;


                //Release feature cursor
                //Marshal.ReleaseComObject(pFeatCursor);


           // }

            #endregion


            //Add Layer to Map
            pMap.AddLayer(pLayer);

            //** Refresh the TOC
            pMxDoc.ActiveView.ContentsChanged();
            pMxDoc.UpdateContents();

            //** Draw the map
            pMxDoc.ActiveView.Refresh();


            #endregion


*****************************************
Thanks and Regards,
Shailesh Gavathe
0 Kudos
1 Reply
DavidClarke1
New Contributor III
I think this is closer to what you want.  Keep in mind it may not plug into the rest of your code but I hope you get the idea.  I removed the labeling code to make it a shorter example.


//Added for syntax checking
IFeatureCursor pFeatCursor = null;
Int32 i = 0;
Int32 n = 0;
Boolean ValFound;
IGeoFeatureLayer pLayer = null;
//Added for syntax checking

IUniqueValueRenderer pRender = new UniqueValueRendererClass();

pRender.FieldCount = 1;
pRender.set_Field(0, "Field3");
pRender.UseDefaultSymbol = false;

//pFeatCursor = Intialize from your source

while (!(i == n))
{
    IFeature pFeat = default(IFeature);
    pFeat = pFeatCursor.NextFeature();

    SimpleMarkerSymbol markerSYmbol = new SimpleMarkerSymbolClass();
    IRgbColor color = new RgbColorClass();
    int indefOfField = pFeat.Fields.FindField("Field3");

    int fieldValue = 0;
    object TPTYpeValue = pFeat.get_Value(indefOfField);
    string tpTypeVal = TPTYpeValue.ToString();
    bool isIntger = int.TryParse(tpTypeVal, out fieldValue);

    if (!isIntger) //if not integer then assume value of 100 for blue
    {
        fieldValue = 100;
    }

    if (fieldValue == 0) //If value is 0 then assign Red color 
    {
        color.Blue = 0;
        color.Green = 0;
        color.Red = 255;

        markerSYmbol.Color = color;
        markerSYmbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle;
        markerSYmbol.Size = 6;
    }
    else if (fieldValue == 50)
    {
        color.Blue = 0;
        color.Green = 255;
        color.Red = 0;

        markerSYmbol.Color = color;
        markerSYmbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle;
        markerSYmbol.Size = 20;
    }
    else
    {
        color.Blue = 255;
        color.Green = 0;
        color.Red = 0;

        markerSYmbol.Color = color;
        markerSYmbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle;
        markerSYmbol.Size = 14;
    }

    ValFound = false;

    string w = fieldValue.ToString(); //0=Red, 50=Green, 100=Blue

    for (Int32 uh = 0; uh < pRender.ValueCount; uh++)
    {
        if (pRender.Value[uh] == w)
        {
            ValFound = true;
            break;
        }
    }

    if (!ValFound)
    {
        ESRI.ArcGIS.Display.ISymbol symbol = (ESRI.ArcGIS.Display.ISymbol)markerSYmbol; // Explicit Cast

        pRender.AddValue(w, null, symbol);
    }
}
pLayer.Renderer = (IFeatureRenderer)pRender;
0 Kudos