概述
要求:需要统计的字段必须是数字类型的数据:
主要使用的核心接口有:IDataStatistics和IStaticsResults。类有:BaseStatisticsClass
思路:
由于IStaticsResults中有统计的相关属性(max、min、sum、mean等),BaseStatisticsClass为实现类,所以需要图层中的某个接口跳到IStaticsResults接口;所以使用IDataStatistics中的Statistics属性;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
namespace staticsgistest
{
public partial class Form1 : Form
{
public Form1()
{
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
//min
private void button1_Click(object sender, EventArgs e)
{
IFeatureLayer lyr = axMapControl1.Map.get_Layer(0) as IFeatureLayer;
IFeatureCursor feacursor = lyr.FeatureClass.Search(null,true);//true表示只读
IDataStatistics statics = new DataStatisticsClass();
statics.Cursor = feacursor as ICursor;//传入图层中的属性表的游标
statics.Field = "cd";
IStatisticsResults iss = statics.Statistics;
double count = iss.Minimum;
MessageBox.Show(count.ToString());
}
//max
private void button2_Click(object sender, EventArgs e)
{
IFeatureLayer lyr = axMapControl1.Map.get_Layer(0) as IFeatureLayer;
IFeatureCursor feacursor = lyr.FeatureClass.Search(null, true);//true表示只读
IDataStatistics statics = new DataStatisticsClass();
statics.Cursor = feacursor as ICursor;
statics.Field = "cd";
IStatisticsResults iss = statics.Statistics;
double count = iss.Maximum;
MessageBox.Show(count.ToString());
}
private void button3_Click(object sender, EventArgs e)
{
IFeatureLayer lyr = axMapControl1.Map.get_Layer(0) as IFeatureLayer;
IFeatureCursor feacursor = lyr.FeatureClass.Search(null, true);//true表示只读
IDataStatistics statics = new DataStatisticsClass();
statics.Cursor = feacursor as ICursor;
statics.Field = "cd";
IStatisticsResults iss = statics.Statistics;
double count = iss.Sum;
MessageBox.Show(count.ToString());
}
private void button4_Click(object sender, EventArgs e)
{
IFeatureLayer lyr = axMapControl1.Map.get_Layer(0) as IFeatureLayer;
IFeatureCursor feacursor = lyr.FeatureClass.Search(null, true);//true表示只读
IDataStatistics statics = new DataStatisticsClass();
statics.Cursor = feacursor as ICursor;
statics.Field = "cd";
IStatisticsResults iss = statics.Statistics;
double count = iss.Count;
MessageBox.Show(count.ToString());
}
}
}
最后
以上就是聪慧煎蛋为你收集整理的AE实现对矢量数据的字段值进行最大值、最小值、求和、平均值、方差统计:...的全部内容,希望文章能够帮你解决AE实现对矢量数据的字段值进行最大值、最小值、求和、平均值、方差统计:...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复