zoukankan      html  css  js  c++  java
  • AE创建一个空白的Shapefile

    http://www.97sky.com/bbs/viewthread.php?tid=2282

    代码
    /// <summary>
    /// 在指定路径下创建一个指定名字的空Shapefile
    /// </summary>
    /// <param name="strShapeFolder">指定路径</param>
    /// <param name="strShapeName">文件名</param>

    public void CreateShapefile(string strShapeFolder)
    {
    //打开工作空间
    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,"");
    }

    更详细的资料

    ms-help://ESRI.EDNv9.3/esriGeoDatabase/html/IFeatureWorkspace.CreateFeatureClass_Example.htm

    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;
    3.
    esriFieldType字段类型,除了int,string,double等常见类型外还包含了esriFieldTypeGeometry的类型

     (几何类型,即点,线,面)

    要素类型,包括简单要素类,复杂要素,注记,多维要素,Covering,Raster等
    Length只针对String字段的,Numeric字段的长度应该设置Precision_2的值,如果是Double的话,还可以用Scale_2来设置保留几位小数点。
    补充一个CreateFeatureClass()的几个参数的说明,刚在网上查阅的:
    CLSID和EXTCLSID,它们的含义非常有趣。我们知道,GeoDatabase中的每个对象都有个唯一标识符UID,系统是靠认证这个64位的随机值来区分不同对象的,同样的,要素类和要素类的扩展部分也有这么个标识,只不过在一般情况下我们无法看到这个UID值而已。如何产生这两个值呢,也很简单,使用:
    CLSID=pOCDesc.InstanceCLSID;
    EXTCLSID=pOCDesc.ClassExtensionCLSID;
    The CLSID property of a Table determines the type of row object returned by the Table;原文
    ShapeFieldName是指一个要素类的Shape字段名,一般都是"SHAPE"。----好像不能更改。更改完了还剩显示Shape,待解决
    ConfigKeyword一般不用设置,可以设置为空字符串。
    view plaincopy to clipboardprint?

    IWorkspaceFactory 

    IFields pFields = new FieldsClass();
    IFieldsEdit pFieldsEdit
    = (IFieldsEdit)pFields;

    因为new FieldsClass()本来就可以转成IFieldsEdit的

  • 相关阅读:
    401. Binary Watch
    46. Permutations
    61. Rotate List
    142. Linked List Cycle II
    86. Partition List
    234. Palindrome Linked List
    19. Remove Nth Node From End of List
    141. Linked List Cycle
    524. Longest Word in Dictionary through Deleting
    android ListView详解
  • 原文地址:https://www.cnblogs.com/hl3292/p/1846326.html
Copyright © 2011-2022 走看看