思路: 1. 首先 获取整个图层的Extend 获取到 Extend的右下角点坐标 Extend.LowerRight
2.然后循环图层内的要素 用要素的Envelope.UpperLeft去和 Extend.LowerRight 的 x 和y 做比较 需要用到递归
具体实现:
/// <summary>
/// 图层要素按照从上到下,从左到右排序
/// </summary>
/// <param name="pGeoDataset">图层的矢量地理数据集 </param>
/// <param name="plst">图层内所有要素的集合</param>
private void setIndex(IGeoDataset pGeoDataset ,List<IFeature> plst)
{
IPoint pExtendUlpt = pGeoDataset.Extent.LowerRight;
double dMinx = pExtendUlpt.X;
double dMaxy = pExtendUlpt.Y;
IFeature pUlFeature = null;
int ix = -1;
foreach (IFeature pFeature in plst)
{
ix++;
//IPoint ULpt = ((pFeature.Shape)as IArea).Centroid;
IPoint ULpt = pFeature.Shape.Envelope.UpperLeft;
if ((ULpt.X < dMinx && ULpt.Y > dMaxy) || (ULpt.X > dMinx && ULpt.Y > dMaxy))
{
dMinx = ULpt.X;
dMaxy = ULpt.Y;
pUlFeature = pFeature;
}
}
if(pUlFeature!=null){
M_LstIndexF.Add(pUlFeature.OID);
plst.Remove(pUlFeature);
setIndex(pGeoDataset, plst);
}
}
======================================调用方式
List<int> M_LstIndexF = new List<int>();
setIndex((pFeatureLayer.FeatureClass as IGeoDataset),lstFeatures);