sgavathe

Symblize Point Layer

Discussion created by sgavathe on Jul 29, 2013
Latest reply on Aug 20, 2013 by davidclarke
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

Outcomes