• ArcEngine创建ShapeFile文件


    public static void CreateShapeFile(string strShapeFolder, string strShapeName, string wkt)
    {

    //打开工作空间
    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.esriGeometryPolygon;
    pGeoDefEdit.SpatialReference_2 = new UnknownCoordinateSystemClass();

    //ISpatialReferenceFactory2 pSpaRefFactory = new SpatialReferenceEnvironmentClass();
    //pSpaRefFactory.CreateESRISpatialReferenceFromPRJFile(@"E: empSuzhou_1954_3_Degree_GK_CM_120E.prj");

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

    //添加其他的字段
    pField = new FieldClass();
    pFieldEdit = (IFieldEdit)pField;
    pFieldEdit.Name_2 = "wkt";
    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
    pFieldsEdit.AddField(pField);

    IField pField2 = new FieldClass();
    IFieldEdit pFieldEdit2 = (IFieldEdit)pField2;
    pFieldEdit2.Type_2 = esriFieldType.esriFieldTypeOID;
    pFieldsEdit.AddField(pField2);

    IField pField3 = new FieldClass();
    IFieldEdit pFieldEdit3 = (IFieldEdit)pField3;
    pFieldEdit3.Name_2 = "str1";
    pFieldEdit3.Type_2 = esriFieldType.esriFieldTypeString;
    pFieldsEdit.AddField(pField3);

    IField pField4 = new FieldClass();
    IFieldEdit pFieldEdit4 = (IFieldEdit)pField4;
    pFieldEdit4.Name_2 = "str2";
    pFieldEdit4.Type_2 = esriFieldType.esriFieldTypeString;
    pFieldsEdit.AddField(pField4);

    //创建shapefile
    pWS.CreateFeatureClass(strShapeName, pFields, null, null, esriFeatureType.esriFTSimple, strShapeFieldName, "");

    //IFeatureClass pointFC = Common.CreateFeatureClass(pointfeatureClassName, pointtype, sr, pFWS, fieldList);
    }

  • 相关阅读:
    练习2
    练习1
    如何生成添加前缀的顺序DIV
    mysql5.7 版本中 timestamp 不能为零日期 以及sql_mode合理设置
    MIME类型大全
    Intel Xeon E5-2620 v4参数
    webgl开发中添加IIS的mime类型
    jquery.validate动态更改校验规则
    mvc4
    asp.net防SQL/JS注入攻击:过滤标记
  • 原文地址:https://www.cnblogs.com/khfang/p/7685302.html
Copyright © 2020-2023  润新知