【036】◀▶ 自己写的程序源代码
2012-04-26 23:10
176 查看
●·● 目录:
A1 ………… ESRI_01.zipA2 ………… 实现:新建shapefile文件
A3 ………… 实现:只显示筛选的要素(IFeatureLayerDefinition)
A4 ………… 实现:高亮显示筛选的要素(IFeatureSelection)
A5 ………… 实现:类似 ArcMap 中 Identify 工具的效果(IIdentify、IArray、IIdentifyObj)
A6 ………… 实现:在 MapControl 上绘制几何图形
---------------------------------------------------------------------------------------------------------
[b]Visual Studio 2008 + ArcGIS Engine 9.3[/b]
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 返回目录 ╠══════════════════════════════════════════════════╣
╚════════╝
[b]①[/b] 点击下载: >->-> ESRI_01.zip <-<-< 标注:实现了基本 GIS 功能,部分截图如下!
全局:
![](http://pic002.cnblogs.com/images/2012/323776/2012042623193594.png)
鹰眼:
![](http://pic002.cnblogs.com/images/2012/323776/2012042623185349.png)
自定义工具对话框:
![](http://pic002.cnblogs.com/images/2012/323776/2012042623203416.png)
面符号:
![](http://pic002.cnblogs.com/images/2012/323776/2012042623213894.png)
线符号:
![](http://pic002.cnblogs.com/images/2012/323776/2012042623222270.png)
点符号:
![](http://pic002.cnblogs.com/images/2012/323776/2012042623224798.png)
右键菜单:
![](http://pic002.cnblogs.com/images/2012/323776/2012042623231915.png)
图层属性表:
![](http://pic002.cnblogs.com/images/2012/323776/2012042623234261.png)
---------------------------------------------------------------------------------------------------------
[b]Visual Studio 2010 + ArcGIS Engine 10.0[/b]
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 返回目录 ╠══════════════════════════════════════════════════╣
╚════════╝
[b]②[/b] 点击下载: >->-> NewPoints.zip <-<-< 标注:实现新建shapefile文件,部分截图如下!
![](http://pic002.cnblogs.com/images/2012/323776/2012060909510082.jpg)
属性截图如下:
![](http://pic002.cnblogs.com/images/2012/323776/2012060909524590.jpg)
实现步骤:
新建工作空间工厂 IWorkspaceFactory!(矢量数据)
新建要素工作空间 IFeatureWorkspace! <IWorkspaceFactory.OpenFromFile()>
若指定的文件名存在了,则将其内部的数据删除! <IDataset.Delete()>
为要素集新建字段 IFields!
新建要素集 IFeatureClass! <IFeatureWorkspace.CreateFeatureClass()>
新建要素 IFeature! <IFeatureClass.CreateFeature()>
代码如下:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using ESRI.ArcGIS.Carto; using System.IO; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.DataSourcesFile; using ESRI.ArcGIS.Geometry; namespace NewPoints { public partial class Form1 : Form { public Form1() { InitializeComponent(); } /// <summary> /// 保存文件的完整路径 /// </summary> string saveFullPath = string.Empty; private void button1_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.InitialDirectory = Directory.GetCurrentDirectory(); sfd.Filter = "Shp文件(*.shp)|*.shp"; if (sfd.ShowDialog() == DialogResult.OK) { saveFullPath = sfd.FileName; } textBox1.Text = saveFullPath; } private void button2_Click(object sender, EventArgs e) { IFeatureLayer pFeatureLayer = CreateShpFromPoint(saveFullPath); pFeatureLayer.Name = "Point"; axMapControl1.Map.AddLayer(pFeatureLayer); } private IFeatureLayer CreateShpFromPoint(string outfileNamePath) { string folder = System.IO.Path.GetDirectoryName(outfileNamePath); string file = System.IO.Path.GetFileName(outfileNamePath); IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace pFWS = pWSF.OpenFromFile(folder, 0) as IFeatureWorkspace; if (File.Exists(outfileNamePath)) { IFeatureClass featureClass = pFWS.OpenFeatureClass(file); IDataset pDataset = featureClass as IDataset; pDataset.Delete(); } 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 GeometryDefClass(); IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit; pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint; pFieldEdit.GeometryDef_2 = pGeometryDef; pFieldsEdit.AddField(pField); pField = new FieldClass(); pFieldEdit = pField as IFieldEdit; pFieldEdit.Name_2 = "X"; pFieldEdit.Length_2 = 20; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; pFieldsEdit.AddField(pField); pField = new FieldClass(); pFieldEdit = pField as IFieldEdit; pFieldEdit.Name_2 = "Y"; pFieldEdit.Length_2 = 20; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; pFieldsEdit.AddField(pField); IFeatureClass pFeatureClass = pFWS.CreateFeatureClass(file, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", ""); for (int i = 0; i < 100;i+=10 ) { for (int j = 0; j < 100;j+=10 ) { IPoint pPoint = new PointClass(); pPoint.PutCoords(i, j); IFeature pFeature = pFeatureClass.CreateFeature(); pFeature.Shape = pPoint as IPoint; pFeature.set_Value(pFeature.Fields.FindField("X"), i.ToString()); pFeature.set_Value(pFeature.Fields.FindField("Y"), j.ToString()); pFeature.Store(); } } IFeatureLayer pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = pFeatureClass; return pFeatureLayer; } } }
相关文章推荐
- 程序将自己的源代码写入记事本
- 程序将自己的源代码输出到控制台
- 一个难题: 怎样写一个输出自己源代码的程序?
- google地图密钥申请与将google地图集成到自己的程序中(附源代码)
- 自己用C#写的一个俄罗斯方块的小程序(附源代码)。
- c#Winform程序的toolStripButton自己定义背景应用演示样例源代码
- 打印自己源代码的程序
- 一个难题: 怎样写一个输出自己源代码的程序?
- 怎样写一个输出自己源代码的程序
- 自己写的明文加密程序的源代码(支持32M的文本文件)
- 3.第三单元任务二实训:使用作业提交系统提交Java作业时 ,需要输入Java源代码文件名和自己的邮箱,提交前对Java文件名以及邮箱进行有效检查。编写程序实现对输入的Java源文件名以及邮箱有效性的
- java 自己写的五子棋程序 源代码和大家分享
- 自己写的用JS脚本定时执行Web地址并且得到它的源代码的页面程序
- google地图密钥申请与将google地图集成到自己的程序中(附源代码)
- 输出自己源代码的C#程序
- 自己动手编写启动JAVA程序的EXE文件
- Java 棋类游戏源代码程序
- 将自己的python程序打包成.exe/.app(秀同学一脸呐)
- 晚自习好难集中注意力 自己又默默在纸上写了两个程序