收藏 分享(赏)

GIS二次开发第5课.ppt

上传人:weiwoduzun 文档编号:5684039 上传时间:2019-03-12 格式:PPT 页数:189 大小:3.63MB
下载 相关 举报
GIS二次开发第5课.ppt_第1页
第1页 / 共189页
GIS二次开发第5课.ppt_第2页
第2页 / 共189页
GIS二次开发第5课.ppt_第3页
第3页 / 共189页
GIS二次开发第5课.ppt_第4页
第4页 / 共189页
GIS二次开发第5课.ppt_第5页
第5页 / 共189页
点击查看更多>>
资源描述

1、GIS二次开发,主讲:张云鹏,第五课 地图的组成,Map对象 图层对象 地图显示(Map Display) PageLayout对象 图形元素与框架元素 MapGrid对象 MapSurround对象,Map对象,地图对象(Map object)是显示和操作地图数据的容器。地图对象上能显示的图形有两类:地理数据和元素。 地理数据包括矢量类型的要素数据、栅格数据、Tin数据等,这些数据都保存在Geodatabase或数据文件如shapefile中。 元素分为两类:图形元素和框架元素。图形元素可以显示出来,而框架元素充当了“容器”的角色。在ArcMap中可以使用“Draw”工具在Map上直接绘制矩

2、形、圆形、文本等对象,在布局视图上也可以给地图添加指北针、图例、比例尺等图形对象,这些都是图形元素。,Map对象有双重身份,一方面是数据的管理容器,可以加载地理数据和图形元素,扮演了数据管理器的角色,另一方面它又可以让用户看到这些数据,即扮演了数据显示的角色。当加载数据到Map对象的时候,Map对象是数据的管理者;当改变视图范围、刷新地图的时候它是数据的显示者。 地图对象中的所有图层共享相同的空间参考。第一个载入的图层的空间参考被自动地设置为地图对象的空间参考 。新载入的图层,如果它们的空间参考与地图的空间参考不同,会被投影到地图的空间参考。 ArcMap中的Map是由文档对象(MxDocum

3、ent)控制的。,Map类的主要接口有: IMap IActiveView IViewManager IActiveViewEvents IGraphicsContainer IMapBookmark ITableCollection,Map对象,IMap与IActiveView接口,IMap接口是有关地图操作任务的起点,它主要用于管理Map对象中的layer对象、要素选择集、MapSurround对象、标注引擎和空间参考等对象。,public void DelayEvents ( bool delay ); 当DelayEvents 设置为TRUE 时, 不会触发IActiveViewEve

4、nts:SelectionChanged事件。这一方法典型情况下用于地图选择集改变时。当DelayEvents 设置为FALSE时,向地图选择集中每添加或移出一个要素,都会触发一次IActiveViewEvents:SelectionChanged事件; 相反, 将DelayEvents 设置为TRUE 时,当整个选择操作完成时仅触发一次该事件,以提高系统性能。,public ISelection FeatureSelection get; set; ArcMap有两种不同的选择集:要素选择集和元素选择集,并使用两个不同的对象来表达这两种不同的选择集,且都实现了ISelection 接口;此外

5、,要素选择集还实现了IEnumFeature接口,元素选择集实现了IEnumElement 接口;ISelection 接口用于剪贴板(clipboard)类型的操作, IEnum(IEnumFeature和IEnumElement )接口用于遍历集合中的条目(Item) 。IMap.FeatureSelection属性返回ISelection类型的对象,但可通过接口查询访问IEnumFeature接口,且通常也是这么做的。 但是,如果通过IActiveView.Selection属性获得选择集,这个选择集不是元素选择集就是要素选择集,这取决于哪个处于活动状态。使用 IMap.FeatureS

6、election属性可以确保获得对要素选择集的引用。每个要素图层都有一个ISelectionSet,但 IEnumFeature是将地图对象中所有要素图层作为一个整体来操作 ,不能通过IEnumFeature 遍历属于单个要素图层中的要素。,MapSelection IEnumFeature IEnumFeatureSetup ISelection,IActiveView接口定义了Map对象的数据显示功能。在ArcObjects中,有4个对象实现了这个接口,即PageLayout、Map、Globe和Scene。在ArcMap中,IMxDocument:ActiveView拥有当前活动视图对象

7、的一个指针。 如果处于布局视图状态,那么IMxDocument:ActiveView返回的IActiveView对象是指向PageLayout对象的; 如果处于在数据视图状态,那么这个属性就会返回一个当前使用的Map对象的指针。,IActiveView: Extent属性返回Map对象当前视图的范围,它是一个Envelope对象。FullExtent属性则可以返回视图的全图范围,因此要显示整幅地图的代码为: /将地图的当前范围设置为全图范围pActiveView.Extent = pActiveView.FullExtent;pActiveView.Refresh(); IActiveView

8、:ScreenDisplay属性指向当前视图的ScreenDisplay对象。每一个视图对象都有一个ScreenDisplay对象用于控制视图的图形绘制工作。 IActiveView:PartialRefresh方法可以让视图对象使用不同的方式来局部刷新以重绘地图。 pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null),public void PartialRefresh ( esriViewDrawPhase phase, object Data, IEnvelope envelope )

9、;,Map对象的获取 通过MapDocument获得Map对象 IMapDocument pMapDocument = new MapDocumentClass pMapDocument.Open(path,null); IMap pMap = pMapDocument.get_Map(i); 通过MxDocument获得Map对象 m_application = hook as IApplication;IDocument document = m_application.Document;IMxDocument mapDocument = document as IMxDocument;I

10、Map map = mapDocument .FocusMap;,IMapDocument,IMxDocument,通过MapControl获得Map对象 IMap pMap = axMapControl1.Map; IActiveView pActiveView= pMap as IActiveView; 或 pActiveView = axMapControl1.ActiveView; 通过PageLayoutControl获得Map对象 IActiveView pActiveView = axPageLayoutControl1.PageLayout as IActiveView; 或

11、pActiveView = axPageLayoutControl1.ActiveView; pMap = pActiveView.FocusMap;,在命令、工具类中获得Map对象 IHookHelper m_hookHelper = null; IMap m_Map; IActiveView m_ActiveView; public override void OnCreate(object hook) if (hook = null) return;m_hookHelper = new HookHelperClass();m_hookHelper.Hook = hook;m_Map =

12、m_hookHelper.FocusMap;m_ActiveView = m_hookHelper.ActiveView; ,IHookHelper,Performing map selection,When working with a map, selection can be managed at both the map level and the layer level.,private void SelectFeaturesPolygon( IMap pMap, IPolygon pPolygon) ISelectionEnvironment pSelectionEnvironme

13、nt = new SelectionEnvironmentClass(); pSelectionEnvironment.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; pMap.SelectByShape(pPolygon, pSelectionEnvironment, false); ,IEnumFeature selectedFeatures = m_map.FeatureSelection as IEnumFeature; selectedFeatures.Reset(); IFeature sele

14、ctedFeature = selectedFeatures.Next(); if (selectedFeature = null) return null; IFeatureClass featureClass = selectedFeature.Class as IFeatureClass; if (featureClass.ShapeType != esriGeometryType.esriGeometryPolyline) return null; IPolyline polyline = selectedFeature.ShapeCopy as IPolyline; txtLineL

15、ength.Text = polyline.Length.ToString(); DrawSelectedFeature(polyline);,private void ClearMapSelection( IMap pMap) pMap.ClearSelection(); ,private IEnumLayer GetLayers( IMap m_map) UID uid = new UIDClass();/uid.Value = “40A9E885-5533-11d0-98BE-00805F7CED21“;/ IFeatureLayeruid.Value = “E156D7E5-22AF-

16、11D3-9F99-00C04F6BC78E“; / IGeoFeatureLayer/uid.Value = “6CA416B1-E160-11D2-9F4E-00C04F6BC78E“; / IDataLayerif (m_map.LayerCount != 0) IEnumLayer layers = m_map.get_Layers (uid, true);return layers;return null;,public IEnumLayer get_Layers (UID uid, bool recursive ); The layers in the map of the typ

17、e specified in the uid. If recursive is true it will return layers in group layers.,IActiveViewEvents接口,IActiveViewEvents接口让Map对象可以监听与活动视图(ActiveView)相关的事件并做出相应的响应,例如AfterDraw、SelectionChanged等。,public event AfterDrawEventHandler AfterDraw public delegate void AfterDrawEventHandler ( IDisplay Displa

18、y, esriViewDrawPhase phase);public event AfterItemDrawEventHandler AfterItemDraw public delegate void AfterItemDrawEventHandler ( short Index, IDisplay Display, esriDrawPhase phase);,许多组件类实现了IActiveViewEvents 接口,不同的组件类触发的事件也有所不同。如Map 对象不会触发FocusMapChanged事件,但PageLayout对象触发该事件;当从Map对象中去除一个图层时, Map对象会

19、触发ItemDeleted事件,当从PageLayout对象中删除元素如地图框架或图形元素时, PageLayout对象也会触发ItemDeleted事件。The AfterItemDraw event will only be fired when the IViewManager:VerboseEvents property is set to True. By default, this property is set to False.,IViewManager,One commonly used property managed by the IViewManager interfa

20、ce is VerboseEvents. When VerboseEvents is set to False, the default, IActiveViewEvents:AfterItemDraw, is not fired. To listen for this event, you must set VerboseEvents equal to True.,将线要素一分为二,点击菜单或命令,弹出如图界面,在地图上选择线要素,其长度会自动显示在界面中. 这需要使用IActiveViewEvents中的SelectionChanged.,IActiveViewEvents_Event a

21、ctiveViewEvent = null; IActiveViewEvents_SelectionChangedEventHandler mapSelectionChanged; private void SetupEvents() activeViewEvent = m_activeView as IActiveViewEvents_Event;activeViewEvent.SelectionChanged += new IActiveViewEvents_SelectionChangedEventHandler(OnMapSelectionChanged);,public void O

22、nMapSelectionChanged() selectedFeature = GetSelectedFeature(); ,private IFeature GetSelectedFeature() IEnumFeature selectedFeatures = m_map.FeatureSelection as IEnumFeature;selectedFeatures.Reset();IFeature selectedFeature = selectedFeatures.Next();if (selectedFeature = null) return null;IFeatureCla

23、ss featureClass = selectedFeature.Class as IFeatureClass;if (featureClass.ShapeType != esriGeometryType.esriGeometryPolyline) return null;IPolyline polyline = selectedFeature.ShapeCopy as IPolyline;txtLineLength.Text = polyline.Length.ToString();DrawSelectedFeature(polyline);return selectedFeature;

24、,IGraphicsContainer接口,IGraphicsContainer 用于管理Map中的元素对象。,AddElement方法用于将一个元素放入Map对象中, 下面是一个添加元素的例子: IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer ;/定义一个line类型的Element ILineElement pLineEle = new LineElementClass(); /设置这个Element的符号对象 pLineEle.Symbol = pSymbol; IElement pEle = pLin

25、eEle as IElement; /设置元素的几何形体对象属性 pEle.Geometry = pGeo; /将元素添加到Map对象中 pGraphicsContainer.AddElement(pEle, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null, null);,public void AddElement (IElement Element, int zorder ); The parameter zorder is currently not utilized by all of the

26、 IGraphicsContainer implementations and is typically set to 0 when calling this method.,IGraphicsContainer:DeleteElement方法用于删除Map对象中的一个给定的元素。 UpdateElement用于更新图形元素。IGraphicsContainer:LocateElements方法是使用一个点来选择元素,它需要传入一个点对象和一个容差值,Map对象会将所有处于点容差周围的元素选择到。LocateElementsByEnvelope方法,它和SelectByShape方法类同,是使

27、用鼠标拖曳一个矩形区域,从而选择到这个区域内所有的元素。,IMapBookmarks接口,IMapBookmarks用于管理Map中的空间书签对象。 public void AddBookmark (ISpatialBookmark bookmark); public IEnumSpatialBookmark Bookmarks get; public void RemoveAllBookmarks (); public void RemoveBookmark (ISpatialBookmark bookmark);,ISpatialBookmark,Classes that implemen

28、t ISpatialBookmark: AOIBookmark: Used to create an Area of Interest bookmark FeatureBookmark: Used to save the areas of interest by selecting features in the map.,ITableCollection接口,ArcMap除了可以添加地理数据外还能够添加纯属性表,加入属性表是为了和要素类等对象进行关联和连接。 AddTable方法可以将一个table对象添加进Map对象;Table属性可以依据表的标识号获得特定的属性表,如:,ITableCo

29、llection pTableCol = pMap as ITableCollection; ITable pTable = pTableCol.get_Table(0);RemoveAllTables方法可以让pTableCol对象删除地图中的所有属性表,RemoveTable可以依据表的标识号删除某个属性表,TableCount则可以返回地图对象中所有的属性表的数目。,图层对象,Map对象可以装载地理数据,这些数据是以图层的形式组织到地图对象的。 Layer对象本身没有包含数据,而仅仅是获得了数据的引用而已,是用于管理数据源的链接;此外图层中还保存着符号化信息(注记要素类除外)。在ArcO

30、bjects中,地理数据始终是保存在GeoDatabase或者地理文件中的。 ArcGIS中也可以在一个要素类上新建一个图层文件,即lyr文件,这个文件也是仅仅获取了地理数据的存储位置而已,而没有拥有数据。,ILayer接口,ILayer是所有图层类都实现了的一般接口,它定义了所有图层的公共方法和属性。 public void Draw ( esriDrawPhase DrawPhase, IDisplay Display, ITrackCancel TrackCancel ); public bool ScaleRangeReadOnly get; Some layer types do n

31、ot support a writeable MinimumScale or MaximumScale. Use this property to determine whether or not a layer supports this. Note: the ILayer interface has been superseded by ILayer2.,ILayer2,要素图层FeatureLayer,要素数据是GIS中最常使用的数据类型之一,它可以用于表示离散矢量对象的信息。 IFeatureLayer2 IGeoFeaturelayer IGeoDataset IFeatureSel

32、ection IFeatureLayerDefinition ILayerFields IIdentify,IFeatureLayer2接口,IFeatureLayer2接口用于管理要素图层的数据源,即要素类(Featureclass)。IFeatureLayer2:DataSourceType属性返回要素图层的数据源的类型.,(New),(New),IFeatureLayer2.DisplayField Property public string DisplayField get; set; Usually this field name contains the string “name

33、“, or is the first string field found in the layers attributes. This field is used to show map tips for the layer.,IFeatureCursor featureCursor=pFeatureLayer.Search(queryFilter, false); IFeature feature = featureCursor.NextFeature();,public IFeatureCursor Search ( IQueryFilter queryFilter, bool recy

34、cling ); Recycling specifies whether the resulting feature cursor will be recycling or non-recycling. Use True for recycling cursor and False for a non-recycling cursor.,IGeoFeaturelayer接口,IGeoFeaturelayer接口继承了ILayer和IFeatureLayer两个接口,用于控制要素图层中与地理相关的内容,例如要素的着色和标注等功能。 public IFeatureCursor SearchDisp

35、layFeatures (IQueryFilter queryFilter, bool recycling); Renderer属性用于设置图层的着色对象; DisplayAnnotation属性可以设置要素图层是否出现标注,当它为true的时候,用户可以在这个要素图层上依据要素类的某个字段进行标注。,private void Renderer() IGeoFeatureLayer pGeoFeatureL = (IGeoFeatureLayer)layer2Symbolize; IFeatureClass featureClass = pGeoFeatureL.FeatureClass; /

36、找出rendererField在字段中的编号 int lfieldNumber = featureClass.FindField(strRendererField); IClassBreaksRenderer m_classBreaksRenderer = CreateClassBreaksRenderer(featureClass, strClassifyMethod); if (m_classBreaksRenderer = null) return; pGeoFeatureL.Renderer = (IFeatureRenderer) m_classBreaksRenderer; m_a

37、ctiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent); ,IGeoDataset接口,IGeoDataset接口仅有两个属性,用于管理地理要素集的范围和空间参考。 Extent可以返回当前数据集的范围,是一个IEnvelope类型的对象; SpatialReference属性则可以让用户获得这个数据集的空间参考。 所有的图层和数据集实现了该接口。,IGeoDataset2,IFeatureSelection接口,IFeatureSelection接口负责管理一个图层中的要

38、素的选择集的方法和属性。 IFeatureSelection接口的Add方法可以把本图层上的一个要素添加到图层的选择集中;SelectFeatures方法则可以使用一个过滤器把符合要求的要素放入图层的选择集中;Clear方法用于清除图层要素选择集。,IFeatureLayerSelectionEvents FeatureLayerSelectionChanged Occurs when the selection changes. ILayerEvents VisibilityChanged Occurs when layer visibility changes.,private void

39、SelectLayersFeatures (IFeatureLayer pFeatureLayer, string WhereClause) IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection; if (pFeatureSelection = null) return;IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.WhereClause = WhereClause; pFeatureSelection . Select

40、Features (pQueryFilter,esriSelectionResultEnum.esriSelectionResultNew, false); ,public void SelectFeatures (IQueryFilter Filter, esriSelectionResultEnum Method, bool justOne );,private void ClearLayerSelection (IFeatureLayer pFeatureLayer) IFeatureSelection pFeatureSelection = pFeatureLayer as IFeat

41、ureSelection; if (pFeatureSelection = null) return;pFeatureSelection.Clear(); ,在要素图层中SelectFeatures (IFeatureSelection)和Search(IFeatureLayer)要素的区别: 要素图层的Search方法返回的是ICursor对象,它仅仅是一个指向要素的指针; 使用IFeatureSelection:SelectFeatures方法,则符合要求的要素会被标记为“被选择的要素集”,这个选择集是一个ISelectionSet对象,可以用SelectionSet返回,如:IFeatu

42、reSelection pSel = pFeatureLayer as IFeatureSelection;ISelectionSet pSelectionSet = pSel.SelectionSet;,Note: the ISelectionSet interface has been superseded by ISelectionSet2. Please consider using the more recent version. ISelectionSet2,(新增),IFeatureLayerDefinition接口,IFeatureLayerDefinition接口定义了Cre

43、ateSelectionLayer方法,可以将一个图层选择集中的要素转换为一个单独的要素图层。它要求四个参数: LayerName定义了新图层的名称; 如果希望使用当前图层的要素选择集,需要设useCurrentSelection为TRUE; joinTableNames是一个可能与当前图层连接的表名称,使用这个方法同样也可以将连接表的数据放入新的图层中; DefinitionExpression可以用于设定一个选择过滤,将要素选择集中符合条件的要素放入新的图层。,public IFeatureLayer CreateSelectionLayer ( string LayerName, boo

44、l useCurrentSelection, string joinTableNames, string Expression );,Note: the IFeatureLayerDefinition interface has been superseded by IFeatureLayerDefinition2. Please consider using the more recent version.,ILayerFields接口,尽管要素图层的数据是保存在要素类中,获得要素类的字段需要从要素类着手,但是ArcObjects也提供了ILayerFields接口,可以直接获取一个要素图层

45、的要素类字段结构。,IFeatureLayer2,ILayerFields,IIdentify接口,IIdentify 接口只定义了Identify 方法: public IArray Identify (IGeometry pGeom); 许多类实现了IIdentify 接口。对于地图图层的IIdentify 接口,Identify()方法返回 FeatureIdentifyObject 类型的对象数组。 On a FeatureIdentifyObject, you can do a QI to the IIdentifyObj interface to get more informat

46、ion about the identified feature. The IIdentifyObj interface returns the window handle, layer, and name of the feature; it has methods to flash the feature in the display and to display a context menu at the Identify location.,IIdentifyObj接口,Note: the IIdentify interface has been superseded by IIden

47、tify2. Please consider using the more recent version.,此外,可以使用ILayerEffects接口来管理一个图层的透明度,对比度和亮度。,TinLayer,TIN用于表达连续的表面,地表高程或温度梯度都可以使用TIN来表示。 ITinLayer接口继承自ILayer,定义了TIN如何在图层上显示的方法和属性。 ITinLayer:Dataset显示了Tin图层的数据源 ITinLayer:DisplayField是TinLayer图层的显示字段 ITinLayer:AddRenderer方法可以加入一个着色对象,ClearRenderers

48、可以清除图层中所有的着色对象 GetRenderer可以用一个索引值获得某个着色对象。 在一幅TIN图中,有多种着色方法,ITinLayer:RendererCount则可以返回这些着色对象的数目。,Note: the ITinLayer interface has been superseded by ITinLayer2. Please consider using the more recent version.,通过地图文档访问地图和图层,Accessing maps and layers via the MxDocument static void AccessMapsAndLaye

49、rsViaMxDocument( IMxDocument pMxDocument) IMap pMap; IMaps pMaps = pMxDocument.Maps; for (int i = 0; i = pMaps.Count - 1; i+) pMap = pMaps.get_Item(i); Console.WriteLine(pMap.Name); IEnumLayer pEnumLayer = pMap.get_Layers(null, true); pEnumLayer.Reset(); ILayer pLayer = pEnumLayer.Next(); while (pLa

50、yer != null) Console.WriteLine(pLayer.Name); pLayer = pEnumLayer.Next(); ,Accessing maps and layers via the MapDocument static void OpenMXDViaMapDocument(string path) IMapDocument pMapDocument = new MapDocumentClass(); if (pMapDocument.get_IsMapDocument(path) pMapDocument.Open(path,null); IMap pMap;

51、 for (int i = 0; i = pMapDocument.MapCount - 1; i+) pMap = pMapDocument.get_Map(i); Console.WriteLine(pMap.Name); IEnumLayer pEnumLayer = pMap.get_Layers(null,true); pEnumLayer.Reset(); ILayer pLayer = pEnumLayer.Next(); while (pLayer != null) Console.WriteLine(pLayer.Name); pLayer = pEnumLayer.Next(); ,

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

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报