ArcGIS_engine_开发相关文章摘抄.doc

上传人:PIYPING 文档编号:10834758 上传时间:2021-06-06 格式:DOC 页数:58 大小:231.50KB
返回 下载 相关 举报
ArcGIS_engine_开发相关文章摘抄.doc_第1页
第1页 / 共58页
ArcGIS_engine_开发相关文章摘抄.doc_第2页
第2页 / 共58页
ArcGIS_engine_开发相关文章摘抄.doc_第3页
第3页 / 共58页
ArcGIS_engine_开发相关文章摘抄.doc_第4页
第4页 / 共58页
ArcGIS_engine_开发相关文章摘抄.doc_第5页
第5页 / 共58页
点击查看更多>>
资源描述

《ArcGIS_engine_开发相关文章摘抄.doc》由会员分享,可在线阅读,更多相关《ArcGIS_engine_开发相关文章摘抄.doc(58页珍藏版)》请在三一文库上搜索。

1、目 录怎样用程序添加删除连接(Join)和关联(Relate)1arcengine C# 按行政区范围加载图层数据4调用ArcToolBox里的Tool的三种方法6Engine开发序列:在C#中调用GeoProcessor的方法7arengine 最简单的打开影像图方法 收藏8arcgis engine中图层与数据表之间的join操作9arcengine中几种常用数据的加载方法11使用engine查询图层的属性表14ArcEngine 统计方法15Delphi ArcEngine 根据条件添加文本注记18AE-地图刷新-PartialRefresh(转载)20ArcGIS Engine 9.2

2、 实现要素闪烁21使用ArcGIS Engine来实现地图的点击查询并闪烁(转贴)25如何将GPS上获取的经纬度坐标进行投影转化26经纬度到平面坐标的相互转换28ArcGis Engine空间插值方法31饼图渲染专题图34如何在Toolbar控件上添加Combobox等其他控件39根据外部关联表格的字段值来符号化图层42ArcEngine开发程序中关闭时内存泄漏的问题50C# winform chart 饼图 直方图52怎样用程序添加删除连接(Join)和关联(Relate)内容摘要ArcMap里面可以通过属性字段为两个图层建立或删除连接和关联,怎样使用VBA或Engine完成同样的工作呢?这

3、里主要用到IDisplayRelationshipClass.DisplayRelationshipClass方法,如下为实现的VBA代码:过程描述Private Sub AddJoin_Relation_Click() Dim pFeatLayer As IFeatureLayer Dim pDispTable As IDisplayTable Dim pFCLayer As IFeatureClass Dim pTLayer As ITable Dim pTabCollection As IStandaloneTableCollection Dim pStTable As IStandal

4、oneTable Dim pDispTable2 As IDisplayTable Dim pTTable As ITable Dim pMemRelFact As IMemoryRelationshipClassFactory Dim pRelClass As IRelationshipClass Dim pDispRC As IDisplayRelationshipClass Set pFeatLayer = GetLayer(0) MapControl1.Layer(0) Dim pDoc As IMxDocument Set pDoc = ThisDocument Dim pMap A

5、s IMap Set pMap = pDoc.ActiveView Set pTabCollection = pMap If pTabCollection.StandaloneTableCount = 0 Then Exit Sub End If Set pDispTable = pFeatLayer Set pFCLayer = pDispTable.DisplayTable Set pTLayer = pFCLayer Set pDispRC = pFeatLayer Set pStTable = pTabCollection.StandaloneTable(0) Set pDispTab

6、le2 = pStTable Set pTTable = pDispTable2.DisplayTable Set pMemRelFact = New MemoryRelationshipClassFactory Set pRelClass = pMemRelFact.Open(pStTable.Name, pTTable, id, pTLayer, 省行政中心, forward, backward, esriRelCardinality.esriRelCardinalityOneToMany) 这里参数根据具体数据和需求设置,详细信息可参照开发帮助文档 增加连接Join pDispRC.Di

7、splayRelationshipClass pRelClass, esriJoinType.esriLeftOuterJoin 增加关系 -Relate Dim pRelClassCollEdit As IRelationshipClassCollectionEdit Set pRelClassCollEdit = pFeatLayer pRelClassCollEdit.AddRelationshipClass pRelClass Set pDispRC = pFeatLayer If Not pDispRC.RelationshipClass Is Nothing Then MsgBox

8、 建立关联时: & pDispRC.RelationshipClass.OriginClass.AliasName End IfEnd SubPrivate Sub RemoveJoinRelation_Click() Dim pFeatLayer As IFeatureLayer Dim pDispRC As IDisplayRelationshipClass Dim pRelationshipClassCollectionEdit As IRelationshipClassCollectionEdit Set pFeatLayer = GetLayer(0) MapControl1.Lay

9、er(0) Set pRelationshipClassCollectionEdit = pFeatLayer Set pDispRC = pFeatLayer If Not pDispRC.RelationshipClass Is Nothing Then MsgBox 删除关联前: & pDispRC.RelationshipClass.OriginClass.AliasName End If 删除Relate Call pRelationshipClassCollectionEdit.RemoveAllRelationshipClasses 删除所有Join pDispRC.Displa

10、yRelationshipClass Nothing, esriJoinType.esriLeftOuterJoin 这里第一个参数传入Nothing即可完成删除 Set pDispRC = pFeatLayer If Not pDispRC.RelationshipClass Is Nothing Then MsgBox 删除关联后: & pDispRC.RelationshipClass.OriginClass.AliasName End IfEnd Subarcengine C# 按行政区范围加载图层数据大家可能在平时开发中可能会遇到按行政区加载图层数据的需求,比方说整个国土资源部有某一

11、类型专题数据有若干图层,每个图层数据的范围是整个中国,这时国土资源部开发一套系统可能有这个需求,每个省只能加载本省的数据。以下函数即为按按行政区范围创建行政区范围的图层。 比方说我想获取河南省的数据只需传入行政区图层中河南省图元的Geometry即可。另外如果如果遇到行政区层必须用 esriSpatialRelEnum.esriSpatialRelContains这个参数,否则行政区这个图层就不能只获取河南这个省份,它会把河南省的周围省份,河北,湖北,安徽,陕西,山东,山西等省份的图元也添加创建到新图层。 / / 按行政区范围创建行政区范围的图层 / / 源数据图层 / 行政区范围 / 图层是

12、否为行政区 / 新创建的图层 private IFeatureLayer GetSelectionLayer(IFeatureLayer pFeatureLayer, IGeometry pGeometry,bool bXZQ) try if (pFeatureLayer != null & pGeometry != null) IQueryFilter pQueryFilter; ISpatialFilter pSpatialFilter = new SpatialFilterClass(); IFeatureSelection pFeatureSelection = pFeatureLay

13、er as IFeatureSelection; pSpatialFilter.GeometryField = pFeatureLayer.FeatureClass.ShapeFieldName; pFeatureSelection.Clear(); if (!bXZQ) pSpatialFilter.Geometry = pGeometry; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pQueryFilter = pSpatialFilter; pFeatureSelection.Sele

14、ctFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false); else pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; pQueryFilter = pSpatialFilter; if(pGeometry is IGeometryCollection) for (int i = 0; i (pGeometry as IGeometryCollection).GeometryCount; i+) pSp

15、atialFilter.Geometry = (pGeometry as IGeometryCollection).get_Geometry(i); pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultAdd, false); IFeatureLayerDefinition pFLDefinition = pFeatureLayer as IFeatureLayerDefinition; IFeatureLayer pNewFeatureLayer = pFLDefi

16、nition.CreateSelectionLayer(pFeatureLayer.Name ,true, null, null); pNewFeatureLayer.MaximumScale = pFeatureLayer.MaximumScale; pNewFeatureLayer.MinimumScale = pFeatureLayer.MinimumScale; pNewFeatureLayer.Selectable = pFeatureLayer.Selectable; pNewFeatureLayer.Visible = pFeatureLayer.Visible; pNewFea

17、tureLayer.ScaleSymbols = pFeatureLayer.ScaleSymbols; return pNewFeatureLayer; else return null; catch (Exception Err) MessageBox.Show(Err.Message, 获取SelectionLayer, MessageBoxButtons.OK, MessageBoxIcon.Information); return null; 本文来自CSDN博客,转载请标明出处:http:/ IArcToolboxExtension获得工具赋给pGPToolCommandHelpe

18、r2,然后InvokeModal UID pUid = new UIDClass(); pUid.Value = esriGeoprocessingUI.ArcToolboxExtension; IArcToolboxExtension pATBExt = m_application.FindExtensionByCLSID(pUid) as IArcToolboxExtension; IGPTool pTool = pATBExt.ArcToolbox.GetToolbyNameString(ExportCAD); IGPToolCommandHelper2 pGPToolCommandHe

19、lper2 = new GPToolCommandHelperClass() as IGPToolCommandHelper2; pGPToolCommandHelper2.SetTool(pTool); Boolean pOk; IGPMessages pGPMessages; pGPToolCommandHelper2.InvokeModal(m_application.hWnd, null, out pOk, out pGPMessages);二.用IWorkspaceFactory 根据工具的文件路径找ToolBoxes,Conversion Tools,然后ExportCAD工具,然

20、后InvokeModalIWorkspaceFactory pToolboxWorkspaceFactory = new ToolboxWorkspaceFactoryClass(); IToolboxWorkspace pToolboxWorkspace = (IToolboxWorkspace)pToolboxWorkspaceFactory.OpenFromFile(D:ArcGISArcToolboxToolboxes, 0); IGPToolbox toolbox = (IGPToolbox)pToolboxWorkspace.OpenToolbox(Conversion Tools

21、); IGPTool pTool = toolbox.OpenTool(ExportCAD); IGPToolCommandHelper2 pGPToolCommandHelper2 = new GPToolCommandHelperClass() as IGPToolCommandHelper2; /pGPToolCommandHelper2.SetTool(pTool); pGPToolCommandHelper2.SetToolByName(Conversion Tools, ExportCAD); Boolean pOk; IGPMessages pGPMessages; pGPToo

22、lCommandHelper2.InvokeModal(m_application.hWnd, null, out pOk, out pGPMessages);三. 直接用SetToolByName方法IGPToolCommandHelper2 pGPToolCommandHelper2 = new GPToolCommandHelperClass() as IGPToolCommandHelper2; /pGPToolCommandHelper2.SetTool(pTool); pGPToolCommandHelper2.SetToolByName(Conversion Tools, Exp

23、ortCAD); Boolean pOk; IGPMessages pGPMessages; pGPToolCommandHelper2.InvokeModal(m_application.hWnd, null, out pOk, out pGPMessages);Engine开发序列:在C#中调用GeoProcessor的方法 为了降低开发难度和提高开发效率,ArcGIS Engine 9.2中添加了GeoProcessor类,该类的作用ESRI的帮助文档中的说明为:A geoprocessing tool is executed by a geoprocessor. The geoproc

24、essor is a helper object that simplifies the task of executing tools. Toolboxes define the set of tools available for the geoprocessor. Toolboxes can be added and removed from the geoprocessor.其意思大概就在是用GeoProcessor能帮助用户直接实现一些简单的工具性的功能,所有在ArcToolBox中的功能,基本都可以用GeoProcessor编程实现。 GeoProcessor在编程中用起来,有时候

25、有些麻烦,因为其参数都是这通过SetEnvironmentValue (string environmentName, object Value )函数来实现的,而environmentName是字符型,因此具体需要设置什么变量,以及变量的值该怎么给,很多时候需要经验以及对ArcToolBox的熟悉程度来决定了。 在使用GeoProcessor时,一般需先定义一个GeoProcessor对象,然后设置该对象的参数,再定义一个具体的操作类,如:Delete,Addjoin等,具体包含哪些操作类,可通过ArcToolBox和ESRI的帮助文档查找。在设置完操作类的参数后,则通过GeoProcess

26、or的Excute函数来执行。 下面以一个JoinTable(将两张表关联为一个表)的例子来做一个具体分析。 Geoprocessor pGp = new Geoprocessor();/定义GeoProcessor对象 /设置参数 pGp.OverwriteOutput = true; /“workspace“参数,pWS为IWorkspace对象(注意:只有当pWS通过创建*.sde文件的方式生成连接时,PathName才会有值,否则为空) pGp.SetEnvironmentValue(workspace, pWS.PathName); /创建工具 AddJoin pJoin = new

27、 AddJoin(); /设置相关参数 ILayer pInLayer = null; pJoin.in_layer_or_view = pInLayer; pJoin.in_field = strInFldName; pJoin.join_table = strJoinTblName; pJoin.join_field = strJoinFldName; /执行 pGp.Execute(pJoin, null); /将关联后的Layer返回 return pInLayer;arengine 最简单的打开影像图方法 收藏 /增加影像图,Filename含路径 by gisoracle,Emai

28、l:function openRasterFile(FileName: string): IRasterLayer;var pRasterLayer : IRasterLayer;begin if not FileExists(FileName) then ,有些影像就是一个路径 begin raise exception.Create(FileName + :文件不存在); end; pRasterLayer := CoRasterLayer.Create as IRasterLayer; pRasterLayer.CreateFromFilePath(FileName); result :

29、= pRasterLayer;end;arcgis engine中图层与数据表之间的join操作在进行join之前,请确认数据库可以连接 try /使用oledb连接数据库,连接到sys.基本信息表 IWorkspaceFactory pWorkspaceFactory = new OLEDBWorkspaceFactory(); IPropertySet pPropSet = new PropertySet(); pPropSet.SetProperty(CONNECTSTRING,Provider=sqloledb;Data Source= + this.instanceBox.Text

30、+ ;Initial Catalog=sys;User Id=sa;Password=sa;); IWorkspace pWorkspace = pWorkspaceFactory.Open(pPropSet,0); IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspace; ITable pForeignTable = pFeatureWorkspace.OpenTable(sys.基本信息表); /打开已经修复好数据源的temp.mxd IMapDocument pMapDocument = new MapDoc

31、umentClass(); pMapDocument.Open(startPath + temp.mxd,null); IMap pMap = pMapDocument.get_Map(0); /获取图层 ILayer pLayer = null; for (int i = 0; i pMap.LayerCount; i+) if (pMap.get_Layer(i).Name = 点位) pLayer = pMap.get_Layer(i); if (pLayer = null) MessageBox.Show(打开地图文件(.mxd)失败); return; /join IFeatureL

32、ayer pFLayer = (IFeatureLayer)pLayer; IFeatureClass pFClass2 = pFLayer.FeatureClass; IMemoryRelationshipClassFactory pMemRelClassFactory = new MemoryRelationshipClassFactoryClass(); IRelationshipClass pRelaClass = pMemRelClassFactory.Open(TableJoin1,pFClass2,点位编号,(IObjectClass)pForeignTable,点位编号,for

33、ward,backward,esriRelCardinality.esriRelCardinalityOneToOne); IDisplayRelationshipClass pDisplayRelationshipC = (IDisplayRelationshipClass)pFLayer; pDisplayRelationshipC.DisplayRelationshipClass(pRelaClass,esriJoinType.esriLeftOuterJoin); pMapDocument.Save(false,true); pMapDocument.Close(); catch (S

34、ystem.Exception ex4) MessageBox.Show(ex4.Message); return; arcengine中几种常用数据的加载方法一、shp文件的加载:IWorkspaceFactory pWorkspaceFactory;IFeatureWorkspace pFeatureWorkspace;IFeatureLayer pFeatureLayer;/获取当前路径和文件名OpenFileDialog dlg=new OpenFileDialog();dlg.ShowDialog();string strFullPath=dlg.FileName;if(strFul

35、lPath=) return;int Index=strFullPath.LastIndexOf();string filePath=strFullPath.Substring(0,Index);string fileName=strFullPath.Substring(Index+1);/打开工作空间并添加shp文件pWorkspaceFactory=new ShapefileWorkspaceFactoryClass();/注意此处的路径是不能带文件名的pFeatureWorkspace=(IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(f

36、ilePath,0);pFeatureLayer=new FeatureLayerClass();/注意这里的文件名是不能带路径的pFeatureLayer.FeatureClass=pFeatureWorkspace.OpenFeatureClass(fileName);pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;axMapControl1.Map.AddLayer(pFeatureLayer);axMapControl1.ActiveView.Refresh();二、个人数据库(personGeodatabase)的加

37、载:IWorkspaceFactory pWorkspaceFactory;IFeatureWorkspace pFeatureWorkspace;IFeatureLayer pFeatureLayer;IFeatureDataset pFeatureDataset;/获取当前路径和文件名OpenFileDialog dlg=new OpenFileDialog();dlg.ShowDialog();string strFullPath=dlg.FileName;if(strFullPath=) return;/打开personGeodatabase,并添加图层IWorkspaceFactory pAccessWorkspaceFactory=new AccessWorkspaceFactoryClass();/打开工作空间并遍历数据集IWorkspace pWorkspace=pAccessWorkspaceFactory.OpenFromFile(strFullPath,0);IEnumDataset pEnumDataset=pWorkspace.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny);pEnumDataset.Reset();I

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1