小生 原文 arcgis Engine创建shp图层

以创建点图层为例。首先要得到保存文件的地址。

            SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Shape文件(*.shp)|*.shp";
saveFileDialog.Title = "新建点形shp文件";
saveFileDialog.CheckFileExists = false;
DialogResult dialogResult = saveFileDialog.ShowDialog();
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
int index;
string fileName;
string filePath;
if (dialogResult == DialogResult.OK)
{
fileFullPath = saveFileDialog.FileName;
index = fileFullPath.LastIndexOf("\");
fileName = fileFullPath.Substring(index + 1);
filePath = fileFullPath.Substring(0, index);
if (System.IO.File.Exists(saveFileDialog.FileName))//检查文件是否存在
{
if (MessageBox.Show("该文件夹下已经有同名文件,替换原文件?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
IFeatureWorkspace FWS = pWorkspaceFactory.OpenFromFile(filePath, 0) as IFeatureWorkspace;
IFeatureClass pFeatureClass = FWS.OpenFeatureClass(fileName);
IDataset pDataset = pFeatureClass as IDataset;
pDataset.Delete();
}
//System.IO.File.Delete(saveFileDialog.FileName);
else
return;
} }
else
{
fileFullPath = null;
return;
}

然后,要为该SHP建立新的字段:

            IFields pFields = new FieldsClass();
IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
IField pField = new FieldClass();
IFieldEdit pFieldEdit = pField as IFieldEdit; pFieldEdit.Name_2 = "Shape";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; IGeometryDef pGeometryDef = new GeometryDef();
IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;//点、线、面什么的
pGeometryDefEdit.SpatialReference_2 = axMapControl1.SpatialReference; ISpatialReferenceFactory2 ipSpaRefFa = new SpatialReferenceEnvironmentClass();
IGeographicCoordinateSystem ipGeoCorSys = new GeographicCoordinateSystemClass(); ipGeoCorSys = ipSpaRefFa.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
ISpatialReference ipSpaRef = ipGeoCorSys;
//IControlPrecision2 contrPrecision = ipSpaRef as IControlPrecision2; pGeometryDefEdit.SpatialReference_2 = ipSpaRef; pFieldEdit.GeometryDef_2 = pGeometryDef; pFieldsEdit.AddField(pField); pField = new FieldClass();//新建字段
pFieldEdit = pField as IFieldEdit;
pFieldEdit.Length_2 = 100;
pFieldEdit.Name_2 = "editorName";
pFieldEdit.AliasName_2 = "editorName";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; pFieldsEdit.AddField(pField);
//继续增加其它字段

 最后,创建图层

            IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(filePath, 0) as IFeatureWorkspace;

            int i = fileName.IndexOf(".shp");
if(i == -1 )
pFeatureWorkspace.CreateFeatureClass(fileName + ".shp", pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
else
pFeatureWorkspace.CreateFeatureClass(fileName, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", ""); axMapControl1.AddShapeFile(filePath, fileName + ".shp");

[转] arcgis Engine创建shp图层的更多相关文章

  1. ArcGIS Engine 创建索引(属性索引)——提高查询效率

    转自原文 ArcGIS Engine 创建索引(属性索引)——提高查询效率 众所周知,建立索引可以提高查询的效率,当对FeatureClass中的某一列频繁的查找,且数据量比较大时,建立索引是非常有必 ...

  2. arcEngine开发之根据点坐标创建Shp图层

    思路 根据点坐标创建Shapefile文件大致思路是这样的: (1)创建表的工作空间,通过 IField.IFieldsEdit.IField 等接口创建属性字段,添加到要素集中. (2)根据获取点的 ...

  3. Arcgis engine 指定图层对要素进行创建、删除等操作

    Arcgis engine 指定图层创建点要素 在指定的图层上创建一个点要素,点要素的位置是通过X,Y坐标指定的,下面是具体的注释 .其中 和IFeatureClassWrite接口有关的代码不要好像 ...

  4. 《ArcGIS Engine+C#实例开发教程》第七讲 图层符号选择器的实现2

    原文:<ArcGIS Engine+C#实例开发教程>第七讲 图层符号选择器的实现2 摘要:在第七讲 图层符号选择器的实现的第一阶段中,我们完成了符号选择器窗体的创建与调用.在第二阶段中, ...

  5. ArcGIS Engine环境下创建自定义的ArcToolbox Geoprocessing工具

    在上一篇日志中介绍了自己通过几何的方法合并断开的线要素的ArcGIS插件式的应用程序.但是后来考虑到插件式的程序的配置和使用比较繁琐,也没有比较好的错误处理机制,于是我就把之前的程序封装成一个类似于A ...

  6. shp图层创建

    IField,IFieldEdit,IFields,IFieldsEdit,IGeometryDef,IGeometryDefEdit接口  (2013-05-06 20:40:27) 转载▼ 标签: ...

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

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

  8. arcgis api for js入门开发系列十叠加SHP图层

    上一篇实现了demo的热力图,本篇新增叠加SHP图层,截图如下: 叠加SHP图层效果实现的思路如下:利用封装的js文件,直接读取shp图层,然后转换geojson,最后通过arcgis api来解析转 ...

  9. arcgis api 3.x for js 地图加载多个 SHP 图层压缩以及 json 文件展示(附源码下载)

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

随机推荐

  1. Strust2最基本使用

    制作一个登陆表单,然后在另一个页面显示提交的内容,简单的一个小工程. 页面: //login.jsp <form action="login.action" method=& ...

  2. mapreduce程序编写(WordCount)

    折腾了半天.终于编写成功了第一个自己的mapreduce程序,并通过打jar包的方式运行起来了. 运行环境: windows 64bit eclipse 64bit jdk6.0 64bit 一.工程 ...

  3. lintcode:合并区间

    题目: 合并区间 给出若干闭合区间,合并所有重叠的部分. 样例 给出的区间列表 => 合并后的区间列表: [ [ [1, 3], [1, 6], [2, 6], => [8, 10], [ ...

  4. net中使用母版页

    .net中使用母版页的优点 母版页提供了开发人员已通过传统方式创建的功能,这些传统方式包括重复复制现有代码.文本和控件元素:使用框架集:对通用元素使用包含文件:使用 ASP.NET 用户控件等.母版页 ...

  5. hdu 2149 Public Sale (博弈规律题)

    #include<stdio.h> int main() { int n,m; while(scanf("%d %d",&m,&n)!=EOF) { ) ...

  6. iOS 精确定时器

    Do I need a high precision timer? Don't use a high precision timer unless you really need it. They c ...

  7. MyEclipse 从数据库反向生成Hibernate实体类

    第一个大步骤 window-->open Perspective-->MyEclipse Java Persistence 进行了上面的 操作后会出现一个视图DB Brower:MyEcl ...

  8. tomcat作为windows服务启动失败解决方法

    再使用如下方法注册windows服务时,出现问题: set CATALINA_BASE=E:\tomcat\tomcat-web-server set CATALINA_HOME=E:\tomcat\ ...

  9. 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序(老罗学习笔记3)

    简单来说,硬件驱动程序一方面分布在Linux内核中,另一方面分布在用户空间的硬件抽象层中.接着,在Ubuntu上为Android系统编写Linux内核驱动程序(老罗学习笔记1)一文中举例子说明了如何在 ...

  10. 1242. Werewolf(dfs)

    1242 简单dfs 往孩子方向搜一遍 父母方向搜一遍 输入还搞什么字符串.. #include <iostream> #include<cstdio> #include< ...