[转] arcgis Engine创建shp图层
小生 原文 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图层的更多相关文章
- ArcGIS Engine 创建索引(属性索引)——提高查询效率
转自原文 ArcGIS Engine 创建索引(属性索引)——提高查询效率 众所周知,建立索引可以提高查询的效率,当对FeatureClass中的某一列频繁的查找,且数据量比较大时,建立索引是非常有必 ...
- arcEngine开发之根据点坐标创建Shp图层
思路 根据点坐标创建Shapefile文件大致思路是这样的: (1)创建表的工作空间,通过 IField.IFieldsEdit.IField 等接口创建属性字段,添加到要素集中. (2)根据获取点的 ...
- Arcgis engine 指定图层对要素进行创建、删除等操作
Arcgis engine 指定图层创建点要素 在指定的图层上创建一个点要素,点要素的位置是通过X,Y坐标指定的,下面是具体的注释 .其中 和IFeatureClassWrite接口有关的代码不要好像 ...
- 《ArcGIS Engine+C#实例开发教程》第七讲 图层符号选择器的实现2
原文:<ArcGIS Engine+C#实例开发教程>第七讲 图层符号选择器的实现2 摘要:在第七讲 图层符号选择器的实现的第一阶段中,我们完成了符号选择器窗体的创建与调用.在第二阶段中, ...
- ArcGIS Engine环境下创建自定义的ArcToolbox Geoprocessing工具
在上一篇日志中介绍了自己通过几何的方法合并断开的线要素的ArcGIS插件式的应用程序.但是后来考虑到插件式的程序的配置和使用比较繁琐,也没有比较好的错误处理机制,于是我就把之前的程序封装成一个类似于A ...
- shp图层创建
IField,IFieldEdit,IFields,IFieldsEdit,IGeometryDef,IGeometryDefEdit接口 (2013-05-06 20:40:27) 转载▼ 标签: ...
- 开一个帖子,等有时间了写写如何用shapelib创建点线面等shp图层
开一个帖子,等有时间了写写如何用shapelib创建点线面等shp图层 C#操作shapelib的实例 http://files.cnblogs.com/yuxuetaoxp/Shapelib--D ...
- arcgis api for js入门开发系列十叠加SHP图层
上一篇实现了demo的热力图,本篇新增叠加SHP图层,截图如下: 叠加SHP图层效果实现的思路如下:利用封装的js文件,直接读取shp图层,然后转换geojson,最后通过arcgis api来解析转 ...
- arcgis api 3.x for js 地图加载多个 SHP 图层压缩以及 json 文件展示(附源码下载)
前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 3.x for js:esri 官网 api,里面详细的介绍 arcgis api 3.x 各个类 ...
随机推荐
- Project Euler 99:Largest exponential 最大的幂
Largest exponential Comparing two numbers written in index form like 211 and 37 is not difficult, as ...
- SaaS系列介绍之十五: SaaS知识重用
1 建立并积累自己的开发体系 遵行业界的规定又有自己的特色是我们所追求的目标.成功的软件公司都有丰富而可复用的代码组件,几行代码在单个系统里可能无足轻重,但一旦可在大量的系统中可重复使用那就是价值不菲 ...
- 转载CSDN (MVC WebAPI 三层分布式框架开发)
前言:SOA(面向服务的架构)是目前企业应用开发过程中普遍采用的技术,基于MVC WebAPI三层分布式框架开发,以此适用于企业信息系统的业务处理,是本文论述的重点.此外,插件技术的应用,富客户端JQ ...
- HTML5 编辑 API 之 Range 对象(二)
1.Range.cloneContents()The Range.cloneContents() returns a DocumentFragment copying the objects of t ...
- javascript中===与==
== equality 等同,=== identity 恒等. ==, 两边值类型不同的时候,要先进行类型转换,再比较. ===,不做类型转换,类型不同的一定不等. 类型转换规则:Boolean> ...
- c创建win窗口
windows程序设计示例: #include "windows.h" #pragma comment(lib, "winmm") LRESULT CALLBA ...
- View的个得区域函数getHitRect,getDrawingRect,getLocalVisibleRect,getGlobalVisibleRect(*)
注意: OnCreate()函数中 调用下面函数,结果全为0,要等UI控件都加载完了才能得到绘制时的值. getHitRect 以父控件的左上为原点,计算当前view在父控件的区域,不管父控件在屏幕的 ...
- Android开发之SmsManager和SmsMessage
Android的手机功能(通话与短信)都放在android.telephony包中,到了4.4时(也就是API19)android.provider.Telephony及相关类横空出世辅助电话功能以及 ...
- Android开发之定义app在手机的安装位置
定义app在手机的安装位置,可以通过在清单文件中添加属性 android:installLocation="" 该属性有三个值:auto(自动),preferExternal(外部 ...
- [Codeforces673A]Bear and Game(水题,思路)
题目链接:http://codeforces.com/contest/673/problem/A 题意:一个人看一个90分钟的节目,然后告诉你一些有趣的时刻.这个人假如在15分钟内还没有看到有趣的时刻 ...