首页 > 代码库 > AE创建一个空白的Shapefile

AE创建一个空白的Shapefile

1.IField和IFieldEdit区别: 

IFieldEdit是继承IField的,因为IField的属性大部分是只读的(read-only),所以IFieldEdit就在IField的基础上多了个只写的属性。这也是为什么会出现Name_2、Length_2等原因了。IFields和IFieldsEdit的区别也是如此。

2.IField和IFields区别

IFields是IField的集合,通过AddField()方法或者set_Field()方法添加Field,其中set_Field通过index可以在指定的位置添加Field;

/// <summary>/// 在指定路径下创建一个指定名字的空Shapefile/// </summary>/// <param name="strShapeFolder">指定路径</param>/// <param name="strShapeName">文件名</param>        public void CreateShapefile(string strShapeFolder,string strShapeName )        {            //打开工作空间            const string strShapeFieldName = "shape";            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();            IFeatureWorkspace pWS = (IFeatureWorkspace)pWSF.OpenFromFile(strShapeFolder,0);             //设置字段集            IFields pFields = new FieldsClass();            IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;            //设置字段            IField pField = new FieldClass();            IFieldEdit pFieldEdit = (IFieldEdit)pField;            //创建类型为几何类型的字段            pFieldEdit.Name_2 = strShapeFieldName;            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;                        //为esriFieldTypeGeometry类型的字段创建几何定义,包括类型和空间参照             IGeometryDef pGeoDef = new GeometryDefClass();     //The geometry definition for the field if IsGeometry is TRUE.            IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;            pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;            pGeoDefEdit.SpatialReference_2 = new UnknownCoordinateSystemClass();            pFieldEdit.GeometryDef_2 = pGeoDef;            pFieldsEdit.AddField(pField);            //添加其他的字段            pField = new FieldClass();            pFieldEdit = (IFieldEdit)pField;            pFieldEdit.Name_2 = "WaterLevel";            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;            pFieldEdit.Precision_2 = 7;//数值精度            pFieldEdit.Scale_2 = 3;//小数点位数            pFieldsEdit.AddField(pField);            //创建shapefile            pWS.CreateFeatureClass(strShapeName,pFields,null,null,esriFeatureType.esriFTSimple,strShapeFieldName,"");        }

 

AE创建一个空白的Shapefile