zoukankan      html  css  js  c++  java
  • AE 创建shp图层

    C#+AE中创建点状Shp文件

    今天将点写入一个新的SHP文件中,自己先做了一个简单试验,一切正常。代码如下

    private void CreateShpFromPoint()
            {
                ISpatialReference pSpatialReference = this.axMapData.ActiveView.FocusMap.SpatialReference;

                string strShapeFolder="C:/";
                string strShapeFile = "test.shp";

                string shapeFileFullName = strShapeFolder + strShapeFile;
                IWorkspaceFactory pWorkspaceFactory= new ShapefileWorkspaceFactory();
                IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace) pWorkspaceFactory.OpenFromFile(strShapeFolder, 0);
                IFeatureClass pFeatureClass;
                if (File.Exists(shapeFileFullName))
                {
                    pFeatureClass = pFeatureWorkspace.OpenFeatureClass(strShapeFile);
                    IDataset pDataset = (IDataset)pFeatureClass;
                    pDataset.Delete();
                }

                IFields pFields = new FieldsClass();
                IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;
                
                IField pField = new FieldClass();
                IFieldEdit pFieldEdit = (IFieldEdit)pField;

                pFieldEdit.Name_2 = "SHAPE";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

                IGeometryDefEdit pGeoDef = new GeometryDefClass();
                IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;
                pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                pGeoDefEdit.SpatialReference_2 = pSpatialReference; //new UnknownCoordinateSystemClass();
                pFieldEdit.GeometryDef_2 = pGeoDef;
                pFieldsEdit.AddField(pField);

                pField = new FieldClass();
                pFieldEdit = (IFieldEdit)pField;
                pFieldEdit.Name_2 = "ID";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                pFieldsEdit.AddField(pField);
                
                pField = new FieldClass();
                pFieldEdit = (IFieldEdit)pField;
                pFieldEdit.Name_2 = "Pixels";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
                pFieldsEdit.AddField(pField);

                pFeatureClass = pFeatureWorkspace.CreateFeatureClass(strShapeFile, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                IPoint pPoint = new PointClass();
                pPoint.X = 113.0;
                pPoint.Y = 23.0;
                IFeature pFeature = pFeatureClass.CreateFeature();
                pFeature.Shape = pPoint;
                pFeature.set_Value(pFeature.Fields.FindField("ID"), "D-1");
                pFeature.set_Value(pFeature.Fields.FindField("Pixels"), 1);
                pFeature.Store();

                IFeatureLayer pFeaturelayer = new FeatureLayerClass();
                pFeaturelayer.FeatureClass = pFeatureClass;
                pFeaturelayer.Name = "layer";

                this.axMapData.AddLayer(pFeaturelayer);

            }


    作者:jinqier
    出处:http://www.cnblogs.com/jinqier/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    洛谷P1057传球游戏(逆向递推递归+记忆化)
    洛谷P1433吃奶酪(正向暴力递归,回溯更新)
    洛谷P1434滑雪(逆向图的遍历搜索递归+记忆化,最长路问题)
    洛谷P1192台阶问题(逆向递推递归dfs+记忆化)
    洛谷p1025数的划分(正向暴力递归,数学排列与组合问题)
    洛谷P1141 01迷宫(图的遍历搜素递归dfs或bfs,连痛块回溯更新问题,记忆化或者并查集根结点)
    Git 版本更新--Windows
    plop-templates自动新建项目文件
    前端-随机生成测试数据-mockjs
    cookie、seseionStorage、localStorage的区别
  • 原文地址:https://www.cnblogs.com/jinqier/p/3104245.html
Copyright © 2011-2022 走看看