新建shape文件——创建FeatureClass存储为shape文件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了新建shape文件——创建FeatureClass存储为shape文件相关的知识,希望对你有一定的参考价值。
1 /// <summary>创建点shapefile 2 /// </summary> 3 /// <param name="filePath">target point shapefile path</param> 4 /// <param name="fileName">target point shapefile name</param> 5 public static void createPointShapefile(IMap map, string filePath, string fileName) 6 { 7 //建立shape字段 8 IFields pFields = new FieldsClass(); 9 IFieldsEdit pFieldsEdit = pFields as IFieldsEdit; 10 IField pField = new FieldClass(); 11 IFieldEdit pFieldEdit = pField as IFieldEdit; 12 pFieldEdit.Name_2 = "Shape"; 13 pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; 14 15 //设置geometry definition 16 IGeometryDef pGeometryDef = new GeometryDefClass(); 17 IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit; 18 pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;//点、线、面 19 pGeometryDefEdit.SpatialReference_2 = map.SpatialReference; 20 pFieldEdit.GeometryDef_2 = pGeometryDef; 21 pFieldsEdit.AddField(pField); 22 23 //新建字段 24 pField = new FieldClass(); 25 pFieldEdit = pField as IFieldEdit; 26 pFieldEdit.Length_2 = 10; 27 pFieldEdit.Name_2 = "id"; 28 pFieldEdit.AliasName_2 = "id"; 29 pFieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger; 30 pFieldsEdit.AddField(pField); 31 //继续增加其它字段 32 33 IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory(); 34 IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(filePath, 0) as IFeatureWorkspace; 35 36 //IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactoryClass(); 37 //IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(filePath, 0) as IFeatureWorkspace; 38 39 int i = fileName.IndexOf(".shp"); 40 if (i == -1) 41 pFeatureWorkspace.CreateFeatureClass(fileName + ".shp", pFields, null, null, esriFeatureType.esriFTSimple, "Shape", ""); 42 else 43 pFeatureWorkspace.CreateFeatureClass(fileName, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", ""); 44 45 //MessageBox.Show("OK"); 46 47 }
以上是关于新建shape文件——创建FeatureClass存储为shape文件的主要内容,如果未能解决你的问题,请参考以下文章
为啥我的Android Studio里新建的drawable的XML文件里没找不到shape这个选项.