【文章內(nèi)容簡(jiǎn)介】
fic layer (IMap) ? Get all layers (IMap) ? An enumeration of layers Dim pLayer As ILayer Set pLayer = Dim pAllLayers As IEnumLayer Set pAllLayers = Dim pLayer As ILayer Set pMap = Set pLayer = (3) Introduction to Programming ArcObjects with VBA Copyright 169。 2022, 2022 ESRI. All rights reserved. 642 遍歷 Maps集合 ? Collections are ordered ? Reference items by position (index) ? First item is at position 0 39。 Map collection example … Dim intIndex As Integer Dim pMaps As IMaps Set pMaps = For intIndex = 0 To 1 MsgBox (intIndex).Name Next intIndex 0 1 2 39。 Syntax Example For index = start To end 39。 process each item … Next index Introduction to Programming ArcObjects with VBA Copyright 169。 2022, 2022 ESRI. All rights reserved. 643 遍歷一個(gè) Map對(duì)象中的圖層對(duì)象 ? IMap’s Layers property returns IEnumLayers ? Like a collection with fewer methods and properties ? Next returns ILayer ? Reset moves to top of Enum Set pLayer = Nothing IEnumLayer Top Set pLayer = Set pLayer = Set pLayer = Dim pLayer As ILayer Dim pLayers As IEnumLayer Set pLayers = Introduction to Programming ArcObjects with VBA Copyright 169。 2022, 2022 ESRI. All rights reserved. 644 遍歷一個(gè) Map對(duì)象中的圖層對(duì)象 ? Do While or Do Until ? Loop based on a Condition (Boolean) 39。 Layer enum example Dim pLayer As ILayer Dim pMapLayers As IEnumLayer Set pMapLayers = Set pLayer = Do Until pLayer Is Nothing MsgBox Set pLayer = Loop Nothing 39。 Syntax Example Do Until/While a condition is true 39。Run this code Loop Introduction to Programming ArcObjects with VBA Copyright 169。 2022, 2022 ESRI. All rights reserved. 645 Managing flow in a loop ? Exit a loop prematurely when a condition is true ? For Next loops: Exit For ? Do While and Do Until loops: Exit Do Dim pCityMap As IMap Dim X As Integer For X = 0 To 1 If (X).Name = Cities Then Set pCityMap = (X) Exit For End If Next X MsgBox All Done, vbInformation Introduction to Programming ArcObjects with VBA Copyright 169。 2022, 2022 ESRI. All rights reserved. 646 Loop review ? Loop a specified number of times ? For Next ? Loop based on condition ? Do While ? Do Until ? 小心無(wú)限循環(huán) 39。Here is an Endless Loop Do While Not MsgBox(Add a Record?) = vbYes 39。Code here to add a record to a table MsgBox Record Added Loop Introduction to Programming ArcObjects with VBA Copyright 169。 2022, 2022 ESRI. All rights reserved. 647 Adding a new layer to a map ? Layer is an abstract class: Not creatable ? Creatable subclasses: TinLayer, FeatureLayer, RasterLayer, etc. 39。Make a New FeatureLayer Dim pFLayer As ILayer Set pFLayer = New FeatureLayer 39。Add a layer to MxDocument or Map Dim pMxDoc As IMxDocument Dim pMap As IMap Set pMxDoc = ThisDocument Set pMap = pFLayer 沒(méi)有設(shè)置數(shù)據(jù)源,所以圖標(biāo)為失去數(shù)據(jù)連接的狀態(tài)。 Introduction to Programming ArcObjects with VBA Copyright 169。 2022, 2022 ESRI. All rights reserved. 648 使用圖層對(duì)象的屬性 ? Ilayer接口的屬性 ? Name, Visible, ShowTips, MaximumScale, MinimumScale, etc. ? IGeoDataset接口屬性 ? Extent, SpatialReference 39。This code will work for ANY type of layer 39。Access the document’s selected layer Dim pLayer As ILayer Set pLayer = 39。Set basic layer properties = Streets = True = False Introduction to Programming ArcObjects with VBA Copyright 169。 2022, 2022 ESRI. All rights reserved. 649 Setting a FeatureLayer’s data source ? FeatureClass property (IFeatureLayer) ?指定顯示的數(shù)據(jù)源 ?以傳引用的方式 (must use the Set keyword) ? 更多的數(shù)據(jù)訪問(wèn)例子在以后的課程中 39。Make a new FeatureLayer Dim pFLayer As IFeatureLayer Set pFLayer = New FeatureLayer 39。Get another layer’s FeatureClass Dim pFClass As IFeatureClass Set pFClass = 39。Set the new layer’s FeatureClass property Set = pFClass Introduction to Programming ArcObjects with VBA Copyright 169。 2022, 2022 ESRI. All rights reserved. 650 Exercise 8 overview ? Loop ? Maps in a document ? Layers in a map ? Fields in a layer table ? Add a layer to a map ? Set basic properties ? Set the data source Copyright 169。 2022, 2022 ESRI. All rights reserved. Introduction to Programming ArcObjects with VBA Data access and creation(IIII) Introduction to Programming ArcObjects with VBA Copyright 169。 2022, 2022 ESRI. All rights reserved. 652 Lesson overview ? Data creation objects ? Workspace ? FeatureDataset ? FeatureClass ? Working with fields and field collections ? Creating Tables and FeatureClasses ? Adding rows ? Editing table values FeatureClasses Workspace FeatureDataset Introduction to Programming ArcObjects with VBA Copyright 169。 2022, 2022 ESRI. All rights reserved. 653 Data creation objects Table Fields Field 1 .. Dataset Workspace WorkspaceFactory AccessWorkspaceFactory Row * FeatureClass ArcInfoWorkspaceFactory ShapefileWorkspaceFactory Others Which ones can be created new? * Introduction to Programming ArcObjects with VBA Copyright 169。 2022, 2022 ESRI. All rights reserved. 655 Opening an existing Workspace ? Use IWorkspaceFactory to return a Workspace object ? Generic interface for all subtypes of WorkspaceFactory ? OpenFromFile: Access an existing folder on disk ? Open: Connect to an existing database (., ArcSDE) Dim pWFactory As IWorkspaceFactory Set pWFactory = New ArcInfoWorkspaceFactory Dim pWorkspace As IWorkspace Set pWorkspace = (D:\Covers, 0) Introduction to Programming ArcObjects with VBA Copyright 169。 2022, 2022 ESRI. All rights reserved. 657 Getting a FeatureDataset ? IFeatureWorkspace interface on Workspace ? OpenFeatureDataset method Dim pFWorkspace As IFeatureWorkspace Set pFWorkspace = pWorkspace 39。QI for IFeatureWorkspace Dim pCover As IFeatu