C#+Arcengine獲得點集合

chhdxzq發表於2015-02-03

 最近在研究C#+arcengine,本人屬於不寫下來記不住的型,就把最近的功能全部寫成部落格記錄下來,以備以後使用,有大神看到,路過就好


通過polyline檔案路徑獲得其點集合,程式很簡單,如下

    /// <summary>
        /// 得到點集合
        /// </summary>
        /// <param name="path"> line的路徑+名稱</param>
        /// <returns></returns>
        private List<IPoint> GetPointCollection(string path)
        {
            try
            {
                List<IPoint> pointCollList = new List<IPoint>();
                int iindx = path.LastIndexOf("\\");
                string suffixRasterName = (path.Substring(iindx + 1));//線的的名稱
                string maskPath = path.Remove(iindx);//線的路徑
                //建立工作空間
                IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
                IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(maskPath, 0);
                //得到使用者所選shp檔案中的featureClass
                IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(suffixRasterName));
                //得到feature
                IFeatureCursor featureCursor = featureClass.Search(null, false);
                IFeature feature = featureCursor.NextFeature();
                while (feature != null)
                {
                    if (featureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                    {
                        IPolyline polyline = (IPolyline)feature.Shape;
                        //得到line的點集合
                        IPointCollection PointCol = polyline as IPointCollection;
                        for (int i = 0; i < PointCol.PointCount; i++)
                        {
                            pointCollList.Add(PointCol.get_Point(i));
                        }
                    }
                    feature = featureCursor.NextFeature();
                }
                return pointCollList;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return null;
            }
        }

相關文章