zoukankan      html  css  js  c++  java
  • 新建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 }
      
  • 相关阅读:
    JS 和 CSS 的位置对其他资源加载顺序的影响
    How browsers workBehind the scenes of modern web browsers
    Gruntjs入门 (2)
    Superhero.js – 构建大型 JavaScript 应用程序的最佳资源
    利用位反操作来简化 indexOf 判断
    Gruntjs入门 (1)
    js和css的顺序关系
    (翻译)理解JavaScript函数调用和"this"(by Yehuda Katz)
    秒,微秒,毫秒
    您试图从目录中执行 CGI、ISAPI 或其他可执行程序,但该目录不允许执行程序
  • 原文地址:https://www.cnblogs.com/xuchen/p/5845677.html
Copyright © 2011-2022 走看看