[转] arcgis Engine创建shp图层

简介:

小生 原文 arcgis Engine创建shp图层

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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建立新的字段:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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);
//继续增加其它字段

 最后,创建图层

1
2
3
4
5
6
7
8
9
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" );

 

没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。

    本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/5903490.html,如需转载请自行联系原作者


相关文章
|
4月前
|
定位技术
ArcGIS中ArcMap栅格图层0值设置为NoData值的简便方法
ArcGIS中ArcMap栅格图层0值设置为NoData值的简便方法
|
4月前
|
定位技术 Windows
ArcGIS中ArcMap图层属性表的中文字段乱码的解决方法
ArcGIS中ArcMap图层属性表的中文字段乱码的解决方法
104 0
|
4月前
ArcGIS中ArcMap为不含坐标系的图层添加地理坐标系或投影坐标系
ArcGIS中ArcMap为不含坐标系的图层添加地理坐标系或投影坐标系
|
4月前
|
数据库
ArcGIS中ArcMap新建矢量点线面要素图层并手动划定要素图层范围区域
ArcGIS中ArcMap新建矢量点线面要素图层并手动划定要素图层范围区域
|
4月前
ArcGIS修改图层标签标注(Label)对应字段与内容的方法
ArcGIS修改图层标签标注(Label)对应字段与内容的方法
|
4月前
|
定位技术
ArcGIS批量计算图层中矢量要素面积——ArcMap
ArcGIS批量计算图层中矢量要素面积——ArcMap
|
4月前
|
定位技术
ArcGIS矢量图层投影与地理坐标系转为投影坐标系——ArcMap
ArcGIS矢量图层投影与地理坐标系转为投影坐标系——ArcMap
|
9月前
|
存储
ArcGIS:模型构建器内变量的数据类型中栅格图层和栅格数据集的区别
ArcGIS:模型构建器内变量的数据类型中栅格图层和栅格数据集的区别
61 0
|
9月前
|
存储 C语言
ArcGIS:Excel/Txt 文件生成点图层、属性表编辑的基本方法、属性表之间的连接(合并)和关联的操作、属性表的字段计算器的使用
ArcGIS:Excel/Txt 文件生成点图层、属性表编辑的基本方法、属性表之间的连接(合并)和关联的操作、属性表的字段计算器的使用
185 0
|
9月前
|
SQL 开发框架 数据可视化
ArcGIS Engine学习系列1 AE基础介绍
市面上AE教程大致到ArcGIS10.2,ESRI宣布从ArcGIS10.5开始便停止AE的更新,使用AO做开发,初学者可以在学习C#语言后,从AE入门,逐渐过度到AO。不同版本下AE数据类型数量Enums:枚举类型,用于实现一些定义的内容Structs:结构体Interfaces:接口Classes:类AE开发中,为了更好地管理COM对象,ESRI将这些COM对象放到不同的组件库中。
203 0