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 }
      
  • 相关阅读:
    基于 IAR 修改工程名称
    Baidu IoT Study
    msp430f5438a Information Flash Seg Write -- Chapter
    MFC 编辑框内容更新方法以及滚动条设置
    通过打开按钮打开文件和通过左键移动打开文件并计算crc
    移动文件并将文件路径显示到编辑框内
    Aritronix Virtual Device 运行
    将一个char类型的数转换成曼切斯特数
    数组中重复的数字
    平衡二叉树
  • 原文地址:https://www.cnblogs.com/xuchen/p/5845677.html
Copyright © 2011-2022 走看看