小生 原文 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. POJ 1852

    #include <iostream> using namespace std; int main() { //freopen("acm.acm","r&qu ...

  2. 各种实用的js,bootstrap插件

    1.nivoSlider  非常优秀的Banner轮播插件 2.BootstrapTable 表格插件使用技巧 = http://www.cnblogs.com/landeanfen/p/497683 ...

  3. Enum枚举 简单的使用

    在枚举中使用抽象方法 /** * 为枚举类定义一个抽象方法,<br/> * 这个抽象方法由不同的枚举值提供不同的实现 * * @author wangzhu * @date 2014-9- ...

  4. 再谈PCA

        其实之前写过PCA相关的博文,但是由于之前掌握的理论知识有限,所以理解也比较浅.这篇博文,我们以另外一种角度来理解PCA看,这里我假设大家对PCA都有一个初步的了解.首先,我们举一个二维空间中 ...

  5. kmeans理解

    最近看到Andrew Ng的一篇论文,文中用到了Kmeans和DL结合的思想,突然发现自己对ML最基本的聚类算法都不清楚,于是着重的看了下Kmeans,并在网上找了程序跑了下. kmeans是unsu ...

  6. GDB笔记

    GDB是在Linux命令行下对C/C++的程序进行调试常用的一个命令,现将平时记录在本子上的笔记整理如下: 一.断点 断点类型有breakpoints, watchpoints, catchpoint ...

  7. SSL/TLS/WTLS原理

    一 前言 首先要澄清一下名字的混淆:1 SSL(Secure Socket Layer)是netscape公司设计的主要用于web的安全传输协议.这种协议在WEB上获得了广泛的应用.2 IETF(ww ...

  8. Xamarin.Android 入门之:Listview和adapter

    一.引言 不管开发什么软件,列表的使用是必不可少的,而本章我们将学习如何使用Xamarin去实现它,以及如何使用自定义适配器.关于xamarin中listview的基础和适配器可以查看官网https: ...

  9. Hibernate逍遥游记-第12章 映射值类型集合-003映射List(<list-index>)

    1. <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hi ...

  10. python mysql 简单总结(MySQLdb模块 需另外下载)

    python 通过DB-API规范了它所支持的不同的数据库,使得不同的数据库可以使用统一的接口来访问和操作. 满足DB-API规范的的模块必须提供以下属性: 属性名 描述 apilevel DB-AP ...