当前位置:
文档之家› GIS应用开发6-地图数据访问
GIS应用开发6-地图数据访问
IEnumLayer Top
pLayers.Reset
Set pLayer = pLayers.Next
Nothing
遍历一个Map对象中的图层对象
通过循环遍历每个图层
ILayer lyr; ToolComboBoxLayer.Items.Clear(); if (m_yerCount > 0) { IEnumLayer pMapLayers; pMapLayers = m_mapControl.Map.get_Layers(null, true); lyr = pMapLayers.Next(); while (lyr != null) { ToolComboBoxLayer.Items.Add(); lyr = pMapLayers.Next(); } Nothing
Maps and layers(III)
Introduction to Programming ArcObjects with VBA
Lesson overview
访问 maps and layers
遍历 maps 和 layers
Collections
Enumerations
创建一个新的图层 使用图层对象的属性
} catch (Exception) {
throw;
} }
Data access and creation(IIII)
Introduction to Programming ArcObjects with VBA
Lesson overview
Data creation objects
Workspace FeatureDataset FeatureClass
Workspace及相关对象
要操作各种类型的空间数据,首先要获得空间数据所在的工 作空间。Workspace(工作空间)是一个普通类(Class), 这意味着用户不能直接新建它。为了获得一个工作空间,需 要使用WorkspaceFactory对象来创建或打开一个 Workspace。
WorkspaceFactory是GeoDatabase的入口。它是一个抽象 类,派生了很多的子类,例如SdeWorkspaceFactory,
Workspace
FeatureDataset FeatureClasses
Working with fields and field collections Creating Tables and FeatureClasses Adding rows Editing table values
Loop review
Loop a specified number of times
For
Next
Loop based on condition
Do
Do
While
Until
小心无限循环
'Here is an Endless Loop Do While Not MsgBox("Add a Record?") = vbYes 'Code here to add a record to a table MsgBox "Record Added" Loop
2
For intIndex = 0 To pMaps.Count - 1 MsgBox pMaps.Item(intIndex).Name Next intIndex
遍历一个Map对象中的图层对象
IMap’s Layers property returns IEnumLayers
Like Next
a collection with fewer methods and properties returns ILayer
Reset
moves to top of Enum
Dim pLayer As ILayer Dim pLayers As IEnumLayer Set pLayers = yers Set pLayer = pLayers.Next Set pLayer = pLayers.Next Set pLayer = pLayers.Next
Others
Which ones can be created new?
Workspace及相关对象
在Geodatabase数据模型中,一个工作空间对应于一个
geodatabase 或一个ArcInfo coverage工作空间或一个文 件夹(内有地理数据文件)。工作空间是空间数据集与非空 间数据集的容器。
使用图层对象的属性
Ilayer接口的属性
Name,
Visible, ShowTips, MaximumScale, MinimumScale, etc.
IGeoDataset接口属性
Extent,
SpatialReference
'This code will work for ANY type of layer 'Access the document’s selected layer Dim pLayer As ILayer Set pLayer = pMxDoc.SelectedLayer 'Set basic layer properties = "Streets" pLayer.Visible = True pLayer.ShowTips = False
Get all layers (IMap)
An
enumeration of layers
IEnumLayer pAllLayers; pAllLayers = Map.get_Layers(null, true);
遍历Maps集合
பைடு நூலகம்Collections are ordered
Reference First
public ILayer GetFeatureLayer(String slayer, IMap m_pMap)
{
IEnumLayer pLayers ; //枚举图层接口 ILayer pLayer ;//'图层接口 try
{
if( m_yerCount == 0 ) return null;
pLayers = m_pMap.get_Layers(null,true); pLayer = pLayers.Next(); while (pLayer !=null) { if( pLayer is IFeatureLayer && slayer== ) { } return pLayer ; break; } pLayer = pLayers.Next();
Adding a new layer to a map
Layer is an abstract class: Not creatable
Creatable
subclasses: TinLayer, FeatureLayer, RasterLayer, etc.
'Make a New FeatureLayer Dim pFLayer As ILayer Set pFLayer = New FeatureLayer 'Add a layer to MxDocument or Map Dim pMxDoc As IMxDocument Dim pMap As IMap Set pMxDoc = ThisDocument Set pMap = pMxDoc.FocusMap pMap.AddLayer pFLayer 没有设置数据源,所以图标为失去数 据连接的状态。
Data creation objects
WorkspaceFactory Workspace
*
Dataset
Field
1 ..
*
Fields
ShapefileWorkspaceFactory
Row
AccessWorkspaceFactory
Table
FeatureClass ArcInfoWorkspaceFactory
Get all maps (IMaps)
A
collection of Maps
Dim pAllMaps As IMaps Set pAllMaps = pMxDoc.Maps
一个地图文档可以包含有多个数据框,每 个数据框都可以拥有不同的图层和表现。 FocusMap是指向当前活动的数据框
Accessing layers
0
items by position (index)
item is at position 0
1
' Syntax Example For <index = start> To <end> ' process each item … Next <index> ' Map Dim Dim Set collection example … intIndex As Integer pMaps As IMaps pMaps = pMxDoc.Maps
GeoDatabase的基础知识
在AO(AE)中,各种类型的空间数据都采用统一的对象模 型— Geodatabase数据模型进行操作。
Accessing maps
Access maps from MxDocument Get the active map IMap pMap; pMap = axMapControl1.Map;
Setting a FeatureLayer’s data source