private void CboUField_SelectedIndexChanged(object sender, EventArgs e) { try { strUncernRenderField = CboUField.Text; ITable pTable = (ITable)pFClass; int intUncernIdx = pTable.FindField(strUncernRenderField); 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; dblMinValue = pStatResults.Minimum; dblMaxValue = pStatResults.Maximum; int intX = lblMax.Location.X + lblMax.Size.Width; lblMin.Text = "MIN: " + Math.Round(pStatResults.Minimum, intNDecimal).ToString(); lblMax.Text = "MAX: " + Math.Round(pStatResults.Maximum, intNDecimal).ToString(); lblMax.SetBounds(intX - lblMax.Size.Width, lblMax.Location.Y, lblMax.Size.Width, lblMax.Size.Height); txtValue.Text = Math.Round(dblMinValue, intNDecimal).ToString(); } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
public double[] Area(string sql, IFeatureClass pFeatureClass) { double[] area; List <double> list = new List <double>(); //获取当前图层; IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, true); IDataStatistics pDataStatistics = new DataStatisticsClass(); pDataStatistics.Field = MainForm.dataInputInfo.zoneField; pDataStatistics.Cursor = (ICursor)pFeatureCursor; IEnumerator pEnumerator = pDataStatistics.UniqueValues; pEnumerator.Reset(); while (pEnumerator.MoveNext()) { object obj = pEnumerator.Current; //计算耕地面积; IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.WhereClause = "\"" + MainForm.dataInputInfo.zoneField + "\"" + " = \'" + obj + "\'" + sql; IFeatureCursor pFeatureCursor3 = pFeatureClass.Search(pQueryFilter, true); IDataStatistics pAreaStatistics3 = new DataStatisticsClass(); pAreaStatistics3.Field = "Shape_Area"; pAreaStatistics3.Cursor = pFeatureCursor3 as ICursor; IStatisticsResults results3 = pAreaStatistics3.Statistics; list.Add(results3.Sum); } area = list.ToArray(); return(area); }
// *------------------------------------------------------------------------------------------------------- // *功能函数:获取自动编号的下一个值 // *开 发 者:陈亚飞 // *开发日期:20110617 // *参 数:表格所在工作空间,表格名称,自动编号的字段名,异常 // *返 回:返回该字段的下一个值 public static long GetMaxID(IFeatureWorkspace pFeaWs, string pTableName, string pFiledName, out Exception outError) { outError = null; long ReturnMaxID = -1; //获取表格 ITable pTable = pFeaWs.OpenTable(pTableName); try { //表格行数 long count = Convert.ToInt64(pTable.RowCount(null).ToString()); if (count == 0) { ReturnMaxID = 1; } else { //若表格行数部位0行,则统计表格中该字段的最大值 IDataStatistics pDataSta = new DataStatisticsClass(); pDataSta.Field = pFiledName; pDataSta.Cursor = pTable.Search(null, false); IStatisticsResults pStaRes = null; pStaRes = pDataSta.Statistics; count = (long)pStaRes.Maximum; //下一个值为最大值+1 ReturnMaxID = count + 1; } return(ReturnMaxID); } catch (Exception eError) { outError = new Exception("获取自动编号的下一个值失败!"); return(-1); } }
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 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); }
//当选择统计字段发生变化时触发事件,执行本函数,完成统计分析操作 private void comboBoxFields_SelectedIndexChanged(object sender, EventArgs e) { //定义及新建IDataStatistics接口的对象进行字段统计 IDataStatistics dataStatistics = new DataStatisticsClass(); //获取需要统计的字段 dataStatistics.Field = comboBoxFields.SelectedItem.ToString(); //将当前矢量图层对象进行接口转换以进行选择集操作 IFeatureSelection featureSelection = currentFeatureLayer as IFeatureSelection; //定义选择集的游标 ICursor cursor = null; //使用null参数的Search方法获取整个选择集中的要素,得到相应的游标 featureSelection.SelectionSet.Search(null, false, out cursor); //将该游标赋值给IDataStatistics接口对象的游标 dataStatistics.Cursor = cursor; //执行统计 IStatisticsResults statisticsResults = dataStatistics.Statistics; //定义StringBuilder对象进行字符串的操作 StringBuilder stringBuilder = new StringBuilder(); //以下语句依次增加各类统计结果 stringBuilder.AppendLine("统计总数: " + statisticsResults.Count.ToString() + "\n"); stringBuilder.AppendLine("最小值:" + statisticsResults.Minimum.ToString() + "\n"); stringBuilder.AppendLine("最大值:" + statisticsResults.Maximum.ToString() + "\n"); stringBuilder.AppendLine("总计: " + statisticsResults.Sum.ToString() + "\n"); stringBuilder.AppendLine("平均值: " + statisticsResults.Mean.ToString() + "\n"); stringBuilder.AppendLine("标准差: " + statisticsResults.StandardDeviation.ToString()); //将统计结果显示在窗体中 labelStatisticsResult.Text = stringBuilder.ToString(); }
private double FindMaxValueInRendererFields(IFeatureClass featureClass) { ITable pTable = (ITable)featureClass; 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; double gMaxValue = 0.0; foreach (System.Collections.DictionaryEntry de in fieldSymbolHashTable) { string strField = de.Key.ToString(); //Set statistical field pDataStatistics.Field = strField; //Get the result of statistics IStatisticsResults pStatisticsResult = pDataStatistics.Statistics; double dmaxValue = pStatisticsResult.Maximum; if (dmaxValue > gMaxValue) { gMaxValue = dmaxValue; } } return(gMaxValue); }
private void GetRankingStatistics(string fieldName) { if (m_featureLayer == null) { return; } //Find the selected field in the feature layer IFeatureClass featureClass = m_featureLayer.FeatureClass; IField field = featureClass.Fields.get_Field(featureClass.FindField(fieldName)); //Get a feature cursor ICursor cursor = (ICursor)m_featureLayer.Search(null, false); //Create a DataStatistics object and initialize properties IDataStatistics dataStatistics = new DataStatisticsClass(); dataStatistics.Field = field.Name; dataStatistics.Cursor = cursor; //Get the result statistics IStatisticsResults statisticsResults = dataStatistics.Statistics; //Set the values min and max values _minriskvalue = statisticsResults.Minimum; _maxriskvalue = statisticsResults.Maximum; }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { string fieldName = comboBox1.SelectedItem.ToString(); string selectLayerName = comboBox2.SelectedItem.ToString(); IEnumLayer pEnumlayer = PMap.Layers; //获取地图中的图层集合 pEnumlayer.Reset(); // ILayer pLayer = pEnumlayer.Next(); //获得第一个图层 while (pLayer != null) // { string name = pLayer.Name; //获得图层名称 if (selectLayerName == name) //在图层集合中找到相应名称的图层 { IFeatureLayer featureLayer = pLayer as IFeatureLayer; if (fieldName != null) { IFields pFields = featureLayer.FeatureClass.Fields; //获得特征类的字段集合 for (int i = 0; i < pFields.FieldCount; i++) // 循环 { IField pField = pFields.get_Field(i); //获得第i个字段 if (pField.Name == fieldName) { IQueryFilter queryFilter = new QueryFilterClass(); // 创建查询过滤条件对象 queryFilter.SubFields = fieldName; // 设置返回的字段名称 IFeatureCursor pFeatureCursor = featureLayer.FeatureClass.Search(queryFilter, true); //得到IFeatureCursor游标 ICursor pCursor = pFeatureCursor as ICursor; //接口查询返回ICursor游标 IDataStatistics pDataStatistics = new DataStatistics(); //创建DataStatistics对象,该对象用于进行字段值的统计 pDataStatistics.Cursor = pCursor; //给DataStatistics对象的游标属性赋值 pDataStatistics.Field = fieldName; //给DataStatistics对象的字段属性赋值 IStatisticsResults pStatisticsResult = pDataStatistics.Statistics; //获得统计结果 label2.Text = pStatisticsResult.Maximum.ToString(); //最大值 label3.Text = pStatisticsResult.Minimum.ToString(); //最小值 label4.Text = pStatisticsResult.Mean.ToString(); //平均值 label5.Text = pStatisticsResult.StandardDeviation.ToString(); //标准差 label6.Text = pStatisticsResult.Count.ToString(); //个数 label7.Text = pStatisticsResult.Sum.ToString(); //总和 return; } } } return; } pLayer = pEnumlayer.Next(); //获得下一个图层 } }
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); }
private double sumArea(IFeature _pFeature, IFeatureClass _pFeatureClass, string zoneValue, IFeatureClass _pFeatureClass1) { double result = 0.0; // IGeometry pGeometry; // IFeatureCursor pFeatureCursor = _pFeatureClass.Search(null, true); // IFeature pFeature = pFeatureCursor.NextFeature(); // while (pFeature != null) // { // // pGeometry = pFeature.Shape; // double area = (pGeometry as IArea).Area; // pGeometry = IntersectGeo(_pFeature.Shape as ITopologicalOperator, pGeometry); // //result += area * sumArea(codeValue, codeField, _pFeatureClass1,pGeometry); // pFeature = pFeatureCursor.NextFeature(); // } IGeometry pGeometry; ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = _pFeature.Shape; spatialFilter.GeometryField = _pFeatureClass.ShapeFieldName; spatialFilter.SpatialRelDescription = "T********"; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelRelation; IFeatureCursor pCursor = _pFeatureClass.Search(spatialFilter, true); IFeature pFeature = pCursor.NextFeature(); while (pFeature != null) { pGeometry = pFeature.Shape; double area = (pGeometry as IArea).Area; IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.WhereClause = zoneValue + " = " + pFeature.get_Value(0); IFeatureCursor pFeatureCursor1 = _pFeatureClass1.Search(pQueryFilter, true); IDataStatistics pAreaStatistics = new DataStatisticsClass(); pAreaStatistics.Field = "Shape_Area"; pAreaStatistics.Cursor = pFeatureCursor1 as ICursor; IStatisticsResults pStatistics = pAreaStatistics.Statistics; result += area * pStatistics.Sum; pFeature = pCursor.NextFeature(); } return(result); }
public static int GetRecord(IFeatureClass featureClass, string whereClause, string field) { IQueryFilter queryFilter = new QueryFilterClass(); queryFilter.WhereClause = whereClause; IFeatureCursor featureCursor = featureClass.Search(queryFilter, false); ICursor cursor = featureCursor as ICursor; IDataStatistics dataStatistics = new DataStatisticsClass(); dataStatistics.Cursor = cursor; dataStatistics.Field = field; IStatisticsResults statisticsResults = dataStatistics.Statistics; System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor); return(statisticsResults.Count); }
/// <summary> /// 根据统计类型返回统计值 /// </summary> /// <param name="statisticsResults"></param> /// <param name="eType">统计值类型</param> /// <returns></returns> private static double StatisticsByType(IStatisticsResults statisticsResults, EStatisticsType eType) { switch (eType) { case EStatisticsType.Count: return(statisticsResults.Count); case EStatisticsType.Maximum: return(statisticsResults.Maximum); case EStatisticsType.Mean: return(statisticsResults.Mean); case EStatisticsType.Minimum: return(statisticsResults.Minimum); case EStatisticsType.Sum: return(statisticsResults.Sum); case EStatisticsType.StandardDeviation: return(statisticsResults.StandardDeviation); default: throw new NotImplementedException(); } }
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { IDataStatistics pDs = new DataStatistics(); pDs.Field = comboBox2.SelectedItem.ToString(); IFeatureSelection featureSelection = currentFeatureLayer as IFeatureSelection; ICursor pCursor = null; featureSelection.SelectionSet.Search(null, false, out pCursor); pDs.Cursor = pCursor; IStatisticsResults pSR = pDs.Statistics; count.Text = pSR.Count.ToString(); min.Text = pSR.Minimum.ToString(); max.Text = pSR.Maximum.ToString(); mean.Text = pSR.Mean.ToString(); std.Text = pSR.StandardDeviation.ToString(); sum.Text = pSR.Sum.ToString(); }
/// <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(); }
private void comboBoxFields_SelectedIndexChanged(object sender, EventArgs e) { IDataStatistics dataStatistics = new DataStatisticsClass(); dataStatistics.Field = comboBoxFields.SelectedItem.ToString(); IFeatureSelection featureSelection = currentFeatureLayer as IFeatureSelection; ICursor cursor = null; featureSelection.SelectionSet.Search(null, false, out cursor); dataStatistics.Cursor = cursor; IStatisticsResults statisticsResults = dataStatistics.Statistics; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("总数: " + statisticsResults.Count.ToString() + "\n"); stringBuilder.AppendLine("最小值:" + statisticsResults.Minimum.ToString() + "\n"); stringBuilder.AppendLine("最大值:" + statisticsResults.Maximum.ToString() + "\n"); stringBuilder.AppendLine("求和: " + statisticsResults.Sum.ToString() + "\n"); stringBuilder.AppendLine("平均值: " + statisticsResults.Mean.ToString() + "\n"); stringBuilder.AppendLine("标准差: " + statisticsResults.StandardDeviation.ToString()); richTextBox1.Text = stringBuilder.ToString(); }
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e) { //Find the selected field in the feature layer IFeatureClass featureClass = m_featureLayer.FeatureClass; IField field = featureClass.Fields.get_Field(featureClass.FindField(comboBox1.Text)); //Get a feature cursor ICursor cursor = (ICursor)m_featureLayer.Search(null, false); //Create a DataStatistics object and initialize properties IDataStatistics dataStatistics = new DataStatisticsClass(); dataStatistics.Field = field.Name; dataStatistics.Cursor = cursor; //Get the result statistics IStatisticsResults statisticsResults = dataStatistics.Statistics; //Set the values min and max values textBox2.Text = statisticsResults.Minimum.ToString(); textBox3.Text = statisticsResults.Maximum.ToString(); textBox1.Text = "10"; }
private void CheckUnion(IFeatureClass featureClass) { var fid1 = string.Format("FID_{0}", CheckLayerName); var fid2 = string.Format("FID_{0}", ExtentLayerName); IQueryFilter queryFilter = new QueryFilterClass(); queryFilter.WhereClause = string.Format("[{0}] < 0 OR [{1}] < 0", fid1, fid2); IFeatureCursor featureCursor = featureClass.Search(queryFilter, false); ICursor cursor = featureCursor as ICursor; IDataStatistics dataStatistics = new DataStatisticsClass(); dataStatistics.Cursor = cursor; dataStatistics.Field = fid1; IStatisticsResults statisticsResults = dataStatistics.Statistics; if (statisticsResults.Count > 0) { Messages.Add(new VillageMessage { Description = string.Format("图层【{0}】中行政区代码【{1}】范围不符", _tableName, _XZQDM) }); } System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor); }
private void cbxFields_SelectedIndexChanged(object sender, EventArgs e) { if (cbxFields.SelectedItem != null) { strRendererField = cbxFields.SelectedItem.ToString(); //Find the selected field in the feature layer IFeatureClass featureClass = layer2Symbolize.FeatureClass; IField field = featureClass.Fields.get_Field(featureClass.FindField(strRendererField)); //Get a feature cursor ICursor cursor = (ICursor)layer2Symbolize.Search(null, false); //Create a DataStatistics object and initialize properties IDataStatistics dataStatistics = new DataStatisticsClass(); dataStatistics.Field = field.Name; dataStatistics.Cursor = cursor; //Get the result statistics IStatisticsResults statisticsResults = dataStatistics.Statistics; //Set the values min min and max values txtMinValue.Text = statisticsResults.Minimum.ToString(); txtMaxValue.Text = statisticsResults.Maximum.ToString(); } }
private void btn_ok_Click(object sender, EventArgs e) { IGeoFeatureLayer pGeoFeatureLayer = (IGeoFeatureLayer)m_FeatureLayer; //Find the selected field in the feature layer IFeatureClass featureClass = m_FeatureLayer.FeatureClass; string pFileName = cbx_Field.SelectedItem.ToString(); if (pFileName == "None") { MessageBox.Show("不可用的字段,请选择其它图层"); return; } IField field = featureClass.Fields.get_Field(featureClass.FindField(pFileName)); //Get a feature cursor ICursor cursor = (ICursor)m_FeatureLayer.Search(null, false); //Create a DataStatistics object and initialize properties IDataStatistics dataStatistics = new DataStatisticsClass(); dataStatistics.Field = field.Name; dataStatistics.Cursor = cursor; //Get the result statistics IStatisticsResults statisticsResults = dataStatistics.Statistics; //Set the values min min and max values m_MinOfField = statisticsResults.Minimum; m_MaxOfField = statisticsResults.Maximum; m_classBreaksRenderer = new ClassBreaksRenderer(); m_classBreaksRenderer.Field = cbx_Field.SelectedItem.ToString(); m_classBreaksRenderer.BreakCount = (int)numUD_TotalClasses.Value; m_classBreaksRenderer.MinimumBreak = m_MinOfField; double interval = (m_MaxOfField - m_MinOfField) / m_classBreaksRenderer.BreakCount; //Get the color ramp IColorRamp colorRamp = (IColorRamp)m_styleGalleryItem.Item; //Set the size of the color ramp and recreate it colorRamp.Size = Convert.ToInt32(numUD_TotalClasses.Value); bool createRamp; colorRamp.CreateRamp(out createRamp); //Get the enumeration of colors from the color ramp IEnumColors enumColors = colorRamp.Colors; enumColors.Reset(); double currentBreak = m_classBreaksRenderer.MinimumBreak; ISimpleFillSymbol simpleFillSymbol; //Loop rhough each class break for (int i = 0; i <= m_classBreaksRenderer.BreakCount - 1; i++) { //Set class break m_classBreaksRenderer.set_Break(i, currentBreak); //Create simple fill symbol and set color simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = enumColors.Next(); //Add symbol to renderer m_classBreaksRenderer.set_Symbol(i, (ISymbol)simpleFillSymbol); currentBreak += interval; } pGeoFeatureLayer.Renderer = (IFeatureRenderer)m_classBreaksRenderer; // geofeaturelayer.Renderer = (IFeatureRenderer)classBreaksRenderer; m_MapControl.ActiveView.ContentsChanged(); m_MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pGeoFeatureLayer, null); }
/// <summary> /// 矢量数据叠加分类统计 /// </summary> /// <param name="pSFeatClass">源要素类,必须为面要素类</param> /// <param name="zoneField">分区字段,整形或字符字段,该字段需要添加到统计结果表字段中</param> /// <param name="pTFeatClass">目标字段</param> /// <param name="FieldNames">统计字段列表,为数字字段</param> /// <param name="StatisticsTypes"> /// 统计方法列表,和统计字段列表相对应 /// 可用的统计方法字串如下:MIN, MAX, SUM, STD MEAN 最小值、最大值、总和、标准差, 平均值 /// </param> public IList FeatureClassOverlapStatistics(ITable pSTable, IPolygon pPolygon, string[] FieldNames, string[] StatisticsTypes) { IList arrayLists = new ArrayList(); string[] str = new string[(int)FieldNames.Length]; for (int i = 0; i < (int)FieldNames.Length; i++) { str[i] = "0"; } ICursor cursor = null; IDataStatistics dataStatisticsClass = null; ISpatialFilter spatialFilterClass = new SpatialFilter() { Geometry = pPolygon, SpatialRel = esriSpatialRelEnum.esriSpatialRelContains }; for (int j = 0; j < (int)FieldNames.Length; j++) { if (dataStatisticsClass != null) { Marshal.ReleaseComObject(dataStatisticsClass); dataStatisticsClass = null; } dataStatisticsClass = new DataStatistics() { Field = FieldNames[j] }; cursor = pSTable.Search(spatialFilterClass, true); dataStatisticsClass.Cursor = cursor; IStatisticsResults statistics = dataStatisticsClass.Statistics; if (statistics.Count > 0) { double sum = 0; string statisticsTypes = StatisticsTypes[j]; if (statisticsTypes != null) { if (statisticsTypes == "SUM") { sum = statistics.Sum; } else if (statisticsTypes == "MAX") { sum = statistics.Maximum; } else if (statisticsTypes == "MIN") { sum = statistics.Minimum; } else if (statisticsTypes == "STD") { sum = statistics.StandardDeviation; } else if (statisticsTypes == "MEAN") { sum = statistics.Mean; } } str[j] = sum.ToString(); } Marshal.ReleaseComObject(cursor); cursor = null; statistics = null; } arrayLists.Add(str); return(arrayLists); }
private void btnApply_Click(object sender, EventArgs e) { try { //Declare variables clsSnippet pSnippet = new clsSnippet(); string strLayerName = cboSourceLayer.Text; int intLIndex = pSnippet.GetIndexNumberFromLayerName(pActiveView, strLayerName); ILayer pLayer = mForm.axMapControl1.get_Layer(intLIndex); IFeatureLayer pFLayer = pLayer as IFeatureLayer; IFeatureClass pFClass = pFLayer.FeatureClass; string strOriRenderField = cboValueField.Text; string strUncernRenderField = CboUField.Text; string strConLevelField = nudConfidenceLevel.Value.ToString(); if (strOriRenderField == "" || strUncernRenderField == "") { MessageBox.Show("Plese choose field names"); return; } //Find Fields ITable pTable = (ITable)pFClass; int intOriIdx = pTable.FindField(strOriRenderField); int intUncernIdx = pTable.FindField(strUncernRenderField); //Create Geofeature Layer IGeoFeatureLayer pGeofeatureLayer = null; 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; } //Calculate confidence levels Chart pChart = new Chart(); double dblConInstance = pChart.DataManipulator.Statistics.InverseNormalDistribution(Convert.ToDouble(nudConfidenceLevel.Value) / 100); if (tcUncer.SelectedIndex == 0) //Proportional symbol composite layers { double dblMinPtSize = Convert.ToDouble(nudSymbolSize.Value); //Find max value at attribute to set to initial value for finding Min value at composite symbols IField pOriField = pTable.Fields.get_Field(intOriIdx); ICursor pCursor = pTable.Search(null, false); IDataStatistics pDataStat = new DataStatisticsClass(); pDataStat.Field = pOriField.Name; pDataStat.Cursor = pCursor; IStatisticsResults pStatResults = pDataStat.Statistics; double dblMinValue = pStatResults.Maximum; pCursor.Flush(); pCursor = pTable.Search(null, false); IRow pRow = pCursor.NextRow(); double dblValue = 0; //Cacluate Min and Max value based on the confidence intervals //Min while (pRow != null) { dblValue = Convert.ToDouble(pRow.get_Value(intOriIdx)) - (Convert.ToDouble(pRow.get_Value(intUncernIdx)) * dblConInstance); if (dblValue < dblMinValue) { dblMinValue = dblValue; } pRow = pCursor.NextRow(); } //Max pCursor.Flush(); double dblMaxValue = 0; pCursor = pTable.Search(null, false); pRow = pCursor.NextRow(); dblValue = 0; //Cacluate Min and Max value based on the confidence intervals while (pRow != null) { dblValue = Convert.ToDouble(pRow.get_Value(intOriIdx)) + (Convert.ToDouble(pRow.get_Value(intUncernIdx)) * dblConInstance); if (dblValue > dblMaxValue) { dblMaxValue = dblValue; } pRow = pCursor.NextRow(); } //To adjust min value to 1, if the min value is zero double dbladjuctMinvalue = 0; if (dblMinValue <= 0) { dbladjuctMinvalue = (0 - dblMinValue) + 1; dblMinValue = dblMinValue + dbladjuctMinvalue; } //Loading uncertainty proportional symbol renderer IDisplay pDisplay = pActiveView.ScreenDisplay; UncernVis.BivariateRenderer.IPropCompositeRenderer pUnProprotional = new UncernVis.BivariateRenderer.PropCompositeRenderer(); pUnProprotional.m_dblMinPtSize = dblMinPtSize; pUnProprotional.m_dblMinValue = dblMinValue; pUnProprotional.m_dblMaxValue = dblMaxValue; pUnProprotional.m_dblOutlineSize = Convert.ToDouble(nudLinewidth.Value); pUnProprotional.m_dblAdjustedMinValue = dbladjuctMinvalue; IRgbColor pSymbolRgb = new RgbColorClass(); pSymbolRgb.Red = picSymbolColor.BackColor.R; pSymbolRgb.Green = picSymbolColor.BackColor.G; pSymbolRgb.Blue = picSymbolColor.BackColor.B; IRgbColor pLineRgb = new RgbColorClass(); pLineRgb.Red = picLineColor.BackColor.R; pLineRgb.Green = picLineColor.BackColor.G; pLineRgb.Blue = picLineColor.BackColor.B; pUnProprotional.m_pLineRgb = pLineRgb; pUnProprotional.m_pSymbolRgb = pSymbolRgb; pUnProprotional.m_strUncernRenderField = strUncernRenderField; pUnProprotional.m_strOriRenderField = strOriRenderField; pUnProprotional.m_dblConInstance = dblConInstance; pUnProprotional.m_pGeometryTypes = pFClass.ShapeType; //Create Legend pUnProprotional.CreateLegend(); pGeofeatureLayer.Renderer = (IFeatureRenderer)pUnProprotional; if (chkNewLayer.Checked == true) { mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGeofeatureLayer); } else { pFLayer = (IFeatureLayer)pGeofeatureLayer; } } else if (tcUncer.SelectedIndex == 1) // Chart composite symbols { double dblChartWidth = Convert.ToDouble(nudChartWidth.Value); double dblChartSize = Convert.ToDouble(nudChartSize.Value); double dblThickness = Convert.ToDouble(nudThickness.Value); //Cacluate Max value based on the confidence intervals ICursor pCursor = (ICursor)pFClass.Search(null, false); IRow pRow = pCursor.NextRow(); double dblMaxValue = 0; double dblTempValue = 0; double dblMaxEstimate = 0; double dblMaxUncern = 0; double dblTempEstimate = 0; double dblTempUncern = 0; while (pRow != null) { dblTempEstimate = Convert.ToDouble(pRow.get_Value(intOriIdx)); dblTempUncern = Convert.ToDouble(pRow.get_Value(intUncernIdx)) * dblConInstance; dblTempValue = dblTempEstimate + dblTempUncern; if (dblTempValue > dblMaxValue) { dblMaxValue = dblTempValue; dblMaxEstimate = dblTempEstimate; dblMaxUncern = dblTempUncern; } pRow = pCursor.NextRow(); } pCursor.Flush(); //IFeatureCursor pFCursor = pGeofeatureLayer.Search(null, true); IChartCompositeRenderer pChartCompositeRenderer = new ChartCompositeRenderer(); pChartCompositeRenderer.m_dblConInstance = dblConInstance; pChartCompositeRenderer.m_dblMaxValue = dblMaxValue; pChartCompositeRenderer.m_bln3Dfeature = chk3D.Checked; pChartCompositeRenderer.m_strOriRenderField = strOriRenderField; pChartCompositeRenderer.m_strUncernRenderField = strUncernRenderField; pChartCompositeRenderer.m_dblMaxEstimate = dblMaxEstimate; pChartCompositeRenderer.m_dblMaxUncern = dblMaxUncern; pChartCompositeRenderer.m_dblBarWidth = dblChartWidth; pChartCompositeRenderer.m_dblBarSize = dblChartSize; pChartCompositeRenderer.m_dblThickness = dblThickness; pChartCompositeRenderer.CreateLegend(); pGeofeatureLayer.Renderer = pChartCompositeRenderer as IFeatureRenderer; if (chkNewLayer.Checked == true) { mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGeofeatureLayer); } else { pFLayer = (IFeatureLayer)pGeofeatureLayer; } } else if (tcUncer.SelectedIndex == 2) //For Line Symbol { double dblMinPtSize = Convert.ToDouble(nudMinWidth.Value); //Find max value at attribute to set to initial value for finding Min value at composite symbols IField pOriField = pTable.Fields.get_Field(intOriIdx); ICursor pCursor = pTable.Search(null, false); IDataStatistics pDataStat = new DataStatisticsClass(); pDataStat.Field = pOriField.Name; pDataStat.Cursor = pCursor; IStatisticsResults pStatResults = pDataStat.Statistics; double dblMinValue = pStatResults.Maximum; pCursor.Flush(); pCursor = pTable.Search(null, false); IRow pRow = pCursor.NextRow(); double dblValue = 0; //Cacluate Min and Max value based on the confidence intervals //Min while (pRow != null) { dblValue = Convert.ToDouble(pRow.get_Value(intOriIdx)) - (Convert.ToDouble(pRow.get_Value(intUncernIdx)) * dblConInstance); if (dblValue < dblMinValue) { dblMinValue = dblValue; } pRow = pCursor.NextRow(); } //Max pCursor.Flush(); double dblMaxValue = 0; pCursor = pTable.Search(null, false); pRow = pCursor.NextRow(); dblValue = 0; //Cacluate Min and Max value based on the confidence intervals while (pRow != null) { dblValue = Convert.ToDouble(pRow.get_Value(intOriIdx)) + (Convert.ToDouble(pRow.get_Value(intUncernIdx)) * dblConInstance); if (dblValue > dblMaxValue) { dblMaxValue = dblValue; } pRow = pCursor.NextRow(); } //To adjust min value to 1, if the min value is zero double dbladjuctMinvalue = 0; if (dblMinValue <= 0) { dbladjuctMinvalue = (0 - dblMinValue) + 1; dblMinValue = dblMinValue + dbladjuctMinvalue; } //Loading uncertainty proportional symbol renderer IDisplay pDisplay = pActiveView.ScreenDisplay; UncernVis.BivariateRenderer.IPropCompositeRenderer pUnProprotional = new UncernVis.BivariateRenderer.PropCompositeRenderer(); pUnProprotional.m_dblMinPtSize = dblMinPtSize; pUnProprotional.m_dblMinValue = dblMinValue; pUnProprotional.m_dblMaxValue = dblMaxValue; pUnProprotional.m_dblOutlineSize = 0; pUnProprotional.m_dblAdjustedMinValue = dbladjuctMinvalue; IRgbColor pSymbolRgb = pSnippet.getRGB(picLineConColor.BackColor.R, picLineConColor.BackColor.G, picLineConColor.BackColor.B); //pSymbolRgb.Red = picSymbolColor.BackColor.R; //pSymbolRgb.Green = picSymbolColor.BackColor.G; //pSymbolRgb.Blue = picSymbolColor.BackColor.B; IRgbColor pLineRgb = pSnippet.getRGB(picLineCntColor.BackColor.R, picLineCntColor.BackColor.G, picLineCntColor.BackColor.B); //pLineRgb.Red = picLineColor.BackColor.R; //pLineRgb.Green = picLineColor.BackColor.G; //pLineRgb.Blue = picLineColor.BackColor.B; pUnProprotional.m_pLineRgb = pLineRgb; pUnProprotional.m_pSymbolRgb = pSymbolRgb; pUnProprotional.m_strUncernRenderField = strUncernRenderField; pUnProprotional.m_strOriRenderField = strOriRenderField; pUnProprotional.m_dblConInstance = dblConInstance; pUnProprotional.m_pGeometryTypes = pFClass.ShapeType; //Create Legend pUnProprotional.CreateLegend(); pGeofeatureLayer.Renderer = (IFeatureRenderer)pUnProprotional; if (chkNewLayer.Checked == true) { mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGeofeatureLayer); } else { pFLayer = (IFeatureLayer)pGeofeatureLayer; } } mForm.axMapControl1.ActiveView.Refresh(); mForm.axTOCControl1.Update(); } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
private IClassBreaksRenderer CreateClassBreaksRenderer(IFeatureClass featureClass, string breakMethod) { ITable pTable = (ITable)featureClass; //从pTable的strRendererField字段中得到信息给datavalues和datafrequency两个数组 ITableHistogram pTableHistogram = new BasicTableHistogramClass(); IBasicHistogram pHistogram = (IBasicHistogram)pTableHistogram; pTableHistogram.Field = strRendererField; if (strNormalizeField.ToLower() != "none") { pTableHistogram.NormField = strNormalizeField; } pTableHistogram.Table = pTable; object dataFrequency; object dataValues; pHistogram.GetHistogram(out dataValues, out dataFrequency); //下面是分级方法,用于根据获得的值计算得出符合要求的数据 //根据条件计算出Classes和ClassesCount,numDesiredClasses为预定的分级数目 IClassifyGEN pClassify = null; int numDesiredClasses = classCount; switch (breakMethod) { case "等间隔": pClassify = new EqualIntervalClass(); break; case "已定义的间隔": pClassify = new DefinedIntervalClass(); IIntervalRange2 intervalRange = pClassify as IIntervalRange2; intervalRange.IntervalRange = dblDefinedInterval; break; case "分位数": pClassify = new QuantileClass(); break; case "自然裂点": pClassify = new NaturalBreaksClass(); break; case "标准差": pClassify = new StandardDeviationClass(); IStatisticsResults pStatRes = pHistogram as IStatisticsResults; IDeviationInterval pStdDev = pClassify as IDeviationInterval; pStdDev.Mean = pStatRes.Mean; pStdDev.StandardDev = pStatRes.StandardDeviation; pStdDev.DeviationInterval = dblStdDevInterval; break; default: break; } if (pClassify == null) { return(null); } pClassify.Classify(dataValues, dataFrequency, ref numDesiredClasses); //返回一个数组 double[] classBreaks = (double[])pClassify.ClassBreaks; int ClassesCount = classBreaks.GetUpperBound(0); nudClassCount.Value = ClassesCount; IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass(); pClassBreaksRenderer.Field = strRendererField; if (strNormalizeField.ToLower() != "none") { pClassBreaksRenderer.NormField = strNormalizeField; } //设置着色对象的分级数目 pClassBreaksRenderer.BreakCount = ClassesCount; pClassBreaksRenderer.SortClassesAscending = true; if (colorRamp == null) { MessageBox.Show("请先选择色带!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } //通过色带设置各级分类符号的颜色 colorRamp.Size = ClassesCount; bool createRamp; colorRamp.CreateRamp(out createRamp); IEnumColors enumColors = colorRamp.Colors; enumColors.Reset(); IColor pColor = null; ISymbol symbol = null; if (gloabalSymbol == null) { MessageBox.Show("请选择符号...", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } //需要注意的是分级着色对象中的symbol和break的下标都是从0开始 for (int i = 0; i < ClassesCount; i++) { pColor = enumColors.Next(); switch (featureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: IMarkerSymbol markerSymbol = gloabalSymbol as IMarkerSymbol; markerSymbol.Color = pColor; symbol = markerSymbol as ISymbol; break; case esriGeometryType.esriGeometryPolyline: ILineSymbol lineSymbol = gloabalSymbol as ILineSymbol; lineSymbol.Color = pColor; symbol = lineSymbol as ISymbol; break; case esriGeometryType.esriGeometryPolygon: IFillSymbol fillSymbol = gloabalSymbol as IFillSymbol; fillSymbol.Color = pColor; symbol = fillSymbol as ISymbol; break; default: break; } pClassBreaksRenderer.set_Symbol(i, symbol); pClassBreaksRenderer.set_Break(i, classBreaks[i + 1]); } return(pClassBreaksRenderer); }
private void btnApply_Click(object sender, EventArgs e) { try { //Declare variables clsSnippet pSnippet = new clsSnippet(); string strLayerName = cboSourceLayer.Text; int intLIndex = pSnippet.GetIndexNumberFromLayerName(pActiveView, strLayerName); ILayer pLayer = mForm.axMapControl1.get_Layer(intLIndex); IFeatureLayer pFLayer = pLayer as IFeatureLayer; ESRI.ArcGIS.Geodatabase.IFeatureClass pFClass = pFLayer.FeatureClass; string strOriRenderField = cboValueField.Text; string strUncernRenderField = cboUField.Text; double dblMinPtSize = Convert.ToDouble(nudSymbolSize.Value); //Create New Layer? IGeoFeatureLayer pGeofeatureLayer = null; 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; } //Find Fields ITable pTable = (ITable)pFClass; int intOriIdx = pTable.FindField(strOriRenderField); int intUncernIdx = pTable.FindField(strUncernRenderField); //Find Min and Max Ori Value IField pOriField = pTable.Fields.get_Field(intOriIdx); ICursor pCursor = pTable.Search(null, true); IDataStatistics pDataStat = new DataStatisticsClass(); pDataStat.Field = pOriField.Name; pDataStat.Cursor = pCursor; IStatisticsResults pStatResults = pDataStat.Statistics; double dblMinOriValue = pStatResults.Minimum; double dblMaxOriValue = pStatResults.Maximum; pCursor.Flush(); //Find Min and Max Uncern Vale IField pUncernField = pTable.Fields.get_Field(intUncernIdx); pCursor = pTable.Search(null, true); pDataStat = new DataStatisticsClass(); pDataStat.Field = pUncernField.Name; pDataStat.Cursor = pCursor; pStatResults = pDataStat.Statistics; double dblMinUncernValue = pStatResults.Minimum; double dblMaxUncernValue = pStatResults.Maximum; pCursor.Flush(); //To adjust minn value to 1, if the min value is zero double dbladjuctMinvalue = 0; if (dblMinOriValue <= 0) { dbladjuctMinvalue = (0 - dblMinOriValue) + 1; dblMinOriValue = dblMinOriValue + dbladjuctMinvalue; } IDisplay pDisplay = pActiveView.ScreenDisplay; IRgbColor pSymbolRgb = new RgbColorClass(); pSymbolRgb.Red = picSymbolColor.BackColor.R; pSymbolRgb.Green = picSymbolColor.BackColor.G; pSymbolRgb.Blue = picSymbolColor.BackColor.B; IRgbColor pLineRgb = new RgbColorClass(); pLineRgb.Red = picLineColor.BackColor.R; pLineRgb.Green = picLineColor.BackColor.G; pLineRgb.Blue = picLineColor.BackColor.B; int intMethods = 0; if (cboMethods.Text == "Saturation") { intMethods = 1; } else if (cboMethods.Text == "Value") { intMethods = 2; } else if (cboMethods.Text == "Whiteness") { intMethods = 3; } IColoringProperties pPreUncern = new ColoringPropClass2(); //IColoringProperties pPreUncern = new ColoringProp(); pPreUncern.m_intMethods = intMethods; pPreUncern.m_intOriLegendCount = 3; //Needs to be changed pPreUncern.m_intUncernLegendCount = 3; //Needs to be changed pPreUncern.m_strOriRenderField = strOriRenderField; pPreUncern.m_strUncernRenderField = strUncernRenderField; pPreUncern.m_pSymbolRgb = pSymbolRgb; pPreUncern.m_pLineRgb = pLineRgb; pPreUncern.m_dblOutlineSize = Convert.ToDouble(nudLinewidth.Value); pPreUncern.m_dblAdjustedMinValue = dbladjuctMinvalue; pPreUncern.m_dblMinOriValue = dblMinOriValue; pPreUncern.m_dblMaxOriValue = dblMaxOriValue; pPreUncern.m_dblMinUncernValue = dblMinUncernValue; pPreUncern.m_dblMaxUncernValue = dblMaxUncernValue; pPreUncern.m_dblMinPtSize = dblMinPtSize; pPreUncern.CreateLegend(); pGeofeatureLayer.Renderer = (IFeatureRenderer)pPreUncern; if (chkNewLayer.Checked == true) { mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGeofeatureLayer); } else { pFLayer = (IFeatureLayer)pGeofeatureLayer; } mForm.axTOCControl1.Update(); mForm.axMapControl1.ActiveView.Refresh(); } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
private IElement method_3(IRow irow_0, IPageLayout ipageLayout_0) { ITable table = irow_0.Table; ElementsTableStruct struct2 = new ElementsTableStruct(); object obj2 = irow_0.get_Value(table.FindField(struct2.AttributesFieldName)); IElement element = this.method_2(obj2); if (element is ITextElement) { string text = (element as ITextElement).Text; if (text[0] == '=') { string[] strArray = text.Substring(1, text.Length - 1).Split(new char[] { '!' }); if (strArray[0] == "Field") { string str3; string str4; string str2 = ""; string[] strArray2 = strArray[1].Split(new char[] { '.' }); if (strArray2.Length > 2) { str2 = strArray2[0]; str3 = strArray2[1].Substring(1, strArray2[0].Length - 2); str4 = strArray2[2].Substring(1, strArray2[1].Length - 2); } else { str3 = strArray2[0].Substring(1, strArray2[0].Length - 2); str4 = strArray2[1].Substring(1, strArray2[1].Length - 2); } string str5 = ""; IQueryFilter queryFilter = null; if (strArray.Length >= 3) { queryFilter = new QueryFilterClass(); string[] strArray3 = strArray[2].Split(new char[] { '#' }); int index = 0; bool flag = true; for (index = 0; index < strArray3.Length; index++) { if (flag) { str5 = str5 + " " + strArray3[index]; } else { str5 = str5 + " " + this.hashtable_0[strArray3[index]].ToString(); } flag = !flag; } queryFilter.WhereClause = str5; } try { ITable table2 = ((irow_0.Table as IDataset).Workspace as IFeatureWorkspace).OpenTable(str3); ICursor o = table2.Search(queryFilter, false); IDataStatistics statistics = null; statistics = new DataStatisticsClass { Field = str4, Cursor = o }; IStatisticsResults results = statistics.Statistics; string str6 = str2; switch (str6) { case null: break; case "SUM": (element as ITextElement).Text = results.Sum.ToString(); goto Label_034E; case "MAX": (element as ITextElement).Text = results.Maximum.ToString(); goto Label_034E; case "MIN": (element as ITextElement).Text = results.Minimum.ToString(); goto Label_034E; default: if (str6 != "STD") { if (str6 != "MEAN") { break; } (element as ITextElement).Text = results.Mean.ToString(); } else { (element as ITextElement).Text = results.StandardDeviation.ToString(); } goto Label_034E; } IRow row = o.NextRow(); if (row != null) { try { string str7 = row.get_Value(table2.FindField(str4)).ToString(); (element as ITextElement).Text = str7; } catch { } } Label_034E: ComReleaser.ReleaseCOMObject(o); } catch { } } else if (strArray[0] == "Param") { try { (element as ITextElement).Text = this.hashtable_0[strArray[1]].ToString(); } catch { } } } } if (element != null) { int num3; double num4; double num5; IEnvelope envelope; object obj3 = irow_0.get_Value(table.FindField(struct2.LocationFieldName)).ToString(); if (obj3 is DBNull) { return(element); } IPoint p = this.method_4(obj3.ToString(), ipageLayout_0, out num3, out num4, out num5); if (element is ITextElement) { if ((element as IElementProperties).Type == "竖向") { string str8 = this.method_1((element as ITextElement).Text); (element as ITextElement).Text = str8; } element.Geometry = p; return(element); } if (element is IMapSurroundFrame) { envelope = element.Geometry.Envelope; envelope.CenterAt(p); element.Geometry = envelope; return(element); } envelope = element.Geometry.Envelope; envelope.CenterAt(p); element.Geometry = envelope; } return(element); }
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; } }
/// <summary> /// 获得字段统计值 /// </summary> /// <param name="table">统计的表格</param> /// <param name="fieldName">统计的字段</param> /// <param name="whereClause">统计条件</param> /// <param name="eType">统计值类型</param> /// <returns></returns> public static double Statistics(this ITable table, string fieldName, string whereClause, EStatisticsType eType) { IStatisticsResults statisticsResults = Statistics(table, fieldName, whereClause); return(StatisticsByType(statisticsResults, eType)); }
private void btnRun_Click(object sender, EventArgs e) { if (cboFldnm1.Text == "" || cboFldnm2.Text == "") { MessageBox.Show("Please select target field"); return; } frmProgress pfrmProgress = new frmProgress(); pfrmProgress.lblStatus.Text = "Processing:"; pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee; pfrmProgress.Show(); REngine pEngine = m_pForm.pEngine; int nFeature = m_pFClass.FeatureCount(null); IFeatureCursor pFCursor = m_pFClass.Search(null, true); IFeature pFeature = pFCursor.NextFeature(); //Get index for independent and dependent variables //Get variable index string strVarNM1 = (string)cboFldnm1.SelectedItem; string strVarNM2 = (string)cboFldnm2.SelectedItem; int intVarIdx1 = m_pFClass.FindField(strVarNM1); int intVarIdx2 = m_pFClass.FindField(strVarNM2); //Store Variable at Array double[] arrVar1 = new double[nFeature]; double[] arrVar2 = new double[nFeature]; int i = 0; while (pFeature != null) { arrVar1[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx1)); arrVar2[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx2)); i++; pFeature = pFCursor.NextFeature(); } pFCursor.Flush(); //Plot command for R StringBuilder plotCommmand = new StringBuilder(); string strStartPath = m_pForm.strPath; string pathr = strStartPath.Replace(@"\", @"/"); pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_LARRY.R')"); pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_neighbor.R')"); pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_SASbi.R')"); //Get the file path and name to create spatial weight matrix string strNameR = m_pSnippet.FilePathinRfromLayer(m_pFLayer); if (strNameR == null) { return; } //Create spatial weight matrix in R pEngine.Evaluate("library(spdep); library(maptools)"); pEngine.Evaluate("sample.shp <- readShapePoly('" + strNameR + "')"); //pEngine.Evaluate("sample.nb <- poly2nb(sample.shp, queen=FALSE)"); pEngine.Evaluate("sample.nb <- poly2nb(sample.shp)"); NumericVector vecVar1 = pEngine.CreateNumericVector(arrVar1); pEngine.SetSymbol("sample.v1", vecVar1); NumericVector vecVar2 = pEngine.CreateNumericVector(arrVar2); pEngine.SetSymbol("sample.v2", vecVar2); //string strRSigLv = nudRsigLv.Value.ToString(); //string strLSigLv = nudLsigLv.Value.ToString(); //string strLSig = cboLocalL.Text; //string strRsig = cboLocalPearson.Text; //string strRowStd = cboRowStandardization.Text; //string strMaxRanges = nudMaxRange.Value.ToString(); //string strHigherOrder = cboHigherOrder.Text; string strNonZero = null; if (chkDiagZero.Checked) { strNonZero = "FALSE"; } else { strNonZero = "TRUE"; } double[] dblLoclLisa = null; if (cboMeasure.Text == "Lee's L") { pEngine.Evaluate("sample.result <- LARRY.bivariate.LISA.lee(sample.v1, sample.v2, 1:length(sample.nb), sample.nb, style = 'W', diag.zero = " + strNonZero + ")"); dblLoclLisa = pEngine.Evaluate("as.numeric(sample.result$local.L)").AsNumeric().ToArray(); } else if (cboMeasure.Text == "Local Pearson") { pEngine.Evaluate("sample.result <- LARRY.bivariate.LISA.pearson(sample.v1, sample.v2, 1:length(sample.nb))"); if (cboMapOption.Text == "Local Pearson") { dblLoclLisa = pEngine.Evaluate("as.numeric(sample.result$local.pearson)").AsNumeric().ToArray(); } else if (cboMapOption.Text == "z-score of variable 1") { dblLoclLisa = pEngine.Evaluate("as.numeric(sample.result$z.x)").AsNumeric().ToArray(); } else if (cboMapOption.Text == "z-score of variable 2") { dblLoclLisa = pEngine.Evaluate("as.numeric(sample.result$z.y)").AsNumeric().ToArray(); } } //Save Output on SHP //Add Target fields to store results in the shapefile // Keep loop for (int j = 0; j < 1; j++) { string strfldName = lvFields.Items[j].SubItems[1].Text; if (m_pFClass.FindField(strfldName) == -1) { IField newField = new FieldClass(); IFieldEdit fieldEdit = (IFieldEdit)newField; fieldEdit.Name_2 = strfldName; fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; m_pFClass.AddField(newField); } } //Update Field pFCursor = m_pFClass.Update(null, false); pFeature = pFCursor.NextFeature(); string strLocalLISAFldName = lvFields.Items[0].SubItems[1].Text; int intSpQuadFldIdx = m_pFClass.FindField(strLocalLISAFldName); int featureIdx = 0; while (pFeature != null) { pFeature.set_Value(intSpQuadFldIdx, dblLoclLisa[featureIdx]); pFCursor.UpdateFeature(pFeature); pFeature = pFCursor.NextFeature(); featureIdx++; } pFCursor.Flush(); if (chkMap.Checked) { ITable pTable = (ITable)m_pFClass; pFCursor = m_pFClass.Search(null, false); IDataStatistics pDataStat = new DataStatisticsClass(); pDataStat.Field = strLocalLISAFldName; pDataStat.Cursor = (ICursor)pFCursor; IStatisticsResults pStatResults = pDataStat.Statistics; double dblMax = pStatResults.Maximum; double dblMin = pStatResults.Minimum; int intBreaksCount = m_pBiLISASym.Length + 1; double[] cb = new double[intBreaksCount]; //Assign Min and Max values for class breaks cb[0] = dblMin; cb[intBreaksCount - 1] = dblMax; for (int k = 0; k < intBreaksCount - 2; k++) { cb[k + 1] = m_pBiLISASym[k].UValue; } IClassBreaksRenderer pCBRenderer = new ClassBreaksRenderer(); pCBRenderer.Field = strLocalLISAFldName; pCBRenderer.BreakCount = intBreaksCount - 1; pCBRenderer.MinimumBreak = cb[0]; //' use this interface to set dialog properties IClassBreaksUIProperties pUIProperties = (IClassBreaksUIProperties)pCBRenderer; pUIProperties.ColorRamp = "Custom"; ISimpleFillSymbol pSimpleFillSym; //int[,] arrColors = CreateColorRamp(); ////Add Probability Value Manually //string[] strsProbLabels = new string[] { "(0.01)", "(0.05)", "(0.1)", "(0.1)", "(0.05)", "(0.01)" }; //' be careful, indices are different for the diff lists for (int j = 0; j < intBreaksCount - 1; j++) { pCBRenderer.Break[j] = cb[j + 1]; pCBRenderer.Label[j] = m_pBiLISASym[j].Label; pUIProperties.LowBreak[j] = cb[j]; pSimpleFillSym = new SimpleFillSymbolClass(); IRgbColor pRGBColor = m_pSnippet.getRGB(m_pBiLISASym[j].R, m_pBiLISASym[j].G, m_pBiLISASym[j].B); pSimpleFillSym.Color = (IColor)pRGBColor; pCBRenderer.Symbol[j] = (ISymbol)pSimpleFillSym; } IFeatureLayer pNewFLayer = new FeatureLayerClass(); pNewFLayer.FeatureClass = m_pFClass; pNewFLayer.Name = lvFields.Items[0].SubItems[0].Text + " of " + m_pFLayer.Name; IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pNewFLayer; pGFLayer.Renderer = (IFeatureRenderer)pCBRenderer; m_pActiveView.FocusMap.AddLayer(pGFLayer); m_pActiveView.Refresh(); m_pForm.axTOCControl1.Update(); pfrmProgress.Close(); } else { MessageBox.Show("Complete. The results are stored in the shape file"); } }