C#+AE 對圖層內的要素 按照從上到下 從左到右 排序算法實現

思路: 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);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章