private void btn_OK_Click(object sender, EventArgs e) { string FieldName = cbx_Field.SelectedItem.ToString(); if (FieldName == "None") { MessageBox.Show("不可用字段,请选择其它图层"); return; } IGeoFeatureLayer pGeoFeatureLayer = (IGeoFeatureLayer)m_FeatureLayer; pGeoFeatureLayer.ScaleSymbols = true; ITable pTable = (ITable)pGeoFeatureLayer; ICursor pCursor = pTable.Search(null, true); IDataStatistics pDataStatistics = new DataStatisticsClass(); pDataStatistics.Cursor = pCursor; //Set statistical field pDataStatistics.Field = FieldName; //Get the result of statistics IStatisticsResults pStatisticsResult = pDataStatistics.Statistics; if (pStatisticsResult == null) { MessageBox.Show("Failed to gather stats on the feature class"); return; } IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); // pFillSymbol.Color = m_BackGroundColor; IMarkerSymbol pCharaterMarkerS = new CharacterMarkerSymbolClass(); pCharaterMarkerS = (IMarkerSymbol)m_StyleGallertItem.Item; pCharaterMarkerS.Size = (int)numericUpDown1.Value; pCharaterMarkerS.Color = m_BackGroundColor; IProportionalSymbolRenderer pProportionalSymbolR = new ProportionalSymbolRendererClass(); pProportionalSymbolR.ValueUnit = esriUnits.esriUnknownUnits; pProportionalSymbolR.Field = FieldName; pProportionalSymbolR.FlanneryCompensation = false; pProportionalSymbolR.MinDataValue = pStatisticsResult.Minimum; pProportionalSymbolR.MaxDataValue = pStatisticsResult.Maximum; pProportionalSymbolR.BackgroundSymbol = pFillSymbol; pProportionalSymbolR.MinSymbol = (ISymbol)pCharaterMarkerS; pProportionalSymbolR.LegendSymbolCount = 5; pProportionalSymbolR.CreateLegendSymbols(); IRotationRenderer pRotationRenderer = (IRotationRenderer)pProportionalSymbolR; pRotationRenderer.RotationField = FieldName; pRotationRenderer.RotationType = esriSymbolRotationType.esriRotateSymbolGeographic; //Set the states layer renderer to the proportional symbol renderer and refresh the display pGeoFeatureLayer.Renderer = (IFeatureRenderer)pProportionalSymbolR; m_MapControl.ActiveView.ContentsChanged(); m_MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
public static void Symbology_Proportional(IFeatureLayer featureLayer, string fieldName, IMapControl2 mapControl, AxTOCControl tocControl) { // 获取渲染字段统计值 IStatisticsResults pStatResult = GetDataSataResults(featureLayer, fieldName); // 比例符号渲染 if (pStatResult != null) { IFillSymbol pFillSymbol = new SimpleFillSymbolClass() { Color = GetRgbColor(155, 255, 0) }; ISymbol pMarkerSymbol = new SimpleMarkerSymbolClass() { Style = esriSimpleMarkerStyle.esriSMSDiamond, Size = 3, Color = GetRgbColor(255, 90, 0) }; IProportionalSymbolRenderer pRenderer = new ProportionalSymbolRendererClass() { ValueUnit = esriUnits.esriUnknownUnits, // 渲染单位 Field = fieldName, // 渲染字段 FlanneryCompensation = false, MinDataValue = pStatResult.Minimum, // 最小值 MaxDataValue = pStatResult.Maximum, // 最大值 BackgroundSymbol = pFillSymbol, // 背景颜色 MinSymbol = pMarkerSymbol, // 最小渲染符号 LegendSymbolCount = 5 // TOC控件中的显示条目 }; pRenderer.CreateLegendSymbols(); (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer; mapControl.Refresh(); tocControl.Update(); } }
private static void MapUsingProportionalSymbolRenderer() { ISimpleMarkerSymbol marker = new SimpleMarkerSymbol(); marker.Style = esriSimpleMarkerStyle.esriSMSCircle; ICmykColor markerColor = ColorbrewerExtension.GetSingleCMYKColor(); marker.Size = 10; marker.Color = markerColor; IMxDocument mxDoc = ArcMap.Application.Document as IMxDocument; IMap map = mxDoc.FocusMap; string layerName = CboLayers.GetSelectedLayer(); ILayer layer = GetLayerByName(layerName); IFeatureLayer fLayer = layer as IFeatureLayer; IFeatureClass fClass = fLayer.FeatureClass as IFeatureClass; IFeatureCursor cursor = fClass.Search(null, true); IDataStatistics dataStats = new DataStatisticsClass(); dataStats.Cursor = cursor as ICursor; string fieldName = CboFields.GetSelectedField(); dataStats.Field = fieldName; IStatisticsResults statResult = dataStats.Statistics; IProportionalSymbolRenderer propSymRenderer = new ProportionalSymbolRendererClass(); propSymRenderer.Field = fieldName; propSymRenderer.MinDataValue = statResult.Minimum == 0.0 ? 1 : statResult.Minimum; propSymRenderer.MaxDataValue = statResult.Maximum; propSymRenderer.FlanneryCompensation = true; propSymRenderer.ValueUnit = esriUnits.esriUnknownUnits; propSymRenderer.MinSymbol = marker as ISymbol; propSymRenderer.LegendSymbolCount = 3; propSymRenderer.CreateLegendSymbols(); IGeoFeatureLayer gFLayer = layer as IGeoFeatureLayer; gFLayer.Renderer = propSymRenderer as IFeatureRenderer; mxDoc.ActiveView.Refresh(); mxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, gFLayer , mxDoc.ActiveView.Extent); mxDoc.UpdateContents(); }
private IProportionalSymbolRenderer CreateRenderer() { IGeoFeatureLayer pGeoFeatureLayer = (IGeoFeatureLayer)layer2Symbolize; ITable pTable = (ITable)pGeoFeatureLayer; ICursor pCursor = pTable.Search(null, false); //Use the statistics objects to calculate the max value and the min value IDataStatistics pDataStatistics = new DataStatisticsClass(); pDataStatistics.Cursor = pCursor; //Set statistical field pDataStatistics.Field = strRendererField; //Get the result of statistics IStatisticsResults pStatisticsResult = pDataStatistics.Statistics; if (pStatisticsResult == null) { return(null); } if (markerSymbol == null) { MessageBox.Show("请先选择点符号...", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } if (fillSymbol == null) { MessageBox.Show("请先选择背景...", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } markerSymbol.Size = minSize; // Create a new proportional symbol renderer to draw pop1990 IProportionalSymbolRenderer pProportionalSymbolR = new ProportionalSymbolRendererClass(); pProportionalSymbolR.Field = strRendererField; if (strNormalizeField.ToLower() != "none") { pProportionalSymbolR.NormField = strNormalizeField; } pProportionalSymbolR.MinDataValue = pStatisticsResult.Minimum; pProportionalSymbolR.MaxDataValue = pStatisticsResult.Maximum; pProportionalSymbolR.BackgroundSymbol = fillSymbol; pProportionalSymbolR.MinSymbol = (ISymbol)markerSymbol; pProportionalSymbolR.LegendSymbolCount = legendCount; pProportionalSymbolR.CreateLegendSymbols(); return(pProportionalSymbolR); }
//ProportionalSymbolRenderer private void button4_Click(object sender, EventArgs e) { IGeoFeatureLayer geoFeatureLayer; IFeatureLayer featureLayer; IProportionalSymbolRenderer proportionalSymbolRenderer; ITable table; ICursor cursor; IDataStatistics dataStatistics; IStatisticsResults statisticsResult; stdole.IFontDisp fontDisp; geoFeatureLayer = getGeoLayer("Continents"); featureLayer = geoFeatureLayer as IFeatureLayer; table = geoFeatureLayer as ITable; cursor = table.Search(null, true); dataStatistics = new DataStatisticsClass(); dataStatistics.Cursor = cursor; dataStatistics.Field = "sqmi"; statisticsResult = dataStatistics.Statistics; if (statisticsResult != null) { IFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = getRGB(0, 255, 0); ICharacterMarkerSymbol characterMarkerSymbol = new CharacterMarkerSymbolClass(); fontDisp = new stdole.StdFontClass() as stdole.IFontDisp; fontDisp.Name = "arial"; fontDisp.Size = 20; characterMarkerSymbol.Font = fontDisp; characterMarkerSymbol.CharacterIndex = 90; characterMarkerSymbol.Color = getRGB(255, 0, 0); characterMarkerSymbol.Size = 8; proportionalSymbolRenderer = new ProportionalSymbolRendererClass(); proportionalSymbolRenderer.ValueUnit = esriUnits.esriUnknownUnits; proportionalSymbolRenderer.Field = "sqmi"; proportionalSymbolRenderer.FlanneryCompensation = false; proportionalSymbolRenderer.MinDataValue = statisticsResult.Minimum; proportionalSymbolRenderer.MaxDataValue = statisticsResult.Maximum; proportionalSymbolRenderer.BackgroundSymbol = fillSymbol; proportionalSymbolRenderer.MinSymbol = characterMarkerSymbol as ISymbol; proportionalSymbolRenderer.LegendSymbolCount = 10; proportionalSymbolRenderer.CreateLegendSymbols(); geoFeatureLayer.Renderer = proportionalSymbolRenderer as IFeatureRenderer; } this.axMapControl1.Refresh(); }
public void ProportionalRenderer1(IFeatureLayer featLayer, string fieldName, IColorRamp colorRamp, int size) { IGeoFeatureLayer geoFeatureLayer; IFeatureLayer featureLayer; IProportionalSymbolRenderer proportionalSymbolRenderer; ITable table; ICursor cursor; IDataStatistics dataStatistics; IStatisticsResults statisticsResult; stdole.IFontDisp fontDisp; geoFeatureLayer = featLayer as IGeoFeatureLayer; featureLayer = geoFeatureLayer as IFeatureLayer; table = geoFeatureLayer as ITable; cursor = table.Search(null, true); dataStatistics = new DataStatisticsClass(); dataStatistics.Cursor = cursor; dataStatistics.Field = fieldName; statisticsResult = dataStatistics.Statistics; if (statisticsResult != null) { IFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = colorRamp.get_Color(0); ICharacterMarkerSymbol characterMarkerSymbol = new CharacterMarkerSymbolClass(); fontDisp = new stdole.StdFontClass() as stdole.IFontDisp; fontDisp.Name = "arial"; fontDisp.Size = 20; characterMarkerSymbol.Font = fontDisp; characterMarkerSymbol.CharacterIndex = 90; characterMarkerSymbol.Color = colorRamp.get_Color(4); characterMarkerSymbol.Size = size; proportionalSymbolRenderer = new ProportionalSymbolRendererClass(); proportionalSymbolRenderer.ValueUnit = esriUnits.esriUnknownUnits; proportionalSymbolRenderer.Field = fieldName; proportionalSymbolRenderer.FlanneryCompensation = false; proportionalSymbolRenderer.MinDataValue = statisticsResult.Minimum; proportionalSymbolRenderer.MaxDataValue = statisticsResult.Maximum; proportionalSymbolRenderer.BackgroundSymbol = fillSymbol; proportionalSymbolRenderer.MinSymbol = characterMarkerSymbol as ISymbol; proportionalSymbolRenderer.LegendSymbolCount = 10; proportionalSymbolRenderer.CreateLegendSymbols(); geoFeatureLayer.Renderer = proportionalSymbolRenderer as IFeatureRenderer; } }
public static void ProportionalRenderer(IFeatureLayer featLayer, string fieldName, IColor pColor, double count) { IProportionalSymbolRenderer psrender = new ProportionalSymbolRendererClass(); psrender.Field = fieldName; psrender.ValueUnit = esriUnits.esriUnknownUnits; psrender.ValueRepresentation = esriValueRepresentations.esriValueRepUnknown; //选择渲染的样式,与颜色 minsymbol为比填内容,否则没有效果 ISimpleMarkerSymbol markersym = new SimpleMarkerSymbol(); markersym.Size = count; markersym.Style = esriSimpleMarkerStyle.esriSMSCircle; markersym.Color = pColor; psrender.MinSymbol = markersym as ISymbol; //IFeatureLayer featLayer = featLayer; IGeoFeatureLayer geofeat = featLayer as IGeoFeatureLayer; ICursor cursor = ((ITable)featLayer).Search(null, true); IDataStatistics datastat = new DataStatisticsClass(); datastat.Cursor = cursor; datastat.Field = fieldName;//千万不能忽视 IStatisticsResults statisticsResult; try { statisticsResult = datastat.Statistics; psrender.MinDataValue = statisticsResult.Minimum + 0.1; psrender.MaxDataValue = statisticsResult.Maximum; ////设置background的样式 IFillSymbol fillsym = new SimpleFillSymbolClass(); fillsym.Color = getcolor(201, 201, 251); ILineSymbol linesym = new SimpleLineSymbolClass(); linesym.Width = 1; fillsym.Outline = linesym; psrender.BackgroundSymbol = fillsym; psrender.LegendSymbolCount = 6; //legend的数量 psrender.CreateLegendSymbols(); //创建TOC的legend geofeat.Renderer = (IFeatureRenderer)psrender; } catch { XtraMessageBox.Show("错误,选择的属性不是数值型!"); } }
/// <summary> /// Symbol Render /// </summary> /// <param name="currentLayer"></param> /// <param name="breakCount"></param> /// <author>Shen Yongyuan</author> /// <date>20091114</date> public static void SymbolRender(ILayer currentLayer, string fieldName) { IGeoFeatureLayer pGeoFeatureL = currentLayer as IGeoFeatureLayer; pGeoFeatureL.ScaleSymbols = true; //Use the statistics objects to calculate the max value and the min value IFeatureCursor pCursor = pGeoFeatureL.DisplayFeatureClass.Search(null, true); IDataStatistics pDataStatistics = new DataStatisticsClass(); pDataStatistics.Cursor = pCursor as ICursor; pDataStatistics.Field = fieldName; IStatisticsResults pStatisticsResult = pDataStatistics.Statistics; IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.FromArgb(239, 228, 190)); ICharacterMarkerSymbol pCharaterMarkerS = new CharacterMarkerSymbolClass(); stdole.StdFont pFontDisp = new stdole.StdFontClass(); pFontDisp.Name = "ESRI Default Marker"; pFontDisp.Size = 30; pCharaterMarkerS.Font = (IFontDisp)pFontDisp; pCharaterMarkerS.CharacterIndex = 81; pCharaterMarkerS.Color = ArcGIS.Color.ToEsriColor(System.Drawing.Color.FromArgb(255, 0, 0)); pCharaterMarkerS.Size = 30; IProportionalSymbolRenderer pProportionalSymbolR = new ProportionalSymbolRendererClass(); pProportionalSymbolR.ValueUnit = esriUnits.esriUnknownUnits; pProportionalSymbolR.Field = fieldName; pProportionalSymbolR.FlanneryCompensation = false; pProportionalSymbolR.MinDataValue = pStatisticsResult.Minimum; pProportionalSymbolR.MaxDataValue = pStatisticsResult.Maximum; pProportionalSymbolR.BackgroundSymbol = pFillSymbol; pProportionalSymbolR.MinSymbol = (ISymbol)pCharaterMarkerS; pProportionalSymbolR.LegendSymbolCount = 12; pProportionalSymbolR.CreateLegendSymbols(); pGeoFeatureL.Renderer = (IFeatureRenderer)pProportionalSymbolR; }
// 比例符号化 public static void Proportional(IFeatureLayer featureLayer, string fieldName, IMapControl2 mapControl, AxTOCControl tocControl) { ITable pTable = featureLayer as ITable; ICursor pCursor = pTable.Search(null, false); // 利用IDataStatistics和IStatisticsResults获取渲染字段的统计值(最大值 and 最小值) IDataStatistics pDataStat = new DataStatisticsClass() { Cursor = pCursor, Field = fieldName }; IStatisticsResults pStatResult = pDataStat.Statistics; if (pStatResult != null) { // 设置渲染背景色 IFillSymbol pFillSymbol = new SimpleFillSymbolClass() { Color = GetRgbColor(155, 255, 0) }; ISimpleMarkerSymbol pSimpleMaskerSymbol = new SimpleMarkerSymbolClass() { Style = esriSimpleMarkerStyle.esriSMSDiamond, Size = 3, Color = GetRgbColor(255, 90, 0) }; IProportionalSymbolRenderer pRenderer = new ProportionalSymbolRendererClass() { ValueUnit = esriUnits.esriUnknownUnits, // 渲染单位 Field = fieldName, // 渲染字段 FlanneryCompensation = false, // 是否使用Flannery补偿 MinDataValue = pStatResult.Minimum, // 获取渲染字段的最小值 MaxDataValue = pStatResult.Maximum, // 获取渲染字段的最大值 BackgroundSymbol = pFillSymbol, MinSymbol = pSimpleMaskerSymbol as ISymbol, // 渲染字段最小值的渲染符号 LegendSymbolCount = 5 // 设置TOC控件中的显示条目 }; pRenderer.CreateLegendSymbols(); // 生成图例 (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer; } mapControl.Refresh(); tocControl.Update(); }
public void LayerRender() { try { IProportionalSymbolRenderer psrender = new ProportionalSymbolRendererClass(); psrender.Field = fieldName; psrender.ValueUnit = esriUnits.esriUnknownUnits; psrender.ValueRepresentation = esriValueRepresentations.esriValueRepUnknown; //选择渲染的样式,与颜色 minsymbol为比填内容,否则没有效果 ISimpleMarkerSymbol markersym = new SimpleMarkerSymbol(); markersym.Size = size; markersym.Style = esriSimpleMarkerStyle.esriSMSCircle; markersym.Color = color; psrender.MinSymbol = markersym as ISymbol; //IFeatureLayer featLayer = featLayer; IGeoFeatureLayer geofeat = featLayer as IGeoFeatureLayer; ICursor cursor = ((ITable)featLayer).Search(null, true); IDataStatistics datastat = new DataStatisticsClass(); datastat.Cursor = cursor; datastat.Field = fieldName;//千万不能忽视 psrender.MinDataValue = datastat.Statistics.Minimum; psrender.MaxDataValue = datastat.Statistics.Maximum; ////设置background的样式 IFillSymbol fillsym = new SimpleFillSymbolClass(); fillsym.Color = getcolor(201, 201, 251); ILineSymbol linesym = new SimpleLineSymbolClass(); linesym.Width = 1; fillsym.Outline = linesym; psrender.BackgroundSymbol = fillsym; psrender.LegendSymbolCount = 5; //legend的数量 psrender.CreateLegendSymbols(); //创建TOC的legend geofeat.Renderer = (IFeatureRenderer)psrender; axmapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); axtoccontrol.Update(); } catch (Exception e) { MessageBox.Show(e.Message); } }
private void btnApply_Click(object sender, EventArgs e) { try { string strLayerName = cboSourceLayer.Text; if (cboSourceLayer.Text == "" || cboValueField.Text == "" || cboUField.Text == "") { MessageBox.Show("Assign proper layer and field"); return; } int intLIndex = pSnippet.GetIndexNumberFromLayerName(pActiveView, strLayerName); ILayer pLayer = mForm.axMapControl1.get_Layer(intLIndex); IFeatureLayer pFLayer = pLayer as IFeatureLayer; IFeatureClass pFClass = pFLayer.FeatureClass; //Create Rendering of Mean Value at Target Layer int intGCBreakeCount = Convert.ToInt32(nudGCNClasses.Value); string strGCRenderField = cboValueField.Text; IGeoFeatureLayer pGeofeatureLayer; if (chkNewLayer.Checked == true) { IFeatureLayer pflOutput = new FeatureLayerClass(); pflOutput.FeatureClass = pFClass; pflOutput.Name = txtNewLayer.Text; pflOutput.Visible = true; pGeofeatureLayer = (IGeoFeatureLayer)pflOutput; } else { pGeofeatureLayer = (IGeoFeatureLayer)pFLayer; } ITable pTable = (ITable)pFClass; IClassifyGEN pClassifyGEN; switch (cboGCClassify.Text) { case "Equal Interval": pClassifyGEN = new EqualIntervalClass(); break; case "Geometrical Interval": pClassifyGEN = new GeometricalInterval(); break; case "Natural Breaks": pClassifyGEN = new NaturalBreaksClass(); break; case "Quantile": pClassifyGEN = new QuantileClass(); break; case "StandardDeviation": pClassifyGEN = new StandardDeviationClass(); break; default: pClassifyGEN = new NaturalBreaksClass(); break; } //Need to be changed 1/29/15 ITableHistogram pTableHistogram = new BasicTableHistogramClass(); pTableHistogram.Field = strGCRenderField; pTableHistogram.Table = pTable; IBasicHistogram pHistogram = (IBasicHistogram)pTableHistogram; object xVals, frqs; pHistogram.GetHistogram(out xVals, out frqs); pClassifyGEN.Classify(xVals, frqs, intGCBreakeCount); ClassBreaksRenderer pRender = new ClassBreaksRenderer(); double[] cb = (double[])pClassifyGEN.ClassBreaks; pRender.Field = strGCRenderField; pRender.BreakCount = intGCBreakeCount; pRender.MinimumBreak = cb[0]; //' create our color ramp IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass(); pColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm; IRgbColor pColor1 = new RgbColor(); IRgbColor pColor2 = new RgbColor(); //Can Change the color in here! pColor1.Red = picSymolfrom.BackColor.R; pColor1.Green = picSymolfrom.BackColor.G; pColor1.Blue = picSymolfrom.BackColor.B; Boolean blnOK = true; pColor2.Red = picSymbolTo.BackColor.R; pColor2.Green = picSymbolTo.BackColor.G; pColor2.Blue = picSymbolTo.BackColor.B; pColorRamp.FromColor = pColor1; pColorRamp.ToColor = pColor2; pColorRamp.Size = intGCBreakeCount; pColorRamp.CreateRamp(out blnOK); IEnumColors pEnumColors = pColorRamp.Colors; pEnumColors.Reset(); IRgbColor pColorOutline = new RgbColor(); //Can Change the color in here! pColorOutline.Red = picGCLineColor.BackColor.R; pColorOutline.Green = picGCLineColor.BackColor.G; pColorOutline.Blue = picGCLineColor.BackColor.B; double dblGCOutlineSize = Convert.ToDouble(nudGCLinewidth.Value); ICartographicLineSymbol pOutLines = new CartographicLineSymbol(); pOutLines.Width = dblGCOutlineSize; pOutLines.Color = (IColor)pColorOutline; //' use this interface to set dialog properties IClassBreaksUIProperties pUIProperties = (IClassBreaksUIProperties)pRender; pUIProperties.ColorRamp = "Custom"; ISimpleFillSymbol pSimpleFillSym; //' be careful, indices are different for the diff lists for (int j = 0; j < intGCBreakeCount; j++) { pRender.Break[j] = cb[j + 1]; pRender.Label[j] = Math.Round(cb[j], 2).ToString() + " - " + Math.Round(cb[j + 1], 2).ToString(); pUIProperties.LowBreak[j] = cb[j]; pSimpleFillSym = new SimpleFillSymbolClass(); pSimpleFillSym.Color = pEnumColors.Next(); pSimpleFillSym.Outline = pOutLines; pRender.Symbol[j] = (ISymbol)pSimpleFillSym; } pGeofeatureLayer.Renderer = (IFeatureRenderer)pRender; if (chkNewLayer.Checked == true) { mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGeofeatureLayer); } ////* Uncertainty Part *//// //Declare variables in if parts if (tcUncern.SelectedIndex == 0) //Graduated Color { int intUncernBreakCount = Convert.ToInt32(nudCoNClasses.Value); string strUncerFieldName = cboUField.Text; IFeatureLayer pflUncern = new FeatureLayerClass(); pflUncern.FeatureClass = pFClass; pflUncern.Name = cboSourceLayer.Text + " Uncertainty"; pflUncern.Visible = true; IGeoFeatureLayer pGFLUncern = (IGeoFeatureLayer)pflUncern; switch (cboTeClassify.Text) { case "Equal Interval": pClassifyGEN = new EqualIntervalClass(); break; case "Geometrical Interval": pClassifyGEN = new GeometricalInterval(); break; case "Natural Breaks": pClassifyGEN = new NaturalBreaksClass(); break; case "Quantile": pClassifyGEN = new QuantileClass(); break; case "StandardDeviation": pClassifyGEN = new StandardDeviationClass(); break; default: pClassifyGEN = new NaturalBreaksClass(); break; } //Need to be changed 1/29/15 pTableHistogram = new BasicTableHistogramClass(); pTableHistogram.Field = strUncerFieldName; pTableHistogram.Table = pTable; pHistogram = (IBasicHistogram)pTableHistogram; pHistogram.GetHistogram(out xVals, out frqs); pClassifyGEN.Classify(xVals, frqs, intUncernBreakCount); pRender = new ClassBreaksRenderer(); cb = (double[])pClassifyGEN.ClassBreaks; pRender.Field = strUncerFieldName; pRender.BreakCount = intUncernBreakCount; pRender.MinimumBreak = cb[0]; IClassBreaksUIProperties pUIColProperties = (IClassBreaksUIProperties)pRender; pUIColProperties.ColorRamp = "Custom"; pColorRamp = new AlgorithmicColorRampClass(); pColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm; pColor1 = new RgbColor(); pColor2 = new RgbColor(); //Can Change the color in here! pColor1 = pSnippet.getRGB(picCoColorFrom.BackColor.R, picCoColorFrom.BackColor.G, picCoColorFrom.BackColor.B); pColor2 = pSnippet.getRGB(picCoColorTo.BackColor.R, picCoColorTo.BackColor.G, picCoColorTo.BackColor.B); if (pColor1 == null || pColor2 == null) { return; } blnOK = true; pColorRamp.FromColor = pColor1; pColorRamp.ToColor = pColor2; pColorRamp.Size = intUncernBreakCount; pColorRamp.CreateRamp(out blnOK); pEnumColors = pColorRamp.Colors; pEnumColors.Reset(); pColorOutline = pSnippet.getRGB(picCoLineColor.BackColor.R, picCoLineColor.BackColor.G, picCoLineColor.BackColor.B); if (pColorOutline == null) { return; } double dblCoOutlineSize = Convert.ToDouble(nudCoLinewidth.Value); pOutLines = new CartographicLineSymbol(); pOutLines.Width = dblCoOutlineSize; pOutLines.Color = (IColor)pColorOutline; //' use this interface to set dialog properties pUIColProperties = (IClassBreaksUIProperties)pRender; pUIColProperties.ColorRamp = "Custom"; ISimpleMarkerSymbol pSimpleMarkerSym; double dblCoSymSize = Convert.ToDouble(nudCoSymbolSize.Value); //' be careful, indices are different for the diff lists for (int j = 0; j < intUncernBreakCount; j++) { pRender.Break[j] = cb[j + 1]; pRender.Label[j] = Math.Round(cb[j], 2).ToString() + " - " + Math.Round(cb[j + 1], 2).ToString(); pUIColProperties.LowBreak[j] = cb[j]; pSimpleMarkerSym = new SimpleMarkerSymbolClass(); pSimpleMarkerSym.Size = dblCoSymSize; pSimpleMarkerSym.Color = pEnumColors.Next(); pSimpleMarkerSym.Outline = true; pSimpleMarkerSym.OutlineColor = pColorOutline; pSimpleMarkerSym.OutlineSize = dblCoOutlineSize; pRender.Symbol[j] = (ISymbol)pSimpleMarkerSym; } pGFLUncern.Renderer = (IFeatureRenderer)pRender; mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGFLUncern); } else if (tcUncern.SelectedIndex == 1) //Texture { //Create Rendering of Uncertainty at Target Layer int intUncernBreakCount = Convert.ToInt32(nudTeNClasses.Value); string strUncerFieldName = cboUField.Text; IFeatureLayer pflUncern = new FeatureLayerClass(); pflUncern.FeatureClass = pFClass; pflUncern.Name = cboSourceLayer.Text + " Uncertainty"; pflUncern.Visible = true; IGeoFeatureLayer pGFLUncern = (IGeoFeatureLayer)pflUncern; switch (cboTeClassify.Text) { case "Equal Interval": pClassifyGEN = new EqualIntervalClass(); break; case "Geometrical Interval": pClassifyGEN = new GeometricalInterval(); break; case "Natural Breaks": pClassifyGEN = new NaturalBreaksClass(); break; case "Quantile": pClassifyGEN = new QuantileClass(); break; case "StandardDeviation": pClassifyGEN = new StandardDeviationClass(); break; default: pClassifyGEN = new NaturalBreaksClass(); break; } //Need to be changed 1/29/15 pTableHistogram = new BasicTableHistogramClass(); pTableHistogram.Field = strUncerFieldName; pTableHistogram.Table = pTable; pHistogram = (IBasicHistogram)pTableHistogram; pHistogram.GetHistogram(out xVals, out frqs); pClassifyGEN.Classify(xVals, frqs, intUncernBreakCount); pRender = new ClassBreaksRenderer(); cb = (double[])pClassifyGEN.ClassBreaks; pRender.Field = strUncerFieldName; pRender.BreakCount = intUncernBreakCount; pRender.MinimumBreak = cb[0]; IClassBreaksUIProperties pUITexProperties = (IClassBreaksUIProperties)pRender; pUITexProperties.ColorRamp = "Custom"; ILineFillSymbol pLineFillSym = new LineFillSymbolClass(); double dblFromSep = Convert.ToDouble(nudSeperationFrom.Value); double dblToSep = Convert.ToDouble(nudSeperationTo.Value); double dblInstantSep = (dblFromSep - dblToSep) / Convert.ToDouble(intUncernBreakCount - 1); double dblFromAngle = Convert.ToDouble(nudAngleFrom.Value); double dblToAngle = Convert.ToDouble(nudAngleFrom.Value); // Remove the angle part (04/16) double dblInstantAngle = (dblToAngle - dblFromAngle) / Convert.ToDouble(intUncernBreakCount - 1); double dblLinewidth = Convert.ToDouble(nudTeLinewidth.Value); IRgbColor pLineColor = new RgbColor(); pLineColor.Red = picTeLineColor.BackColor.R; pLineColor.Green = picTeLineColor.BackColor.G; pLineColor.Blue = picTeLineColor.BackColor.B; //' be careful, indices are different for the diff lists for (int j = 0; j < intUncernBreakCount; j++) { pRender.Break[j] = cb[j + 1]; pRender.Label[j] = Math.Round(cb[j], 5).ToString() + " - " + Math.Round(cb[j + 1], 5).ToString(); pUITexProperties.LowBreak[j] = cb[j]; pLineFillSym = new LineFillSymbolClass(); pLineFillSym.Angle = dblFromAngle + (dblInstantAngle * Convert.ToDouble(j)); pLineFillSym.Color = pLineColor; pLineFillSym.Separation = dblFromSep - (dblInstantSep * Convert.ToDouble(j)); pLineFillSym.LineSymbol.Width = dblLinewidth; pRender.Symbol[j] = (ISymbol)pLineFillSym; } pGFLUncern.Renderer = (IFeatureRenderer)pRender; mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGFLUncern); } else if (tcUncern.SelectedIndex == 2) //For Proportional Symbols { string strUncerFieldName = cboUField.Text; double dblMinPtSize = Convert.ToDouble(nudProSymbolSize.Value); double dblLineWidth = Convert.ToDouble(nudProLinewidth.Value); IFeatureLayer pflUncern = new FeatureLayerClass(); pflUncern.FeatureClass = pFClass; pflUncern.Name = cboSourceLayer.Text + " Uncertainty"; pflUncern.Visible = true; //Find Fields int intUncernIdx = pTable.FindField(strUncerFieldName); //Find Min value //Set to initial value for min IField pUncernField = pTable.Fields.get_Field(intUncernIdx); ICursor pCursor = pTable.Search(null, false); IDataStatistics pDataStat = new DataStatisticsClass(); pDataStat.Field = pUncernField.Name; pDataStat.Cursor = pCursor; IStatisticsResults pStatResults = pDataStat.Statistics; double dblMinValue = pStatResults.Minimum; double dblMaxValue = pStatResults.Maximum; pCursor.Flush(); IRgbColor pSymbolRgb = pSnippet.getRGB(picProSymbolColor.BackColor.R, picProSymbolColor.BackColor.G, picProSymbolColor.BackColor.B); if (pSymbolRgb == null) { return; } IRgbColor pLineRgb = pSnippet.getRGB(picProiLineColor.BackColor.R, picProiLineColor.BackColor.G, picProiLineColor.BackColor.B); if (pLineRgb == null) { return; } ISimpleMarkerSymbol pSMarkerSym = new SimpleMarkerSymbolClass(); pSMarkerSym.Style = esriSimpleMarkerStyle.esriSMSCircle; pSMarkerSym.Size = dblMinPtSize; pSMarkerSym.OutlineSize = dblLineWidth; pSMarkerSym.Outline = true; pSMarkerSym.OutlineColor = (IColor)pLineRgb; pSMarkerSym.Color = (IColor)pSymbolRgb; IGeoFeatureLayer pGFLUncern = (IGeoFeatureLayer)pflUncern; IProportionalSymbolRenderer pUncernRender = new ProportionalSymbolRendererClass(); pUncernRender.LegendSymbolCount = 2; //Need to be changed 0219 pUncernRender.Field = strUncerFieldName; pUncernRender.MaxDataValue = dblMaxValue; pUncernRender.MinDataValue = dblMinValue; pUncernRender.MinSymbol = (ISymbol)pSMarkerSym; pUncernRender.ValueUnit = esriUnits.esriUnknownUnits; pUncernRender.BackgroundSymbol = null; pUncernRender.CreateLegendSymbols(); pGFLUncern.Renderer = (IFeatureRenderer)pUncernRender; mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGFLUncern); } else if (tcUncern.SelectedIndex == 3) // Bar { string strUncerFieldName = cboUField.Text; double dblMaxLength = Convert.ToDouble(nudMaxBarHeight.Value); double dblBarWidth = Convert.ToDouble(nudBarWidth.Value); IFeatureLayer pflUncern = new FeatureLayerClass(); pflUncern.FeatureClass = pFClass; pflUncern.Name = cboSourceLayer.Text + " Uncertainty"; pflUncern.Visible = true; int intUncernIdx = pTable.FindField(strUncerFieldName); IField pUncernField = pTable.Fields.get_Field(intUncernIdx); ICursor pCursor = pTable.Search(null, false); IDataStatistics pDataStat = new DataStatisticsClass(); pDataStat.Field = pUncernField.Name; pDataStat.Cursor = pCursor; IStatisticsResults pStatResults = pDataStat.Statistics; double dblMaxValue = pStatResults.Maximum; pCursor.Flush(); IChartRenderer chartRenderer = new ChartRendererClass(); IRendererFields rendererFields = chartRenderer as IRendererFields; rendererFields.AddField(strUncerFieldName); IBarChartSymbol barChartSymbol = new BarChartSymbolClass(); barChartSymbol.Width = dblBarWidth; IMarkerSymbol markerSymbol = barChartSymbol as IMarkerSymbol; markerSymbol.Size = dblMaxLength; IChartSymbol chartSymbol = barChartSymbol as IChartSymbol; chartSymbol.MaxValue = dblMaxValue; ISymbolArray symbolArray = barChartSymbol as ISymbolArray; IFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = pSnippet.getRGB(picBarSymCol.BackColor.R, picBarSymCol.BackColor.G, picBarSymCol.BackColor.B); if (fillSymbol.Color == null) { return; } symbolArray.AddSymbol(fillSymbol as ISymbol); if (chk3D.Checked) { I3DChartSymbol p3DChartSymbol = barChartSymbol as I3DChartSymbol; p3DChartSymbol.Display3D = true; p3DChartSymbol.Thickness = 3; } chartRenderer.ChartSymbol = barChartSymbol as IChartSymbol; SimpleFillSymbol pBaseFillSym = new SimpleFillSymbolClass(); //pBaseFillSym.Color = pSnippet.getRGB(picBarSymCol.BackColor.R, picBarSymCol.BackColor.G, picBarSymCol.BackColor.B); //chartRenderer.BaseSymbol = pBaseFillSym as ISymbol; chartRenderer.UseOverposter = false; chartRenderer.CreateLegend(); IGeoFeatureLayer pGFLUncern = (IGeoFeatureLayer)pflUncern; pGFLUncern.Renderer = (IFeatureRenderer)chartRenderer; mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGFLUncern); } #region illumination //This function is not applied in this version. 032317 HK //} // else if (tcUncern.SelectedIndex == 4) //illumination // { // frmProgress pfrmProgress = new frmProgress(); // pfrmProgress.lblStatus.Text = "Processing:"; // pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee; // pfrmProgress.Show(); // string strUncerFieldName = cboUField.Text; // IGeoDataset geoDataset_output = createRasterfromPolygon(pFClass, strUncerFieldName, pFLayer, 100); // double altitude = Convert.ToDouble(nudAltitude.Value); // double azimuth = Convert.ToDouble(nudAzimuth.Value); // object zFactor = Convert.ToDouble(nudZFactor.Value); // ISurfaceOp2 pSurfOP = new RasterSurfaceOpClass(); // IRaster pOutputDS = (IRaster)pSurfOP.HillShade(geoDataset_output, azimuth, altitude, true, ref zFactor); // ((IDataset)geoDataset_output).Delete(); // // Create a raster for viewing // ESRI.ArcGIS.Carto.IRasterLayer rasterLayer = new ESRI.ArcGIS.Carto.RasterLayerClass(); // rasterLayer.CreateFromRaster(pOutputDS); // //Calculate hillshade value at slope 0 to set as background value // double dblRadian = (Math.PI / 180) * (90 - altitude); // double dblBackValue = Math.Truncate(255 * Math.Cos(dblRadian)); // IRasterStretch pRasterStretch = new RasterStretchColorRampRendererClass(); // IColor pColor = new RgbColorClass(); // pColor.NullColor = true; // pColor.Transparency = 0; // pRasterStretch.Background = true; // pRasterStretch.BackgroundColor = pColor; // pRasterStretch.set_BackgroundValues(ref dblBackValue); // rasterLayer.Name = "Uncertainty of " + strGCRenderField; // rasterLayer.Renderer = pRasterStretch as IRasterRenderer; // rasterLayer.Renderer.Update(); // //Apply Transparency // ILayerEffects pLayerEffect = (ILayerEffects)rasterLayer; // pLayerEffect.Transparency = Convert.ToInt16(nudTransparent.Value); // pfrmProgress.Close(); // // Add the raster to the map // pActiveView.FocusMap.AddLayer(rasterLayer); // } // mForm.axMapControl1.ActiveView.Refresh(); // mForm.axTOCControl1.Update(); #endregion } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
//比例图 private void button4_Click(object sender, EventArgs e) { IGeoFeatureLayer geoFeatureLayer; IFeatureLayer featureLayer; IProportionalSymbolRenderer proportionalSymbolRenderer; ITable table; ICursor cursor; IDataStatistics dataStatistics; IStatisticsResults statisticsResult; stdole.IFontDisp fontDisp; geoFeatureLayer = getGeoLayer("东丰县行政区域"); featureLayer = geoFeatureLayer as IFeatureLayer; table = geoFeatureLayer as ITable; cursor = table.Search(null, true); dataStatistics = new DataStatisticsClass(); dataStatistics.Cursor = cursor; dataStatistics.Field = "SHAPE_Area"; statisticsResult = dataStatistics.Statistics; if (statisticsResult != null) { IFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = getRGB(0, 255, 0); ICharacterMarkerSymbol characterMarkerSymbol = new CharacterMarkerSymbolClass(); fontDisp = new stdole.StdFontClass() as stdole.IFontDisp; fontDisp.Name = "arial"; fontDisp.Size = 20; characterMarkerSymbol.Font = fontDisp; characterMarkerSymbol.CharacterIndex = 90; characterMarkerSymbol.Color = getRGB(255, 0, 0); characterMarkerSymbol.Size = 8; proportionalSymbolRenderer = new ProportionalSymbolRendererClass(); proportionalSymbolRenderer.ValueUnit = esriUnits.esriUnknownUnits; proportionalSymbolRenderer.Field = "SHAPE_Area"; proportionalSymbolRenderer.FlanneryCompensation = false; proportionalSymbolRenderer.MinDataValue = statisticsResult.Minimum; proportionalSymbolRenderer.MaxDataValue = statisticsResult.Maximum; proportionalSymbolRenderer.BackgroundSymbol = fillSymbol; proportionalSymbolRenderer.MinSymbol = characterMarkerSymbol as ISymbol; proportionalSymbolRenderer.LegendSymbolCount = 10; proportionalSymbolRenderer.CreateLegendSymbols(); geoFeatureLayer.Renderer = proportionalSymbolRenderer as IFeatureRenderer; } this.axMapControl1.Refresh(); }
private void btnProportionalSymbolRender_Click(object sender, EventArgs e) { IGeoFeatureLayer pGeoFeatLyr = (IGeoFeatureLayer)this.mainMapControl.get_Layer(0); ITable pTable = pGeoFeatLyr as ITable; IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField("GDP_1999("); pQueryFilter.WhereClause = ""; ICursor pCursor;//DataStatistic对象统计需要用一个Cursor pCursor = pTable.Search(pQueryFilter, true); IDataStatistics pDataStatistics = new DataStatisticsClass();//用于统计字段信息,需要一个Cursor pDataStatistics.Cursor = pCursor; pDataStatistics.Field = "GDP_1999("; IStatisticsResults pStatisticsResults;//字段统计结果 pStatisticsResults = pDataStatistics.Statistics; ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();//用于背景 pSimpleFillSymbol.Color = this.getHsvColor(60, 120, 60); ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass();//标注符号(最小),注意size属性 pSimpleMarkerSymbol.Color = this.getHsvColor(120, 100, 75); pSimpleMarkerSymbol.Size = 0.5; //以下创建并设置着色对象 IProportionalSymbolRenderer pProportionalSymbolRenderer = new ProportionalSymbolRendererClass(); pProportionalSymbolRenderer.ValueUnit = esriUnits.esriUnknownUnits; pProportionalSymbolRenderer.Field = "GDP_1999("; pProportionalSymbolRenderer.FlanneryCompensation = false; pProportionalSymbolRenderer.MinDataValue = 1;//为什么用pStatisticsResults.Minimum会出错?????????? pProportionalSymbolRenderer.MaxDataValue = pStatisticsResults.Maximum; pProportionalSymbolRenderer.BackgroundSymbol = pSimpleFillSymbol as IFillSymbol; pProportionalSymbolRenderer.MinSymbol = pSimpleMarkerSymbol as ISymbol;//最小值的符号,关键!!!!!!! pProportionalSymbolRenderer.LegendSymbolCount = 3; pProportionalSymbolRenderer.CreateLegendSymbols(); pGeoFeatLyr.Renderer = pProportionalSymbolRenderer as IFeatureRenderer; this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); this.axTOCControl.Update(); }
public void btnOk_Click(object sender, EventArgs e) { // valida os campos if (!this.ValidarCampos()) { return; } this.Cursor = Cursors.WaitCursor; //enviar os parametros pra function do banco try { var incidenciaDoencaEmUnidadeSaude = new DoencaEmUnidadeSaudeRepositorio(); if (cmbDoenca.SelectedItem != null && rbtnTodas.Checked == true) { //retorna uma lista de unidades de saude com incidencia da doença escolhida var listaIncidenciaDoencaEmUnidadeSaude = incidenciaDoencaEmUnidadeSaude.GerarMapaTematicoEmUnidadesDeSaude((int)this.cmbDoenca.SelectedValue, this.dtInicio.Value.Year, this.dtFinal.Value.Year); listaIncidenciaDoencaEmUnidadeSaude.Count.ToString(); //criar a Feature Class IFeatureClass featureClass = CreateNewShapeFile(@"C:\Sistemas\GestaoSMS\Files\Mapas\MapaIncidencia" + cmbDoenca.Text + "EmUnidadeDeSaude" + DateTime.Now.ToString("ddMMyyyyhhmmss") + ".shp"); //criar uma feature buffer IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer(); //campo nome int indexNome = featureClass.FindField("nome"); //campo incidências int indexIncidencia = featureClass.FindField("incidencia"); //criar um feature cursor com buffer ativado IFeatureCursor featureCursor = featureClass.Insert(true); foreach (MapaDoencaEmUnidadeSaude incidencia in listaIncidenciaDoencaEmUnidadeSaude) { //passar de Wkb para IGeometry var geometry = WKBToGeometry(incidencia.UnidadesSaude); //atribuir a geometria ao buffer featureBuffer.Shape = geometry; featureBuffer.set_Value(indexNome, incidencia.Nome); featureBuffer.set_Value(indexIncidencia, incidencia.TotalIncidencias); //inserir a feature na featureclass featureCursor.InsertFeature(featureBuffer); } Marshal.FinalReleaseComObject(featureCursor); try { //cria featureLayer IFeatureLayer featureLayer = new FeatureLayerClass(); featureLayer.FeatureClass = featureClass; if (featureLayer != null) { //cria a geofeaturelayer IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer; //ativar os Labels //geoFeatureLayer.DisplayAnnotation = true; //calculo do raio minimo das pontos var minimo = (double)listaIncidenciaDoencaEmUnidadeSaude.Min(p => p.TotalIncidencias); var maximo = (double)listaIncidenciaDoencaEmUnidadeSaude.Max(p => p.TotalIncidencias); var n = (double)listaIncidenciaDoencaEmUnidadeSaude.Max(p => p.TotalIncidencias) / (Math.PI * Math.Pow((double)listaIncidenciaDoencaEmUnidadeSaude.Max(p => p.UnidadesSaude.LongLength), 2.0)); var div = minimo / n; var pow = Math.Pow(div, 0.57); var tamanho = pow * 0.564; //cria o símbolo do marcador ISimpleMarkerSymbol symbol = new SimpleMarkerSymbolClass(); symbol.Style = esriSimpleMarkerStyle.esriSMSCircle; symbol.Size = tamanho; ISymbol symbolteste = symbol as ISymbol; //Renderer de simbolos proporcionais IProportionalSymbolRenderer teste = new ProportionalSymbolRendererClass(); teste.ValueUnit = ESRI.ArcGIS.esriSystem.esriUnits.esriUnknownUnits; teste.Field = "incidencia"; teste.MinDataValue = listaIncidenciaDoencaEmUnidadeSaude.Min(p => p.TotalIncidencias); teste.MaxDataValue = listaIncidenciaDoencaEmUnidadeSaude.Max(p => p.TotalIncidencias); teste.FlanneryCompensation = false; teste.LegendSymbolCount = 5; teste.MinSymbol = symbolteste; teste.CreateLegendSymbols(); geoFeatureLayer.Renderer = (IFeatureRenderer)teste; //carregar o shape no mapa geoFeatureLayer.FeatureClass = featureClass; geoFeatureLayer.Name = featureClass.AliasName; geoFeatureLayer.Visible = true; ArcMap.Document.FocusMap.AddLayer(geoFeatureLayer); MessageBox.Show("O mapa de incidência da doença [" + cmbDoenca.Text + "] em todas as Unidade de Saúde foi gerado com sucesso!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } catch (Exception ex) { MostrarErro(ex); MessageBox.Show("Escolha um período que contenha incidências da doença [" + cmbDoenca.Text + "].", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } else if (cmbDoenca.SelectedItem != null && rbtnDSEspecifico.Checked == true) { //retorna uma lista de unidades de saude com incidencia da doença escolhida var listaIncidenciaDoencaEmUnidadeSaude = incidenciaDoencaEmUnidadeSaude.GerarMapaTematicoEmUnidadesDeSaudeDeDistritoEspecifico( (int)cmbDoenca.SelectedValue, (int)cmbDSEspecifico.SelectedValue, this.dtInicio.Value.Year, this.dtFinal.Value.Year); listaIncidenciaDoencaEmUnidadeSaude.Count.ToString(); //criar a Feature Class IFeatureClass featureClass = CreateNewShapeFile(@"C:\Sistemas\GestaoSMS\Files\Mapas\MapaIncidencia" + cmbDoenca.Text + "EmUS" + cmbDSEspecifico.Text + DateTime.Now.ToString("ddMMyyyyhhmmss") + ".shp"); //criar uma feature buffer IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer(); //campo nome int indexNome = featureClass.FindField("nome"); //campo incidências int indexIncidencia = featureClass.FindField("incidencia"); //criar um feature cursor com buffer ativado IFeatureCursor featureCursor = featureClass.Insert(true); foreach (MapaDoencaEmUnidadeSaude incidencia in listaIncidenciaDoencaEmUnidadeSaude) { //passar de Wkb para IGeometry var geometry = WKBToGeometry(incidencia.UnidadesSaude); //atribuir a geometria ao buffer featureBuffer.Shape = geometry; featureBuffer.set_Value(indexNome, incidencia.Nome); featureBuffer.set_Value(indexIncidencia, incidencia.TotalIncidencias); //inserir a feature na featureclass featureCursor.InsertFeature(featureBuffer); } Marshal.FinalReleaseComObject(featureCursor); try { //cria featureLayer IFeatureLayer featureLayer = new FeatureLayerClass(); featureLayer.FeatureClass = featureClass; if (featureLayer != null) { //cria a geofeaturelayer IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer; //ativar os Labels //geoFeatureLayer.DisplayAnnotation = true; //calculo do raio minimo das pontos var minimo = (double)listaIncidenciaDoencaEmUnidadeSaude.Min(p => p.TotalIncidencias); var maximo = (double)listaIncidenciaDoencaEmUnidadeSaude.Max(p => p.TotalIncidencias); var n = (double)listaIncidenciaDoencaEmUnidadeSaude.Max(p => p.TotalIncidencias) / (Math.PI * Math.Pow((double)listaIncidenciaDoencaEmUnidadeSaude.Max(p => p.UnidadesSaude.LongLength), 2.0)); var div = minimo / n; var pow = Math.Pow(div, 0.57); var tamanho = pow * 0.564; //cria o símbolo do marcador ISimpleMarkerSymbol symbol = new SimpleMarkerSymbolClass(); symbol.Style = esriSimpleMarkerStyle.esriSMSCircle; symbol.Size = tamanho; ISymbol symbolteste = symbol as ISymbol; //Renderer de simbolos proporcionais IProportionalSymbolRenderer teste = new ProportionalSymbolRendererClass(); teste.ValueUnit = ESRI.ArcGIS.esriSystem.esriUnits.esriUnknownUnits; teste.Field = "incidencia"; teste.MinDataValue = listaIncidenciaDoencaEmUnidadeSaude.Min(p => p.TotalIncidencias); teste.MaxDataValue = listaIncidenciaDoencaEmUnidadeSaude.Max(p => p.TotalIncidencias); teste.FlanneryCompensation = false; teste.LegendSymbolCount = 5; teste.MinSymbol = symbolteste; teste.CreateLegendSymbols(); geoFeatureLayer.Renderer = (IFeatureRenderer)teste; //carregar o shape no mapa geoFeatureLayer.FeatureClass = featureClass; geoFeatureLayer.Name = featureClass.AliasName; geoFeatureLayer.Visible = true; ArcMap.Document.FocusMap.AddLayer(geoFeatureLayer); MessageBox.Show("O mapa de incidência da doença [" + cmbDoenca.Text + "] nas Unidades de Saúde da [" + cmbDSEspecifico.Text + "] foi gerado com sucesso!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } catch (Exception ex) { MostrarErro(ex); MessageBox.Show("Escolha um período que contenha incidências da doença [" + cmbDoenca.Text + "] na [" + cmbDSEspecifico.Text + "].", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } } catch (Exception ex) { this.MostrarErro(ex); } finally { this.Cursor = Cursors.Default; } }
private void button_thematic_Click(object sender, EventArgs e) { // IFeatureClass pFeatureClass = GetFeatureClass("D://a_gis工程设计实践课//shp//POI.shp"); //DataTable dataTable = GetAttributesTable(pFeatureClass); try { //获取目标图层 IFeatureClass pFeatureClass = GetFeatureClass("D://a_gis工程设计实践课//shp//POI.shp"); ILayer pLayer = new FeatureLayerClass(); pLayer = axMapControl1.get_Layer(0); IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer;//目标图层的feature*/ /* IFeatureClass pFeatureClass = GetFeatureClass("D://a_gis工程设计实践课//shp//POI.shp"); * //pLayer = new FeatureLayerClass(); * ILayer pLayer = pFeatureClass as ILayer; * IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer;//目标图层的feature*/ ITable table; ICursor cursor; IDataStatistics dataStatistics; //用一个字段生成统计数据 IStatisticsResults statisticsResult; //报告统计数据 //stdole.IFontDisp fontDisp;//定义字体 //设置点符号 ISimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbol(); pMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; //设置点符号样式为方形 IRgbColor pRgbColor1 = new RgbColor(); pRgbColor1.Red = 127; pRgbColor1.Blue = 255; pRgbColor1.Green = 212; pMarkerSymbol.Color = pRgbColor1; table = pLayer as ITable; cursor = table.Search(null, true); dataStatistics = new DataStatisticsClass(); dataStatistics.Cursor = cursor; dataStatistics.Field = "难度";//确定分级字段 statisticsResult = dataStatistics.Statistics; if (statisticsResult != null) { IFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = pRgbColor1; IProportionalSymbolRenderer proportionalSymbolRenderer = new ProportionalSymbolRendererClass(); //proportionalSymbolRenderer.ValueUnit = units; proportionalSymbolRenderer.Field = "难度"; proportionalSymbolRenderer.FlanneryCompensation = false; //分级是不是在TOC中显示legend proportionalSymbolRenderer.MinDataValue = statisticsResult.Minimum; // proportionalSymbolRenderer.MaxDataValue = statisticsResult.Maximum; // // proportionalSymbolRenderer.BackgroundSymbol = fillSymbol; pMarkerSymbol.Size = 15; proportionalSymbolRenderer.MinSymbol = pMarkerSymbol as ISymbol; proportionalSymbolRenderer.LegendSymbolCount = 6;//要分成的级数 proportionalSymbolRenderer.CreateLegendSymbols(); pGeoFeatLyr.Renderer = proportionalSymbolRenderer as IFeatureRenderer; //axMapControl1.Update(); //axMapControl1.Refresh(); axTOCControl1.Update(); //Thread.Sleep(2000); //停一秒 for (int i = 0; i < 4; i++) { pMarkerSymbol.Size = 3 * (i + 1); proportionalSymbolRenderer.MinSymbol = pMarkerSymbol as ISymbol; //proportionalSymbolRenderer.LegendSymbolCount = 6;//要分成的级数 proportionalSymbolRenderer.CreateLegendSymbols(); pGeoFeatLyr.Renderer = proportionalSymbolRenderer as IFeatureRenderer; axMapControl1.Update(); axMapControl1.Refresh(); //axTOCControl1.Update(); Thread.Sleep(500); //停一秒 } /*pMarkerSymbol.Size = 10; * proportionalSymbolRenderer.MinSymbol = pMarkerSymbol as ISymbol; * pGeoFeatLyr.Renderer = proportionalSymbolRenderer as IFeatureRenderer; * axMapControl1.Refresh(); * axTOCControl1.Update();*/ } } catch { MessageBox.Show("请输入有效图层!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// 比例符号法渲染器(ProportionalSymbolRenderer)——用不同大小的符号绘制要素, 其大小对应某一字段值的比例。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 比例符号法渲染ToolStripMenuItem_Click(object sender, EventArgs e) { //声明IGeoFeatureLayer变量, 提供一个要素图层对成员控制地理特征的入口 IGeoFeatureLayer geoFeatureLayer; //声明要素图层 IFeatureLayer pFtLayer; //声明专题图变量 //在利用该方法进行着色时, 需获得最大和最小标识符号所代表的字段及其各个数值, 还需要确定每个字段数值所匹配的着色符号。 IProportionalSymbolRenderer proportionalSymbolRenderer; //声明表格 ITable table; //声明游标 ICursor cursor; //用于统计变量 IDataStatistics dataStatistics; //用于存放统计结果 IStatisticsResults statisticsResults; //声明一个字体对象 stdole.IFontDisp fontDisp; //获取图层 geoFeatureLayer = getGeoLayer("北部湾"); //强转为要素图层 pFtLayer = geoFeatureLayer as IFeatureLayer; //图层类型转换成表 table = geoFeatureLayer as ITable; //获取游标 cursor = table.Search(null, true); //实例化数据统计对象 dataStatistics = new DataStatisticsClass(); //赋游标给数据统计对象的游标 dataStatistics.Cursor = cursor; //获取图层要素中进行专题地图制图的字段名称, 此实例中所用的数据中字段名为"年"(2010年GDP增长速率) dataStatistics.Field = "年"; //存放统计结果为统计对象的统计数据 statisticsResults = dataStatistics.Statistics; //如果统计结果不为空 if (statisticsResults != null) { //简单填充符号 IFillSymbol fillSymbol = new SimpleFillSymbolClass(); //设置颜色 fillSymbol.Color = getRGB(195, 255, 255); //设置简单线型符号 ISimpleLineSymbol SLS = new SimpleLineSymbolClass(); SLS.Color = getRGB(196, 196, 196); //颜色 SLS.Width = 1.5; //宽度 fillSymbol.Outline = SLS; //外边界线 //利用ESRI特殊符号调用成员进行填充 ICharacterMarkerSymbol characterMarkerSymbol = new CharacterMarkerSymbolClass(); fontDisp = new stdole.StdFontClass() as stdole.IFontDisp; //调用指定子库(ESRI Default Marker是子库名称) fontDisp.Name = "ESRI Default Marker"; //对characterMarkerSymbol的font属性 characterMarkerSymbol.Font = fontDisp; //特征标记符号(Character Marker Symbol)的索引值 //0xB6是C#特殊的16进制表示方法, 换算为十进制值182 characterMarkerSymbol.CharacterIndex = 0xB6; //特征标记符号的颜色 characterMarkerSymbol.Color = getRGB(253, 191, 110); //设计特征标记符号的尺寸 characterMarkerSymbol.Size = 18; //实例化一个比例符号渲染器 proportionalSymbolRenderer = new ProportionalSymbolRendererClass(); proportionalSymbolRenderer.ValueUnit = esriUnits.esriUnknownUnits; //获取渲染字段 proportionalSymbolRenderer.Field = "年"; //是否启用颜色补偿(默认为否) proportionalSymbolRenderer.FlanneryCompensation = false; //赋值统计数据(比例符号渲染器) //MinDataValue获取数据中最小值 proportionalSymbolRenderer.MinDataValue = statisticsResults.Minimum; //获取数据中最大值 proportionalSymbolRenderer.MaxDataValue = statisticsResults.Maximum; //在多边形特征上绘制比例标记符号时使用的背景填充符号 proportionalSymbolRenderer.BackgroundSymbol = fillSymbol; //用于绘制具有规格化最小数据值的特征的符号。 proportionalSymbolRenderer.MinSymbol = characterMarkerSymbol as ISymbol; //目录和图例中显示的符号数为3 proportionalSymbolRenderer.LegendSymbolCount = 3; //创建图例, 设置完所有属性后调用。 proportionalSymbolRenderer.CreateLegendSymbols(); //赋值目标图层的渲染器属性 geoFeatureLayer.Renderer = proportionalSymbolRenderer as IFeatureRenderer; } axMapControl1.Refresh(); //刷新axMapControl1 axTOCControl1.Update(); //更新axTOCControl1 }