AE中新建shapefile,自定义字段

代码由ESRI社区GIScafe提供

           IFields pFields  =   new  FieldsClass();
            IFieldsEdit pFieldsEdit 
=  pFields  as  IFieldsEdit;
            IField pField 
=   new  FieldClass();
            IFieldEdit pFieldEdit 
=  pField  as  IFieldEdit;
            pFieldEdit.Name_2 
=   " shape " ;
            pFieldEdit.Type_2 
=  esriFieldType.esriFieldTypeGeometry;

            
// set up Geometry Definition
            IGeometryDef pGeometryDef  =   new  GeometryDefClass();
            IGeometryDefEdit pGeometryDefEdit 
=  pGeometryDef  as  IGeometryDefEdit;
            pGeometryDefEdit.GeometryType_2 
=  esriGeometryType.esriGeometryPoint;   // Point,line,polygon et.
            pGeometryDefEdit.SpatialReference_2  =  axMapControl1.SpatialReference;

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

            
// 新建字段
            pField  =   new  FieldClass();
            pFieldEdit 
=  pField  as  IFieldEdit;
            pFieldEdit.Length_2 
=   15 ;
            pFieldEdit.Name_2 
=   " SchoolName " ;
            pFieldEdit.AliasName_2 
=   " SchoolName " ;
            pFieldEdit.Type_2 
=  esriFieldType.esriFieldTypeString;
            pFieldsEdit.AddField(pField);

            
string  mappath  =   @" E:\data " ;
            
string  layername = " school " ;
            IWorkspaceFactory pWorkspaceFactory 
=   new  ShapefileWorkspaceFactory();
            IFeatureWorkspace pFeatureWorkspace 
=  pWorkspaceFactory.OpenFromFile(mappath, 0 as  IFeatureWorkspace;
            pFeatureWorkspace.CreateFeatureClass(layername
+ " .shp " ,pFields, null , null ,esriFeatureType.esriFTSimple, " shape " , "" );
            axMapControl1.AddShapeFile(mappath,layername
+ " .shp " );

代码中路径名称可以自定义

你可能感兴趣的:(shape)