思路

根据点坐标创建Shapefile文件大致思路是这样的:

(1)创建表的工作空间,通过 IField、IFieldsEdit、IField 等接口创建属性字段,添加到要素集中。

(2)根据获取点的坐标信息为属性字段赋值,进而得到图层的要素集

必要元素

将创建 Shapefile 文件代码封装成方法如下,这里说明一下创建一 个 Shapefile 文件至少需要配置的元素:

(1)首先,当我们创建一个shp文件时,ArcMap会自动生成如下字段:



其中shp表示几何字段,我们需要设置 IFile.NameIField.Type 来定义这个字段

(2)其次,如果我们没有设置空间坐标时,会弹出如下对话框:



因此第二步我们需要设置shp文件的空间坐标。 这里是通过设置 IField.GeometryDef 实现的。这个属性其实是IGeometryDef接口,通过对这个接口的 GeometryTypeSpatialReference 属性进行设置即可完成对空间坐标的定义。

代码说明

封装的这段代码里,发现对于 IFeatureIFeatureClass 还是不怎么理解,通过查阅资料发现, IFeature 继承自 IRowIObject ,由于IFeature 可以通过 IFeatureClass 创建而成,因此可以知道的是IFeatureClass 是和ITable处于同一个级别,IFeature 相当于是属性表中的一行。

代码

private IFeatureLayer CreateShpFromPoints(List<CPoint> cPointList,string filePath)
{
//其中,CPoint为存储点数据的结构体,包含name,x,y属性
//利用IWorkspaceFactory打开工作空间
int index = filePath.LastIndexOf('\\');
string folder = filePath.Substring(0, index);
string shapeName = filePath.Substring(index + 1);
IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
IFeatureWorkspace pFWS = (IFeatureWorkspace)pWSF.OpenFromFile(folder, 0); //创建字段编辑所需要的接口
IFields pFields = new FieldsClass();
IFieldsEdit pFieldsEdit;
pFieldsEdit = (IFieldsEdit)pFields; //给字段属性、类型赋值
IField pField = new FieldClass();
IFieldEdit pFieldEdit = (IFieldEdit)pField;
pFieldEdit.Name_2 = "Shape";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
IGeometryDef pGeometryDef = new GeometryDefClass();
IGeometryDefEdit pGDefEdit = (IGeometryDefEdit)pGeometryDef;
pGDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
//定义坐标系
ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass();
ISpatialReference pSpatialReference = pSRF.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
pGDefEdit.SpatialReference_2 = pSpatialReference; pFieldEdit.GeometryDef_2 = pGeometryDef;
pFieldsEdit.AddField(pField); IFeatureClass pFeatureClass;
pFeatureClass = pFWS.CreateFeatureClass(shapeName, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", ""); IPoint pPoint = new PointClass();
for (int j = 0; j < cPointList.Count; j++)
{
pPoint.X = cPointList[j].X;
pPoint.Y = cPointList[j].Y; IFeature pFeature = pFeatureClass.CreateFeature();
pFeature.Shape = pPoint;
pFeature.Store();
} IFeatureLayer pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.Name = shapeName;
pFeatureLayer.FeatureClass = pFeatureClass;
return pFeatureLayer;
}

arcEngine开发之根据点坐标创建Shp图层的更多相关文章

  1. [转] arcgis Engine创建shp图层

    小生 原文 arcgis Engine创建shp图层 以创建点图层为例.首先要得到保存文件的地址. SaveFileDialog saveFileDialog = new SaveFileDialog ...

  2. arcgis api 3.x for js 入门开发系列批量叠加 zip 压缩 SHP 图层优化篇(附源码下载)

    前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 3.x for js:esri 官网 api,里面详细的介绍 arcgis api 3.x 各个类 ...

  3. arcengine 开发经典帖

    http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=25575&page=1&extra= 使用ArcGIS Engine 开发自定义 ...

  4. ArcEngine开发遇到的问题(转)

    ArcEngine开发遇到的问题 https://blog.csdn.net/u013751758/article/category/6971559 转载 2018年02月11日 17:28:11 1 ...

  5. arcengine 开发经典帖 【强烈推荐仔细研读】

    转自原文 arcengine 开发经典帖 使用ArcGIS Engine 开发自定义GIS应用: 第一部分:使用ArcGIS Engine 发布自定义GIS应用软件-全面了解ArcGIS Engine ...

  6. iOS开发UI篇—九宫格坐标计算

    iOS开发UI篇—九宫格坐标计算 一.要求 完成下面的布局 二.分析 寻找左边的规律,每一个uiview的x坐标和y坐标. 三.实现思路 (1)明确每一块用得是什么view (2)明确每个view之间 ...

  7. iOS开发UI篇—使用storyboard创建导航控制器以及控制器的生命周期

    iOS开发UI篇—使用storyboard创建导航控制器以及控制器的生命周期 一.基本过程 新建一个项目,系统默认的主控制器继承自UIViewController,把主控制器两个文件删掉. 在stor ...

  8. iOS开发UI篇—控制器的创建

    iOS开发UI篇—控制器的创建 说明:控制器有三种创建方式,下面一一进行说明. 一.第一种创建方式(使用代码直接创建) 1.创建一个空的IOS项目. 2.为项目添加一个控制器类. 3.直接在代理方法中 ...

  9. 开一个帖子,等有时间了写写如何用shapelib创建点线面等shp图层

    开一个帖子,等有时间了写写如何用shapelib创建点线面等shp图层  C#操作shapelib的实例 http://files.cnblogs.com/yuxuetaoxp/Shapelib--D ...

随机推荐

  1. [leetcode]经典算法题- String to Integer (atoi)

    题目描述: 把字符串转化为整数值 原文描述: Implement atoi to convert a string to an integer. Hint: Carefully consider al ...

  2. 【算法导论】最小生成树之Prime法

    关于最小生成树的概念,在前一篇文章中已经讲到,就不在赘述了.下面介绍Prime算法:         其基本思想为:从一个顶点出发,选择由该顶点出发的最小权值边,并将该边的另一个顶点包含进来,然后找出 ...

  3. [WinForm]动态显示本地目录图片与悬浮窗

    加载显示: if (File.Exists(@"D:\产品图片\" + item + ".jpg")) { //需要判断是否存在图片 Image img = I ...

  4. (二十一)即时通信的聊天气泡的实现II

    一些优化: 禁止TableView的点击: self.tableView.allowsSelection = NO; 合并相同的时间: 不需要显示的时间,只要不设置尺寸就行了. 一个if判断的技巧,为 ...

  5. (八)喜马拉雅Demo引出的细节(代理模式和图片缩放)

    喜玛拉雅是一款电台APP,界面非常美观,通过模仿这一APP学习到很多细节. 1.图片导入后有些框内不全如何补全: 寻常的办法是再准备一张图片拖入,比较好的办法是右击已经导入的图片选择Show in F ...

  6. How Many Processes Should Be Set For The Receiving Transaction Manager (RTM)

    In this Document   Goal   Solution   References APPLIES TO: Oracle Inventory Management - Version 10 ...

  7. 【一天一道LeetCode】#35. Search Insert Position

    一天一道LeetCode系列 (一)题目 Given a sorted array and a target value, return the index if the target is foun ...

  8. Invalid Subledger (XLA) Packages In Release 12.1.3

    In this Document   Goal   Solution   1.- Information about These Packages   2.- Solution   Reference ...

  9. 【LaTeX排版】LaTeX使用--入门基础<二>

    1.在命令之后留一个空格有下列方式: 源文件如下: \documentclass[a4paper,12pt]{book}%采用book类型(中篇论文一般采用这种类型),A4纸,字体为12磅,默认为10 ...

  10. Prefix tree

    Prefix tree The trie, or prefix tree, is a data structure for storing strings or other sequences in ...