private void _muiStaticFeature_Click(object sender, EventArgs e)
{
TreeNode tNode = this._tevCatalog.SelectedNode;
TreeNode tChildNode = new TreeNode();
ESRI.ArcGIS.Geodatabase.IFeature pFeature;
ESRI.ArcGIS.Geodatabase.IFeatureClass pFeatureClass;
ESRI.ArcGIS.Geodatabase.IFeatureCursor pCursor;
ESRI.ArcGIS.Carto.IFeatureLayer pFeatureLayer;
ESRI.ArcGIS.Geodatabase.IQueryFilter pQuery = new QueryFilterClass();
YJDSoft.Maps.MapManager.Forms.FeatureCalculate frmFeatureCalculate = new YJDSoft.Maps.MapManager.Forms.FeatureCalculate();
this.iPointCalculate = 0;
this.iLineCalculate = 0;
this.iPolygonCalculate = 0;
//当所选节点为叶子节点时的要素个数统计
if(tNode!=null && tNode.FirstNode == null)
{
//获取图层信息,放到变量layerinfo中
if (layerinfo!=null)
{
pFeatureLayer = layerinfo.Layer as IFeatureLayer;
pFeatureClass = pFeatureLayer.FeatureClass;
try
{
pCursor = pFeatureClass.Search(pQuery,false);
pFeature = pCursor.NextFeature();
}
catch(Exception err)
{
MessageBox.Show(err.Message,"错误提示", MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
if(pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
{
frmFeatureCalculate.iPointCount = pFeatureLayer.FeatureClass.FeatureCount(pQuery);
}
if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline||pFeature.Shape.GeometryType == esriGeometryType.esriGeometryLine)
{
frmFeatureCalculate.iLineCount = pFeatureLayer.FeatureClass.FeatureCount(pQuery);
}
if(pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
{
frmFeatureCalculate.iPolygonCount= pFeatureLayer.FeatureClass.FeatureCount(pQuery);
}
}
}
//当所选节点有子节点时的要素个数统计
if(tNode!=null && tNode.FirstNode!=null)
{
this.calculateFeature(tNode);
frmFeatureCalculate.iPointCount = this.iPointCalculate;
frmFeatureCalculate.iLineCount = this.iLineCalculate;
frmFeatureCalculate.iPolygonCount = this.iPolygonCalculate;
}
frmFeatureCalculate.Show();
}
//遍历所选节点的所有子节点,并且计算要素的个数
public void calculateFeature(TreeNode SelectedNode)
{
ESRI.ArcGIS.Geodatabase.IFeature pFeature;
ESRI.ArcGIS.Geodatabase.IFeatureClass pFeatureClass;
ESRI.ArcGIS.Geodatabase.IFeatureCursor pCursor;
ESRI.ArcGIS.Carto.IFeatureLayer pFeatureLayer;
ESRI.ArcGIS.Geodatabase.IQueryFilter pQuery = new QueryFilterClass();
if(SelectedNode!=null && SelectedNode.FirstNode!=null )
{
foreach(TreeNode tn in SelectedNode.Nodes)
{
//获取图层信息,放到变量layerinfo中
if (layerinfo!=null)
{
pFeatureLayer = layerinfo.Layer as IFeatureLayer;
pFeatureClass = pFeatureLayer.FeatureClass;
try
{
pCursor = pFeatureClass.Search(pQuery,false);
pFeature = pCursor.NextFeature();
}
catch(Exception err)
{
MessageBox.Show(err.Message,"错误提示", MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
if(pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
{
this.iPointCalculate += pFeatureLayer.FeatureClass.FeatureCount(pQuery);
}
if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline||pFeature.Shape.GeometryType == esriGeometryType.esriGeometryLine)
{
this.iLineCalculate += pFeatureLayer.FeatureClass.FeatureCount(pQuery);
}
if(pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
{
this.iPolygonCalculate += pFeatureLayer.FeatureClass.FeatureCount(pQuery);
}
}
this.calculateFeature(tn);
}
}
}
浙公网安备 33010602011771号