地图集合(Maps)和图层集合(Layers)

访问Maps和Layers
遍历maps和layers
  Collections
  Enumerations
创建一个新的图层
使用图层对象的属性
  设置一个图层的数据源

上一讲中,我们了解到在ArcMap应用中,Application代表ArcMap,一个Application
有MxDocument组成,一个MxDocument由多个Map组成,一个Map由多个图层Layer组成,
图层Layer是FeatureLayer的基类。现在,我们要了解,一个FeatureLayer和0或者1
个FeatureClass相联合。Dataset为抽象基类,Table为实例化类,从Dataset派生,
FeatureClass是Table的子类。多个FeatureClass组成FeatureDataset。

访问maps
由MxDocument访问maps
得到当前的map
Dim pMxDoc as IMxDocument
Set pMxDoc=ThisDocument
dim pMap as IMap
set pMap=pMxDoc.FocusMap
得到maps(IMaps)
  是Map的集合
  Dim pAllMaps as IMaps
  Set pAllMaps=pMxDoc.Maps
一个地图文档可以包含有多个数据框,每个数据框都可以拥有不同的图层和表现。
FocusMap是指向当前活动的数据框。

访问Layers
有map和MxDocument访问layers
得到选定的layer(IMxDocument)
  dim pLayer as ILayer
  Set pLayer=pMxDoc.SelectLayer
得到指定的图层(IMap)
  dim pLayer as ILayer
  Set pMap=pMxDoc.FocusMap
  set pLayer=pMap.Layer(3)
得到所有图层(IMap)
  一个图层的enumeration
  dim pAllLayers as IEnumLayer
  set pAllLayers=pMap.Layers

遍历Maps集合
集合是按照顺序的.
  通过下标的到引用.第一项的下标为0.
  dim intIndex as Integer
  dim pMaps as IMaps
  set pMaps=pMxDoc.maps

  for intIndex=0 to pMaps.Count-1
    MsgBox pMaps.item(intIndex).Name
  next
 
遍历一个Map对象中的图层对象
IMaps图层集属性返回IEnumLayers,其只有Next和Reset两个方法.
好像是具有较少属性和方法的集合.Next返回ILayer,Reset当前指针指向top,即第一项的前边。
dim pLayer as ILayer
dim pLayers as IEnumLayers
set pLayers=pMap.layers

set pLayer=pLayers.Next;
set pLayer=pLayers.Next;

添加一个新图层到Map中
Layer是一个抽象类:不能创建
可创建的子类:TinLayer,FeatureLayer,RasterLayer等。
dim pFLayer as ILayer
set pFLayer=new FeatureLayer
dim pMxDoc as IMxDocument
dim pMap as IMap
set pMxDoc=thisdocument
set pMap=pMxDoc.focusmap
pMap.AddLayer pFLayer
因为还没有设置数据源,所以图标为失去数据连接的状态


使用图层对象
ILayer接口的属性:Name Visible ShowTips MaximumScale MinimumScale等
IGeoDataSet接口属性:Extent SpatialReference

Dim pLayer as ILayer
set pLayer=pMxDoc.SelectedLayer

pLayer.Name="Streets"
pLayer.Visible=true
pLayer.ShowTips=false


设置FeatureLayer的数据源
FeatureClass属性(IFeatureLayer)
  指定显示的数据源
  以传引用的方式(必须用set关键字)
  Dim pFLayer as IFeatureLayer
  set pFLayer=new FeatureLayer
  dim pFClass as IFeatureClass
  set pFClass=pSomeObjLayer.FeatureClass
  set pFLayer.FeatureClass=pFClass

转载于:https://www.cnblogs.com/mygis_3/archive/2009/04/29/1446572.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值