private void method_1(IEnumRelationshipClass ienumRelationshipClass_0, IObject iobject_0, TreeNode treeNode_0, bool bool_3) { ienumRelationshipClass_0.Reset(); for (IRelationshipClass class2 = ienumRelationshipClass_0.Next(); class2 != null; class2 = ienumRelationshipClass_0.Next()) { try { IObjectClass destinationClass; if (bool_3) { destinationClass = class2.DestinationClass; } else { destinationClass = class2.OriginClass; } TreeNode node = new TreeNode(destinationClass.AliasName) { Tag = destinationClass }; ISet objectsRelatedToObject = class2.GetObjectsRelatedToObject(iobject_0); objectsRelatedToObject.Reset(); for (IRowBuffer buffer = objectsRelatedToObject.Next() as IRowBuffer; buffer != null; buffer = objectsRelatedToObject.Next() as IRowBuffer) { TreeNode node2 = new TreeNode(buffer.get_Value(0).ToString()) { Tag = buffer }; node.Nodes.Add(node2); } if (node.Nodes.Count > 0) { treeNode_0.Nodes.Add(node); } } catch (Exception exception) { exception.ToString(); } } }
// 唯一值符号化 public static void UniqueValueRenderer(IFeatureLayer featureLayer, string fieldName, IMapControl2 mapControl, AxTOCControl tocControl) { ITable pTable = featureLayer as ITable; IUniqueValueRenderer pRenderer = new UniqueValueRendererClass(); pRenderer.FieldCount = 1; // 设置唯一值符号化的关键字段为一个 pRenderer.set_Field(0, fieldName); // 设置唯一值符号化的第一个关键字段 IRandomColorRamp pColorRamp = new RandomColorRampClass() { StartHue = 0, MinValue = 0, MinSaturation = 0, EndHue = 100, MaxValue = 100, MaxSaturation = 100 }; // 根据渲染字段的值的个数,设置一组随机颜色 pColorRamp.Size = featureLayer.FeatureClass.FeatureCount(new QueryFilterClass()); bool bSuccess = false; pColorRamp.CreateRamp(out bSuccess); IEnumColors pEnumColors = pColorRamp.Colors; IColor pNextUniqueColor = null; // 查询字段的值 IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField(fieldName); int fieldNumber = pTable.FindField(fieldName); // 获取渲染字段索引 ICursor pCursor = pTable.Search(pQueryFilter, true); IRow pNextRow = pCursor.NextRow(); object codeValue = null; IRowBuffer pNextRowBuffer = null; while (pNextRow != null) { pNextRowBuffer = pNextRow as IRowBuffer; // 获取渲染字段的每一个值 codeValue = pNextRowBuffer.get_Value(fieldNumber); pNextUniqueColor = pEnumColors.Next(); if (pNextUniqueColor == null) { pEnumColors.Reset(); pNextUniqueColor = pEnumColors.Next(); } ISymbol pSymbol = null; switch (featureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPolygon: pSymbol = new SimpleFillSymbolClass() { Color = pNextUniqueColor }; break; case esriGeometryType.esriGeometryPolyline: pSymbol = new SimpleLineSymbolClass() { Color = pNextUniqueColor }; break; case esriGeometryType.esriGeometryPoint: pSymbol = new SimpleMarkerSymbolClass() { Color = pNextUniqueColor }; break; } pRenderer.AddValue(codeValue.ToString(), "", pSymbol); pNextRow = pCursor.NextRow(); } (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer; mapControl.Refresh(); tocControl.Update(); }
private void mnuUniqueValue_Click(object sender, EventArgs e) { ILayer pLayer = MainMap.get_Layer(0); ITable pTable = pLayer as ITable; IUniqueValueRenderer pUniqueValueRender = new UniqueValueRendererClass(); pUniqueValueRender.FieldCount = 1; pUniqueValueRender.set_Field(0, "ADCODE99"); int fldIndex = pTable.Fields.FindField("ADCODE99"); // 产生一个随机的色带 IRandomColorRamp pColorRamp = new RandomColorRampClass(); pColorRamp.StartHue = 0; pColorRamp.MinValue = 99; pColorRamp.MinSaturation = 15; pColorRamp.EndHue = 360; pColorRamp.MaxValue = 100; pColorRamp.MinSaturation = 30; // 任意产生50种颜色 pColorRamp.Size = 50; bool bOK; pColorRamp.CreateRamp(out bOK); IEnumColors pEnumRamp = pColorRamp.Colors; IColor pNextUniqueColor = null; IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField("ADCODE99"); ICursor pCursor = pTable.Search(pQueryFilter, true); IRow pRow = pCursor.NextRow(); while (pRow != null) { IRowBuffer pRowBuffer = pRow as IRowBuffer; System.Object cValue = pRowBuffer.get_Value(fldIndex); pNextUniqueColor = pEnumRamp.Next(); if (pNextUniqueColor == null) { pEnumRamp.Reset(); pNextUniqueColor = pEnumRamp.Next(); } ISimpleFillSymbol pSym = new SimpleFillSymbolClass(); pSym.Color = pNextUniqueColor; pUniqueValueRender.AddValue(cValue.ToString(), "", pSym as ISymbol); pRow = pCursor.NextRow(); } IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer; pGeoFeatureLayer.Renderer = pUniqueValueRender as IFeatureRenderer; MainMap.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
// 唯一值符号化 public static void Symbology_UniqueValue(IFeatureLayer featureLayer, string fieldName, IMapControl2 mapControl, AxTOCControl tocControl) { IUniqueValueRenderer pRenderer = new UniqueValueRendererClass() { FieldCount = 1 }; // 随机色带 IColorRamp pColorRamp = new RandomColorRampClass() { StartHue = 0, MinSaturation = 0, MinValue = 0, EndHue = 360, MaxSaturation = 100, MaxValue = 100, Size = featureLayer.FeatureClass.FeatureCount(new QueryFilterClass()) }; bool bOk = false; pColorRamp.CreateRamp(out bOk); IEnumColors pColors = pColorRamp.Colors; ITable pTable = featureLayer as ITable; int fieldIndex = pTable.FindField(fieldName); IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField(fieldName); ICursor pCursor = pTable.Search(pQueryFilter, true); IRow pRow = pCursor.NextRow(); while (pRow != null) { IRowBuffer pRowBuffer = pRow as IRowBuffer; string value = pRowBuffer.get_Value(fieldIndex).ToString(); IColor pColor = pColors.Next(); ISymbol pSymbol = null; switch (featureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: pSymbol = new SimpleMarkerSymbolClass() { Color = pColor }; break; case esriGeometryType.esriGeometryPolyline: pSymbol = new SimpleLineSymbolClass() { Color = pColor }; break; case esriGeometryType.esriGeometryPolygon: pSymbol = new SimpleFillSymbolClass() { Color = pColor }; break; } pRenderer.AddValue(value, "", pSymbol); pRow = pCursor.NextRow(); } (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer; mapControl.Refresh(); tocControl.Update(); }
/// <summary> /// 实现要素图层属性唯一值设色 /// </summary> /// <param name="pFeatureLayer">需要设色的要素图层</param> /// <param name="fieldName">唯一值的属性字段</param> private void UniqueValueRenderer(IFeatureLayer pFeatureLayer, string fieldName) { IGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer as IGeoFeatureLayer; ITable pTable = pFeatureLayer as ITable; int fieldNumber = pTable.FindField(fieldName); IUniqueValueRenderer pUniqueRenderer = new UniqueValueRendererClass(); pUniqueRenderer.FieldCount = 1; pUniqueRenderer.set_Field(0, fieldName); //设置显示颜色的范围 IRandomColorRamp pRandColorRamp = new RandomColorRampClass(); pRandColorRamp.StartHue = 0; pRandColorRamp.MinValue = 85; pRandColorRamp.MinSaturation = 15; pRandColorRamp.EndHue = 360; pRandColorRamp.MaxValue = 100; pRandColorRamp.MaxSaturation = 30; //创建随机颜色带 pRandColorRamp.Size = getUniqueValue(pFeatureLayer.FeatureClass, fieldName).Count; bool bSucess = false; pRandColorRamp.CreateRamp(out bSucess); IEnumColors pEnumColors = pRandColorRamp.Colors; IColor pNextUniqueColor = null; //属性唯一值 IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField(fieldName); ICursor pCursor = pFeatureLayer.FeatureClass.Search(pQueryFilter, false) as ICursor; IRow pNextRow = pCursor.NextRow(); object codeValue = null; IRowBuffer pNextRowBuffer = null; IFillSymbol pFillSymbol = null; ILineSymbol pLineSymbol = null; IMarkerSymbol pMarkerSymbol = null; while (pNextRow != null) { pNextRowBuffer = pNextRow as IRowBuffer; codeValue = pNextRowBuffer.get_Value(fieldNumber); pNextUniqueColor = pEnumColors.Next(); if (pNextUniqueColor == null) { pEnumColors.Reset(); pNextUniqueColor = pEnumColors.Next(); } switch (pGeoFeatureLayer.FeatureClass.ShapeType) { case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint: pMarkerSymbol = new SimpleMarkerSymbolClass(); pMarkerSymbol.Color = pNextUniqueColor; pUniqueRenderer.AddValue(codeValue.ToString(), "", pMarkerSymbol as ISymbol); pNextRow = pCursor.NextRow(); break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline: pLineSymbol = new SimpleLineSymbolClass(); pLineSymbol.Color = pNextUniqueColor; pUniqueRenderer.AddValue(codeValue.ToString(), "", pLineSymbol as ISymbol); pNextRow = pCursor.NextRow(); break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon: pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = pNextUniqueColor; pUniqueRenderer.AddValue(codeValue.ToString(), "", pFillSymbol as ISymbol); pNextRow = pCursor.NextRow(); int k = pFillSymbol.Color.CMYK; break; default: break; } } pGeoFeatureLayer.Renderer = pUniqueRenderer as IFeatureRenderer; //必须手动清除COM对象,否则会造成内存溢出(尤其是IQueryFilter,ICursor) Marshal.ReleaseComObject(pQueryFilter); Marshal.ReleaseComObject(pCursor); Marshal.ReleaseComObject(pEnumColors); }
private void btn_OK_Click(object sender, EventArgs e) { string LayerName = cbx_Layer.SelectedItem.ToString(); IGeoFeatureLayer pGeoFeatureLayer = (IGeoFeatureLayer)m_FeatureLayer; ITable pTable = (ITable)pGeoFeatureLayer; ICursor pCursor = pTable.Search(null, true); int numFields = lstbx_RightFields.Items.Count; string[] fildName = new string[numFields]; int[] fieldIndecies = new int[numFields]; for (int i = 0; i < numFields; i++) { if (lstbx_RightFields.Items[i].ToString() != "None") { fildName[i] = lstbx_RightFields.Items[i].ToString(); fieldIndecies[i] = pTable.FindField(fildName[i]); } else { MessageBox.Show("不可用的字段,请选择其它图层"); return; } } //fieldIndecies[0] = pTable.FindField(strPopField1); //fieldIndecies[1] = pTable.FindField(strPopField2); bool firstValue = true; double dmaxValue = 0.0; //Iterate across each feature IRowBuffer pRowBuffer = pCursor.NextRow(); double dfieldValue; while (pRowBuffer != null) { // iterate through each data field and update the maxVal if needed for (int lfieldIndex = 0; lfieldIndex <= numFields - 1; lfieldIndex++) { dfieldValue = (double)pRowBuffer.get_Value(fieldIndecies[lfieldIndex]); if (firstValue) { // Special case for the first value in a feature class dmaxValue = dfieldValue; firstValue = false; } else { if (dfieldValue > dmaxValue) { // we've got a new biggest value dmaxValue = dfieldValue; } } } pRowBuffer = pCursor.NextRow(); } if (dmaxValue <= 0) { MessageBox.Show("Failed to gather stats on the feature class"); return; } IChartRenderer pChartRenderer = new ChartRendererClass(); //Set up the fields to draw charts of IRendererFields pRendererFields = (IRendererFields)pChartRenderer; for (int i = 0; i < numFields; i++) { pRendererFields.AddField(fildName[i], fildName[i]); } // Set up the chart marker symbol to use with the renderer IPieChartSymbol pPieChartSymbol; pPieChartSymbol = new PieChartSymbolClass(); //饼图使用顺时针方法 pPieChartSymbol.Clockwise = true; //饼图有外轮廓线 pPieChartSymbol.UseOutline = true; IChartSymbol pChartSymbol = (IChartSymbol)pPieChartSymbol; pChartSymbol.MaxValue = dmaxValue; ILineSymbol pOutline; pOutline = new SimpleLineSymbolClass(); pOutline.Color = getRGB(213, 212, 252); pOutline.Width = 1; //设置外轮廓线的样式 pPieChartSymbol.Outline = pOutline; IMarkerSymbol pMarkerSymbol = (IMarkerSymbol)pPieChartSymbol; pMarkerSymbol.Size = 8; IColorRamp pColorRamp = (IColorRamp)m_StyleGallertItem.Item; pColorRamp.Size = pTable.RowCount(null); bool ok = true; pColorRamp.CreateRamp(out ok); IEnumColors pEnumRamp = pColorRamp.Colors; IFillSymbol pFillSymbol; ISymbolArray pSymbolArray = (ISymbolArray)pPieChartSymbol; for (int i = 0; i < numFields; i++) { pFillSymbol = new SimpleFillSymbolClass(); for (int j = 0; j < 8; j++) { pEnumRamp.Next(); } pFillSymbol.Color = pEnumRamp.Next(); pSymbolArray.AddSymbol((ISymbol)pFillSymbol); } //Now set the barchart symbol into the renderer pChartRenderer.ChartSymbol = (IChartSymbol)pPieChartSymbol; // pChartRenderer.Label = "Population"; //set up the background symbol to use tan color pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = m_BackGroundColor; pChartRenderer.BaseSymbol = (ISymbol)pFillSymbol; pChartRenderer.UseOverposter = false; IPieChartRenderer pPieChartRenderer = pChartRenderer as IPieChartRenderer; pPieChartRenderer.MinSize = 3; //设置最小值,用于尺寸比例 pPieChartRenderer.MinValue = 453588; pPieChartRenderer.FlanneryCompensation = false; pPieChartRenderer.ProportionalBySum = true; //pChartRenderer.Label = "Population"; //产生图例对象 pChartRenderer.CreateLegend(); //pdate the renderer and refresh the screen pGeoFeatureLayer.Renderer = (IFeatureRenderer)pChartRenderer; m_MapControl.ActiveView.ContentsChanged(); m_MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }