public void LayerRender() { try { //IFeatureLayer pFeatureLayer = featLayer; IGeoFeatureLayer pGeoFeatureLayer = featLayer as IGeoFeatureLayer; IFeatureClass pFeatureClass = featLayer.FeatureClass; //获取图层上的featureClass IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false); IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); //唯一值渲染器 //设置渲染字段对象 pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, fieldName); ISimpleFillSymbol pSimFillSymbol = new SimpleFillSymbolClass(); //创建填充符号 pUniqueValueRenderer.DefaultSymbol = (ISymbol)pSimFillSymbol; pUniqueValueRenderer.UseDefaultSymbol = false; int n = pFeatureClass.FeatureCount(null); for (int i = 0; i < n; i++) { IFeature pFeature = pFeatureCursor.NextFeature(); IClone pSourceClone = pSimFillSymbol as IClone; ISimpleFillSymbol pSimpleFillSymbol = pSourceClone.Clone() as ISimpleFillSymbol; string pFeatureValue = pFeature.get_Value(pFeature.Fields.FindField(fieldName)).ToString(); pUniqueValueRenderer.AddValue(pFeatureValue, "", (ISymbol)pSimpleFillSymbol); } //为每个符号设置颜色 for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++) { string xv = pUniqueValueRenderer.get_Value(i); if (xv != "") { ISimpleFillSymbol pNextSymbol = (ISimpleFillSymbol)pUniqueValueRenderer.get_Symbol(xv); pNextSymbol.Color = colorRamp.get_Color(i * (colorRamp.Size / pUniqueValueRenderer.ValueCount)); pUniqueValueRenderer.set_Symbol(xv, (ISymbol)pNextSymbol); if (xv.Contains(".")) { pUniqueValueRenderer.set_Label(xv, xv.Substring(0, xv.IndexOf(".") + 4)); } else { pUniqueValueRenderer.set_Label(xv, xv); } } } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; axmapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); axtoccontrol.Update(); } catch (Exception e) { MessageBox.Show(e.Message); } }
public static void uniqueRender(IFeatureLayer featLayer, string fieldName) { IGeoFeatureLayer pGeoFeatureLayer = featLayer as IGeoFeatureLayer; IFeatureClass pFeatureClass = featLayer.FeatureClass; //获取图层上的featureClass IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false); IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); //唯一值渲染器 //设置渲染字段对象 pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, fieldName); ISimpleFillSymbol pSimFillSymbol = new SimpleFillSymbolClass(); //创建填充符号 pUniqueValueRenderer.DefaultSymbol = (ISymbol)pSimFillSymbol; pUniqueValueRenderer.UseDefaultSymbol = false; int n = pFeatureClass.FeatureCount(null); for (int i = 0; i < n; i++) { IFeature pFeature = pFeatureCursor.NextFeature(); string pFeatureValue = pFeature.get_Value(pFeature.Fields.FindField(fieldName)).ToString(); pUniqueValueRenderer.AddValue(pFeatureValue, "", null); } IRandomColorRamp colorRamp = new RandomColorRampClass(); colorRamp.Size = pUniqueValueRenderer.ValueCount; bool b = true; colorRamp.CreateRamp(out b); //为每个符号设置颜色 for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++) { string xv = pUniqueValueRenderer.get_Value(i); if (xv != "") { pUniqueValueRenderer.set_Symbol(xv, getISymbolByGeomType(featLayer, colorRamp.get_Color(i * (colorRamp.Size - 1) / (pUniqueValueRenderer.ValueCount - 1)))); } } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; }
/// <summary> /// 按聚类号对凸包进行渲染 /// </summary> /// <param name="pGeoFeatureLayer"></param> /// <param name="fieldName"></param> public void DefinePolygonUniqueValueRenderer(IGeoFeatureLayer pGeoFeatureLayer, string fieldName) { IRandomColorRamp pRandomColorRamp = new RandomColorRampClass(); //Create the color ramp for the symbols in the renderer. pRandomColorRamp.MinSaturation = 20; pRandomColorRamp.MaxSaturation = 40; pRandomColorRamp.MinValue = 85; pRandomColorRamp.MaxValue = 100; pRandomColorRamp.StartHue = 76; pRandomColorRamp.EndHue = 188; pRandomColorRamp.UseSeed = true; pRandomColorRamp.Seed = 43; //Create the renderer. IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSimpleFillSymbol.Outline.Width = 0.4; /* ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); * pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; * pSimpleMarkerSymbol.Size = 5; * pSimpleMarkerSymbol.Outline = true; * IRgbColor pLineRgbColor = new RgbColorClass(); * pLineRgbColor.Red = 0; * pLineRgbColor.Green = 0; * pLineRgbColor.Blue = 0; * pSimpleMarkerSymbol.OutlineColor = pLineRgbColor as IColor; */ //These properties should be set prior to adding values. pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, fieldName); pUniqueValueRenderer.DefaultSymbol = pSimpleFillSymbol as ISymbol; pUniqueValueRenderer.UseDefaultSymbol = true; IDisplayTable pDisplayTable = pGeoFeatureLayer as IDisplayTable; IFeatureCursor pFeatureCursor = pDisplayTable.SearchDisplayTable(null, false) as IFeatureCursor; IFeature pFeature = pFeatureCursor.NextFeature(); bool ValFound; int fieldIndex; IFields pFields = pFeatureCursor.Fields; fieldIndex = pFields.FindField(fieldName); while (pFeature != null) { ISimpleFillSymbol pClassSymbol = new SimpleFillSymbolClass(); pClassSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pClassSymbol.Outline.Width = 0.4; /* ISimpleMarkerSymbol pClassSymbol = new SimpleMarkerSymbolClass(); * pClassSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; * pClassSymbol.Size = 5; * pClassSymbol.Outline = true; * pClassSymbol.OutlineColor = pLineRgbColor as IColor; */ string classValue; classValue = pFeature.get_Value(fieldIndex).ToString(); //Test to see if this value was added to the renderer. If not, add it. ValFound = false; for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++) { if (pUniqueValueRenderer.get_Value(i) == classValue) { ValFound = true; break; //Exit the loop if the value was found. } } //If the value was not found, it's new and will be added. if (ValFound == false) { pUniqueValueRenderer.AddValue(classValue, fieldName, pClassSymbol as ISymbol); pUniqueValueRenderer.set_Label(classValue, classValue); pUniqueValueRenderer.set_Symbol(classValue, pClassSymbol as ISymbol); } pFeature = pFeatureCursor.NextFeature(); } //Since the number of unique values is known, the color ramp can be sized and the colors assigned. pRandomColorRamp.Size = pUniqueValueRenderer.ValueCount; bool bOK; pRandomColorRamp.CreateRamp(out bOK); IEnumColors pEnumColors = pRandomColorRamp.Colors; pEnumColors.Reset(); for (int j = 0; j <= pUniqueValueRenderer.ValueCount - 1; j++) { string xv; xv = pUniqueValueRenderer.get_Value(j); if (xv != "") { ISimpleFillSymbol pSimpleFillColor = pUniqueValueRenderer.get_Symbol(xv) as ISimpleFillSymbol; pSimpleFillColor.Color = pEnumColors.Next(); pUniqueValueRenderer.set_Symbol(xv, pSimpleFillColor as ISymbol); } } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; pGeoFeatureLayer.DisplayField = fieldName; }
public static void DefineUniqueValueRenderer(IGeoFeatureLayer geoFealyr,string fieldName) { // Create color ramp for the symbol in rendere IRandomColorRamp randomColorRamp = new RandomColorRampClass(); randomColorRamp.MinSaturation = 20; randomColorRamp.MaxSaturation = 40; randomColorRamp.MinValue = 85; randomColorRamp.MaxValue = 100; randomColorRamp.StartHue = 76; randomColorRamp.EndHue = 188; randomColorRamp.UseSeed = true; randomColorRamp.Seed = 43; // Create a symbol ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; simpleFillSymbol.Outline.Width = 0.4; // Create the renderer IUniqueValueRenderer uniqueValueRender = new UniqueValueRendererClass(); uniqueValueRender.FieldCount = 1; uniqueValueRender.set_Field(0, fieldName); uniqueValueRender.DefaultSymbol = simpleFillSymbol as ISymbol; uniqueValueRender.UseDefaultSymbol = true; IDisplayTable displayTable = geoFealyr as IDisplayTable; IFeatureCursor feacursor = displayTable.SearchDisplayTable(null, false) as IFeatureCursor; IFeature fea = feacursor.NextFeature(); bool valfound; int fieldIndex; IFields fields = feacursor.Fields; fieldIndex = fields.FindField(fieldName); while(fea!=null) { ISimpleFillSymbol classSymbol = new SimpleFillSymbolClass(); classSymbol.Style = esriSimpleFillStyle.esriSFSSolid; classSymbol.Outline.Width = 0.4; string classValue; classValue = fea.get_Value(fieldIndex) as string; valfound = false; for(int i=0;i<=uniqueValueRender.ValueCount-1;i++) { if(uniqueValueRender.get_Value(i)==classValue) { valfound = true; break; } } if(valfound==false) { uniqueValueRender.AddValue(classValue, fieldName, classSymbol as ISymbol); uniqueValueRender.set_Label(classValue, classValue); uniqueValueRender.set_Symbol(classValue, classSymbol as ISymbol); } fea = feacursor.NextFeature(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(feacursor); randomColorRamp.Size = uniqueValueRender.ValueCount; bool bOK; randomColorRamp.CreateRamp(out bOK); IEnumColors enumColors = randomColorRamp.Colors; enumColors.Reset(); for(int j=0;j<=uniqueValueRender.ValueCount-1;j++) { string xv; xv = uniqueValueRender.get_Value(j); if(xv!="") { ISimpleFillSymbol simplefs = uniqueValueRender.get_Symbol(xv) as ISimpleFillSymbol; simplefs.Color = enumColors.Next(); uniqueValueRender.set_Symbol(xv, simplefs as ISymbol); } } uniqueValueRender.ColorScheme = "Custome"; ITable tbl = displayTable as ITable; bool isString = tbl.Fields.get_Field(fieldIndex).Type == esriFieldType.esriFieldTypeString; uniqueValueRender.set_FieldType(0, isString); geoFealyr.Renderer = uniqueValueRender as IFeatureRenderer; IUID uid = new UIDClass(); uid.Value = "{25AE5C2F-0B57-41C6-A492-31352BAD3A37}"; geoFealyr.RendererPropertyPageClassID = uid as UIDClass; }
/// <summary> /// Returns Simple Renderer if no values can be found /// </summary> /// <param name="renderContainer"></param> /// <returns></returns> public static IFeatureRenderer NewUniqueValueRenderer(RendererContainer renderContainer) { BiPolarRendererContainer biPolarRendererContainer = renderContainer.BiPolarRendererContainer; IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRendererClass(); ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; simpleFillSymbol.Outline.Width = 0.4; var fieldName = biPolarRendererContainer.Field.Name; uniqueValueRenderer.FieldCount = 1; uniqueValueRenderer.Field[0] = fieldName; int fieldIndex; ISet <double> setOfFeatures = new HashSet <double>(); var containsDbNullValue = false; using (var comReleaser = new ComReleaser()) { var featureCursor = renderContainer.Field.Feature.FeatureClass.Search(null, true); comReleaser.ManageLifetime(featureCursor); fieldIndex = featureCursor.Fields.FindField(fieldName); IFeature currentFeature; while ((currentFeature = featureCursor.NextFeature()) != null) { var value = currentFeature.Value[fieldIndex]; if (Convert.IsDBNull(value)) { containsDbNullValue = true; continue; } //TODO datetime is possible??? setOfFeatures.Add(Convert.ToDouble(value)); } } if (containsDbNullValue && setOfFeatures.Count == 0) { return(NewAllMissingValuesRenderer()); } if (setOfFeatures.Count == 0) { return(NewSimpleRenderer()); } IEnumerable <double> orderedSet = setOfFeatures.OrderBy(d => d); foreach (var currentClassValue in orderedSet) { ISimpleFillSymbol pClassSymbol = new SimpleFillSymbolClass(); pClassSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pClassSymbol.Outline.Width = 0.4; // the format is important, because the normal to string will represent the power as E-05 or something like that // the result are mismatches between the renderer value and the column value //string classValue = currentClassValue.ToString("N20"); does not really work var dirtyTrick = (decimal)currentClassValue; var classValue = dirtyTrick.ToString(); uniqueValueRenderer.AddValue(classValue, fieldName, (ISymbol)pClassSymbol); uniqueValueRenderer.set_Label(classValue, classValue); uniqueValueRenderer.set_Symbol(classValue, (ISymbol)pClassSymbol); } //figure out how many colors belong to which side from the neutral color var size = uniqueValueRenderer.ValueCount; var left = (int)(size * biPolarRendererContainer.NeutralColorPosition); var right = size - left; // for the case one or both are zero -> create color ramp crashes, the magic value seems to be 2 if (left < 2) { left = 2; } if (right < 2) { right = 2; } IAlgorithmicColorRamp firstColorRamp = new AlgorithmicColorRampClass(); firstColorRamp.FromColor = ToColor(biPolarRendererContainer.NegativColor); firstColorRamp.ToColor = ToColor(biPolarRendererContainer.NeutralColor); firstColorRamp.Size = left; bool bOk; IAlgorithmicColorRamp secondColorRamp = new AlgorithmicColorRampClass(); secondColorRamp.FromColor = ToColor(biPolarRendererContainer.NeutralColor); secondColorRamp.ToColor = ToColor(biPolarRendererContainer.PositivColor); secondColorRamp.Size = right; firstColorRamp.CreateRamp(out bOk); secondColorRamp.CreateRamp(out bOk); var firstEnumColors = firstColorRamp.Colors; var secondEnumColors = secondColorRamp.Colors; firstEnumColors.Reset(); secondEnumColors.Reset(); for (var j = 0; j <= uniqueValueRenderer.ValueCount - 1; j++) { var label = uniqueValueRenderer.Value[j]; var pSimpleFillColor = (ISimpleFillSymbol)uniqueValueRenderer.Symbol[label]; var color = firstEnumColors.Next(); //in case the first half colors is "empty" change to the second if (color == null) { firstEnumColors = secondEnumColors; color = firstEnumColors.Next(); } pSimpleFillColor.Color = color; uniqueValueRenderer.set_Symbol(label, (ISymbol)pSimpleFillColor); } //'** If you didn'toolParameter use a predefined color ramp //'** in a style, use "Custom" here. Otherwise, //'** use the name of the color ramp you selected. uniqueValueRenderer.ColorScheme = "Custom"; ////ITable pTable = pDisplayTable as ITable; bool isString = renderContainer.Field.Feature.FeatureClass.Fields.Field[fieldIndex].Type == esriFieldType.esriFieldTypeString; //uniqueValueRenderer.FieldType[0] = isString; uniqueValueRenderer.set_FieldType(0, isString); //TODO geoFeatureLayer var geoFeatureLayer = renderContainer.Field.Feature.FeatureLayer as IGeoFeatureLayer; geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer; return((IFeatureRenderer)uniqueValueRenderer); }
public static void DefineUniqueValueRenderer(IGeoFeatureLayer pGeoFeatureLayer, string fieldName) { IRandomColorRamp pRandomColorRamp = new RandomColorRampClass(); //Create the color ramp for the symbols in the renderer. pRandomColorRamp.MinSaturation = 20; pRandomColorRamp.MaxSaturation = 40; pRandomColorRamp.MinValue = 85; pRandomColorRamp.MaxValue = 100; pRandomColorRamp.StartHue = 76; pRandomColorRamp.EndHue = 188; pRandomColorRamp.UseSeed = true; pRandomColorRamp.Seed = 43; //Create the renderer. IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSimpleFillSymbol.Outline.Width = 0.4; //These properties should be set prior to adding values. pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, fieldName); pUniqueValueRenderer.DefaultSymbol = pSimpleFillSymbol as ISymbol; pUniqueValueRenderer.UseDefaultSymbol = true; IDisplayTable pDisplayTable = pGeoFeatureLayer as IDisplayTable; IFeatureCursor pFeatureCursor = pDisplayTable.SearchDisplayTable(null, false) as IFeatureCursor; IFeature pFeature = pFeatureCursor.NextFeature(); bool ValFound; int fieldIndex; IFields pFields = pFeatureCursor.Fields; fieldIndex = pFields.FindField(fieldName); while (pFeature != null) { ISimpleFillSymbol pClassSymbol = new SimpleFillSymbolClass(); pClassSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pClassSymbol.Outline.Width = 0.4; string classValue; classValue = pFeature.get_Value(fieldIndex) as string; //Test to see if this value was added to the renderer. If not, add it. ValFound = false; for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++) { if (pUniqueValueRenderer.get_Value(i) == classValue) { ValFound = true; break; //Exit the loop if the value was found. } } //If the value was not found, it's new and will be added. if (ValFound == false) { pUniqueValueRenderer.AddValue(classValue, fieldName, pClassSymbol as ISymbol); pUniqueValueRenderer.set_Label(classValue, classValue); pUniqueValueRenderer.set_Symbol(classValue, pClassSymbol as ISymbol); } pFeature = pFeatureCursor.NextFeature(); } //Since the number of unique values is known, the color ramp can be sized and the colors assigned. pRandomColorRamp.Size = pUniqueValueRenderer.ValueCount; bool bOK; pRandomColorRamp.CreateRamp(out bOK); IEnumColors pEnumColors = pRandomColorRamp.Colors; pEnumColors.Reset(); for (int j = 0; j <= pUniqueValueRenderer.ValueCount - 1; j++) { string xv; xv = pUniqueValueRenderer.get_Value(j); if (xv != "") { ISimpleFillSymbol pSimpleFillColor = pUniqueValueRenderer.get_Symbol(xv) as ISimpleFillSymbol; pSimpleFillColor.Color = pEnumColors.Next(); pUniqueValueRenderer.set_Symbol(xv, pSimpleFillColor as ISymbol); } } //'** If you didn't use a predefined color ramp in a style, use "Custom" here. //'** Otherwise, use the name of the color ramp you selected. pUniqueValueRenderer.ColorScheme = pRandomColorRamp.Name;//"Custom"; ITable pTable = pDisplayTable as ITable; bool isString = pTable.Fields.get_Field(fieldIndex).Type == esriFieldType.esriFieldTypeString; pUniqueValueRenderer.set_FieldType(0, isString); pGeoFeatureLayer.Renderer = pUniqueValueRenderer as IFeatureRenderer; //This makes the layer properties symbology tab show the correct interface. IUID pUID = new UIDClass(); pUID.Value = "{683C994E-A17B-11D1-8816-080009EC732A}"; pGeoFeatureLayer.RendererPropertyPageClassID = pUID as UIDClass; }
// ********************* // Author: Erika Kamptner // Created Date: 3/10/2017 // Description: This method takes several parameters from the BuildMap method to connect to geodatabase, load layer, // place in appropriate group layer, style, and label. Only Address points, Cadastral, Building, and Centerline layers // have specified labels and symbology. // // ************************** public static void LoadCSCLFeatureClass(bool isCSCL, string strFCName, IGroupLayer pGroupLayer, string strGeodatabase) { //Point to map document IMxDocument pMxDoc; pMxDoc = (IMxDocument)ArcMap.Application.Document; IMap pMap; pMap = pMxDoc.FocusMap; //Set up shapefile Workspace connection IWorkspaceFactory pWorkspaceFactory; pWorkspaceFactory = new ShapefileWorkspaceFactoryClass(); //If connecting to SDE, set up SDE workspace connection //IWorkspaceFactory pWorkspaceFactory; //pWorkspaceFactory = new SdeWorkspaceFactoryClass(); IWorkspace pWorkspace; pWorkspace = pWorkspaceFactory.OpenFromFile(strGeodatabase, 0); IFeatureWorkspace pFeatureWorkspace; pFeatureWorkspace = (IFeatureWorkspace)pWorkspace; IFeatureClass pFeatureClass; pFeatureClass = pFeatureWorkspace.OpenFeatureClass(strFCName); IFeatureLayer pFeatureLayer; pFeatureLayer = new FeatureLayer(); pFeatureLayer.FeatureClass = pFeatureClass; pFeatureLayer.Name = pFeatureClass.AliasName; //Add layer to group if CSCL map type. Otherwise, just add layer. if (isCSCL) { pGroupLayer.Add((ILayer)pFeatureLayer); } else { pMap.AddLayer((ILayer)pFeatureLayer); } //Symbolize Address points based if the address has subaddresses if (pFeatureLayer.Name == "AddressPoint") { ILayer pLayer; pLayer = (ILayer)pFeatureLayer; IGeoFeatureLayer pGeoFeatureLayer; pGeoFeatureLayer = (IGeoFeatureLayer)pLayer; pGeoFeatureLayer.DisplayAnnotation = true; //Create unique symbology based on subaddress flag using unique value renderer ISimpleMarkerSymbol pAddressSymbolDefault; pAddressSymbolDefault = new SimpleMarkerSymbolClass(); pAddressSymbolDefault.Color = SetColor(230, 0, 0); pAddressSymbolDefault.Style = esriSimpleMarkerStyle.esriSMSCircle; pAddressSymbolDefault.Size = 4; IUniqueValueRenderer pUniqueValueRenderer; pUniqueValueRenderer = new UniqueValueRendererClass(); pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, "SUBADDRESS"); pUniqueValueRenderer.UseDefaultSymbol = false; //Create unique symbology for different values ISimpleMarkerSymbol pAddressSymbolYES; pAddressSymbolYES = new SimpleMarkerSymbolClass(); pAddressSymbolYES.Color = SetColor(230, 0, 0); pAddressSymbolYES.Style = esriSimpleMarkerStyle.esriSMSCircle; pAddressSymbolYES.Size = 8; pAddressSymbolYES.OutlineSize = 2; pAddressSymbolYES.OutlineColor = SetColor(255, 255, 0); pAddressSymbolYES.Outline = true; ISimpleMarkerSymbol pAddressSymbolNO; pAddressSymbolNO = new SimpleMarkerSymbolClass(); pAddressSymbolNO.Color = SetColor(230, 0, 0); pAddressSymbolNO.Style = esriSimpleMarkerStyle.esriSMSCircle; pAddressSymbolNO.Size = 4; pUniqueValueRenderer.AddValue("YES", "SUBADDRESS", pAddressSymbolYES as ISymbol); pUniqueValueRenderer.set_Label("YES", "YES"); pUniqueValueRenderer.set_Symbol("YES", pAddressSymbolYES as ISymbol); pUniqueValueRenderer.AddValue("NO", "SUBADDRESS", pAddressSymbolNO as ISymbol); pUniqueValueRenderer.set_Label("NO", "NO"); pUniqueValueRenderer.set_Symbol("NO", pAddressSymbolNO as ISymbol); //Create Label LabelFeatures(pGeoFeatureLayer, "\"ADDRESSID: \" + [ADDRESS_ID]"); pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; } else if (pFeatureLayer.Name == "Building") { ILayer pLayer; pLayer = (ILayer)pFeatureLayer; IGeoFeatureLayer pGeoFeatureLayer; pGeoFeatureLayer = (IGeoFeatureLayer)pLayer; pGeoFeatureLayer.DisplayField = "BIN"; pGeoFeatureLayer.DisplayAnnotation = true; //Create ouline element ISimpleLineSymbol pOutline; pOutline = new SimpleLineSymbolClass(); pOutline.Color = SetColor(0, 0, 255); pOutline.Width = 2; //Create polygon with outline element ISimpleFillSymbol pBuildingSymbol; pBuildingSymbol = new SimpleFillSymbolClass(); pBuildingSymbol.Style = esriSimpleFillStyle.esriSFSHollow; pBuildingSymbol.Outline = pOutline; //Create Label LabelFeatures(pGeoFeatureLayer, "\"BIN : \" + [BIN]"); //Render features ISimpleRenderer pSimpleRenderer; pSimpleRenderer = new SimpleRenderer(); pSimpleRenderer.Symbol = (ISymbol)pBuildingSymbol; pGeoFeatureLayer.Renderer = (IFeatureRenderer)pSimpleRenderer; } else if (pFeatureLayer.Name == "StreetCenterline") { ILayer pLayer; pLayer = (ILayer)pFeatureLayer; IGeoFeatureLayer pGeoFeatureLayer; pGeoFeatureLayer = (IGeoFeatureLayer)pLayer; pGeoFeatureLayer.DisplayField = "ST_NAME"; pGeoFeatureLayer.DisplayAnnotation = true; //Create arrow element to place at end of line segment IArrowMarkerSymbol arrowMarkerSymbol = new ArrowMarkerSymbolClass(); arrowMarkerSymbol.Color = SetColor(0, 0, 0); arrowMarkerSymbol.Size = 6; arrowMarkerSymbol.Length = 8; arrowMarkerSymbol.Width = 6; arrowMarkerSymbol.XOffset = 0.8; //Create cartographic line symbol ICartographicLineSymbol pCartographicLineSymbol; pCartographicLineSymbol = new CartographicLineSymbolClass(); pCartographicLineSymbol.Color = SetColor(0, 0, 0); pCartographicLineSymbol.Width = 2; //Place arrow at end of line ISimpleLineDecorationElement pCenterlineDecoration; pCenterlineDecoration = new SimpleLineDecorationElementClass(); pCenterlineDecoration.AddPosition(1); pCenterlineDecoration.MarkerSymbol = arrowMarkerSymbol; pCenterlineDecoration.Rotate = true; //set line decoration ILineDecoration pLineDecoration; pLineDecoration = new LineDecorationClass(); pLineDecoration.AddElement(pCenterlineDecoration); //Set line properties ILineProperties lineProperties = (ILineProperties)pCartographicLineSymbol; lineProperties.LineDecoration = pLineDecoration; lineProperties.Flip = false; //Create Label LabelFeatures(pGeoFeatureLayer, "[L_LOW_HN] + \" - \" + [L_HIGH_HN]+ \" \" +[ST_NAME] + vbCrLf + [PHYSICALID]"); //Render features ISimpleRenderer pSimpleRenderer; pSimpleRenderer = new SimpleRenderer(); pSimpleRenderer.Symbol = (ISymbol)pCartographicLineSymbol; pGeoFeatureLayer.Renderer = (IFeatureRenderer)pSimpleRenderer; } else if (pFeatureLayer.Name == "Cadastral") { ILayer pLayer; pLayer = (ILayer)pFeatureLayer; IGeoFeatureLayer pGeoFeatureLayer; pGeoFeatureLayer = (IGeoFeatureLayer)pLayer; pGeoFeatureLayer.DisplayField = "BBL"; pGeoFeatureLayer.DisplayAnnotation = true; //Create ouline element ISimpleLineSymbol pOutline; pOutline = new SimpleLineSymbolClass(); pOutline.Color = SetColor(76, 230, 0); pOutline.Width = 2; //Create polygon with outline element ISimpleFillSymbol pTaxLotSymbol; pTaxLotSymbol = new SimpleFillSymbolClass(); pTaxLotSymbol.Style = esriSimpleFillStyle.esriSFSHollow; pTaxLotSymbol.Outline = pOutline; //Create label LabelFeatures(pGeoFeatureLayer, "\"BBL: \" + [BBL]"); //Render features ISimpleRenderer pSimpleRenderer; pSimpleRenderer = new SimpleRenderer(); pSimpleRenderer.Symbol = (ISymbol)pTaxLotSymbol; pGeoFeatureLayer.Renderer = (IFeatureRenderer)pSimpleRenderer; } else { pFeatureLayer.Visible = false; } }
/// <summary> /// 按聚类号对凸包进行渲染 /// </summary> /// <param name="pGeoFeatureLayer"></param> /// <param name="fieldName"></param> public void DefinePointUniqueValueRenderer(IGeoFeatureLayer pGeoFeatureLayer, string fieldName) { IRandomColorRamp pRandomColorRamp = new RandomColorRampClass(); //Create the color ramp for the symbols in the renderer. pRandomColorRamp.MinSaturation = 20; pRandomColorRamp.MaxSaturation = 40; pRandomColorRamp.MinValue = 85; pRandomColorRamp.MaxValue = 100; pRandomColorRamp.StartHue = 76; pRandomColorRamp.EndHue = 188; pRandomColorRamp.UseSeed = true; pRandomColorRamp.Seed = 43; //Create the renderer. IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass(); /* ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSimpleFillSymbol.Outline.Width = 0.4; */ ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pSimpleMarkerSymbol.Size = 5; pSimpleMarkerSymbol.Outline = true; IRgbColor pLineRgbColor = new RgbColorClass(); pLineRgbColor.Red = 0; pLineRgbColor.Green = 0; pLineRgbColor.Blue = 0; pSimpleMarkerSymbol.OutlineColor = pLineRgbColor as IColor; //These properties should be set prior to adding values. pUniqueValueRenderer.FieldCount = 1; pUniqueValueRenderer.set_Field(0, fieldName); pUniqueValueRenderer.DefaultSymbol = pSimpleMarkerSymbol as ISymbol; pUniqueValueRenderer.UseDefaultSymbol = true; IDisplayTable pDisplayTable = pGeoFeatureLayer as IDisplayTable; IFeatureCursor pFeatureCursor = pDisplayTable.SearchDisplayTable(null, false) as IFeatureCursor; IFeature pFeature = pFeatureCursor.NextFeature(); bool ValFound; int fieldIndex; IFields pFields = pFeatureCursor.Fields; fieldIndex = pFields.FindField(fieldName); while (pFeature != null) { /* ISimpleFillSymbol pClassSymbol = new SimpleFillSymbolClass(); pClassSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pClassSymbol.Outline.Width = 0.4; */ ISimpleMarkerSymbol pClassSymbol = new SimpleMarkerSymbolClass(); pClassSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; pClassSymbol.Size = 5; pClassSymbol.Outline = true; pClassSymbol.OutlineColor = pLineRgbColor as IColor; string classValue; classValue = pFeature.get_Value(fieldIndex).ToString(); //Test to see if this value was added to the renderer. If not, add it. ValFound = false; for (int i = 0; i <= pUniqueValueRenderer.ValueCount - 1; i++) { if (pUniqueValueRenderer.get_Value(i) == classValue) { ValFound = true; break; //Exit the loop if the value was found. } } //If the value was not found, it's new and will be added. if (ValFound == false) { pUniqueValueRenderer.AddValue(classValue, fieldName, pClassSymbol as ISymbol); pUniqueValueRenderer.set_Label(classValue, classValue); pUniqueValueRenderer.set_Symbol(classValue, pClassSymbol as ISymbol); } pFeature = pFeatureCursor.NextFeature(); } //Since the number of unique values is known, the color ramp can be sized and the colors assigned. pRandomColorRamp.Size = pUniqueValueRenderer.ValueCount; bool bOK; pRandomColorRamp.CreateRamp(out bOK); IEnumColors pEnumColors = pRandomColorRamp.Colors; pEnumColors.Reset(); for (int j = 0; j <= pUniqueValueRenderer.ValueCount - 1; j++) { string xv; xv = pUniqueValueRenderer.get_Value(j); if (xv != "") { ISimpleMarkerSymbol pSimpleMarkerColor = pUniqueValueRenderer.get_Symbol(xv) as ISimpleMarkerSymbol; pSimpleMarkerColor.Color = pEnumColors.Next(); pUniqueValueRenderer.set_Symbol(xv, pSimpleMarkerColor as ISymbol); } } pGeoFeatureLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer; pGeoFeatureLayer.DisplayField = fieldName; }