arcengine要素转点文件

Posted clgis

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了arcengine要素转点文件相关的知识,希望对你有一定的参考价值。

有一个将标注文件(Annotation)以重心转换为点文件的任务,方法一:要素转点

public void FeatureToPointCollection(IMap pMap)
        {
            IFeatureLayer pFeatureLayer = pMap.get_Layer(0) as IFeatureLayer;
            IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
            IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
            IFeature pFeature = pFeatureCursor.NextFeature();
            IPointCollection pPointCollection = new MultipointClass();
            object o = Type.Missing;
            while (pFeature != null)
            {
                IGeometry pGeometry = pFeature.Shape;
                IArea pArea = pGeometry as IArea;
                IPoint pPoint = pArea.Centroid;
                pPointCollection.AddPoint(pPoint, ref o, ref o);
                pFeature = pFeatureCursor.NextFeature();
            }
            IGeoDataset pGeoDataset = pFeatureLayer as IGeoDataset;
            ISpatialReferenceFactory pSRFactory = new SpatialReferenceEnvironmentClass();
            ISpatialReference pSpatialReference = pGeoDataset.SpatialReference;
            PointCollToShpFile(pPointCollection, "C:/Users/Administrator/Desktop/testfolder/test.shp", pSpatialReference);
        }
public IFeatureLayer PointCollToShpFile(IPointCollection pPointCollection, string filePath, ISpatialReference pReference)
        {
            //利用IWorkspaceFactory打开工作空间
            int index = filePath.LastIndexOf(/);
            string folder = filePath.Substring(0, index);
            string shapeName = filePath.Substring(index + 1);
            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pFWS = (IFeatureWorkspace)pWSF.OpenFromFile(folder, 0);

            //创建字段编辑所需要的接口
            IFields pFields = new FieldsClass();
            IFieldsEdit pFieldsEdit;
            pFieldsEdit = (IFieldsEdit)pFields;

            //给字段属性、类型赋值
            IField pField = new FieldClass();
            IFieldEdit pFieldEdit = (IFieldEdit)pField;
            pFieldEdit.Name_2 = "Shape";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            IGeometryDef pGeometryDef = new GeometryDefClass();
            IGeometryDefEdit pGDefEdit = (IGeometryDefEdit)pGeometryDef;
            pGDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            //设置坐标系
            pGDefEdit.SpatialReference_2 = pReference;

            pFieldEdit.GeometryDef_2 = pGeometryDef;
            pFieldsEdit.AddField(pField);

            IFeatureClass pFeatureClass;
            pFeatureClass = pFWS.CreateFeatureClass(shapeName, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

            IPoint pPoint = new PointClass();
            for (int j = 0; j < pPointCollection.PointCount; j++)
            {
                pPoint = pPointCollection.get_Point(j);
                IFeature pFeature = pFeatureClass.CreateFeature();
                pFeature.Shape = pPoint;
                pFeature.Store();
            }
        }

还有一种思路应该比这个简单,正在~~~~~,记录一下

以上是关于arcengine要素转点文件的主要内容,如果未能解决你的问题,请参考以下文章

arcEngine开发之根据点坐标创建Shp图层

求ArcEngine 选择属性表内字段,然后在地图高亮显示选择要素的C#代码

怎样在arcengine中创建一个要素数据集。建立一个要素数据集,数据集下面建四个要素,分别是线要素和面要素

arcengine featureclass里怎么添加feature

ArcEngine 添加多个要素为啥不能同时显示

用C#代码写,ArcEngine开发,在加载的地图上绘制多边形后,导出绘制区域内的所有矢量要素(点线面)