Professional Documents
Culture Documents
This Lecture
Data access.
Getting Maps and Layers Getting Attributes Selecting Features
Data Access
The ArcMap Object model Application
Document / MxDocument type Object Display / AppDisplay type Object
Document
Maps, FocusMap, ActiveView, StyleGallery
Well look at
Getting the Maps, Layers, Features. Getting Attribute data. Selecting and getting selected Features.
Getting data
Various levels
Map AttributeTable
FID Data 234 875
Layer
1 2
Feature
234
Values
Getting a Map
A Map contains all the data and features in the Data View or each Layout View Frame. Dim pDoc As IMxDocument Set pDoc = ThisDocument Dim pMap As IMap Set pMap = pDoc.FocusMap FocusMap is the one visible in data view or selected in layout view.
IMaps
You can loop through all the IMap Interface objects in an IMaps Interface object using its .count and .item Methods.
Dim pMap As IMap For i = 0 To pMaps.count -1 Set pMap = pMaps.item(i) Do stuff to pMap Next
Getting data
Its rare we want to get data out of a Map. Its more usual to get data from a Layer ~ (a Coverage, FeatureDataset, Image etc.).
Map AttributeTable
FID Data 234 875
Layer
1 2
Feature
234
Values
Getting Layers
If you know what the type of the Layers are, you can get them thus
Dim Set Dim Set pMxDocument As IMxDocument pMxDocument = Application.Document pMap As IMap pMap = pMxDocument.FocusMap
Dim pLayer As ILayer For i = 0 To pMap.LayerCount - 1 Set pLayer = pMap.Layer(i) Do something Next
Types of Layer
Remember however that we can add many things as Layers (images, data, etc.). If we dont know the data type we need to filter our Layers before we try to do some job. We do this by knowing the number by which the system refers to the Layer Classes as. This is quite painful.
Types of Layer
IDataLayer
{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}
IGeoFeatureLayer
{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}
IGraphicsLayer
{34B2EF81-F4AC-11D1-A245-080009B6F22B}
IFDOGraphicsLayer
{34B2EF85-F4AC-11D1-A245-080009B6F22B}
ICoverageAnnotationLayer
{0C22A4C7-DAFD-11D2-9F46-00C04F6BC78E}
IGroupLayer
{EDAD6644-1810-11D1-86AE-0000F8751720}
Layers that implement IDataLayer include FeatureLayers, FDOGraphicsLayers (Annotation), TinLayer, RasterLayer, and CoverageAnnotationLayer.
Enumerations
Objects containing lists of other objects. Like a 1D array. Arc uses them to return arrays of data to you. Have a next Method to get the next Object. Also a reset Method to return to the start. Arc Object types have different Enumerations. IEnumFeature is the Interface for a set of Map IFeatures.
Dim pUnk As IUnknown Set pUnk = pEnumLayer.Next If TypeOf pUnk Is IGeoFeatureLayer Then Set pFeatLayer = pUnk 'Do something with pFeatLayer End If
Getting data
Once we have our Layer, we want to get data from it.
Map AttributeTable
FID Data 234 875
Layer
1 2
Feature
234
Values
Assuming we have an Enumeration of Layers Dim pAttributeTable As IAttributeTable Set pAttributeTable = pEnumLayer.Next
For i = 0 To pTable.RowCount(Nothing) - 1 Set pRow = pTable.GetRow(i) Dim index As Long index = pTable.FindField("School") Debug.Print pRow.Value(index) Next i
Getting data
Alternative is to get data from a Feature.
Map AttributeTable
FID Data 234 875
Layer
1 2
Feature
234
Values
First though, we need to get only the features we are interested in. We can search for these.
Searching
You need to get a reference to the data and a search cursor (ICursor / IFeatureCursor). The search cursor jumps between records in a dataset that match some search criteria. The cursor marks the row in the dataset that youre currently interested in. They have a nextFeature Method which gets a Feature object appropriate to the Dataset.
Search Methods
IFeatureLayer / IGeoFeatureLayer
Set pCursor = pFeatureLayer.Search(Q, False)
Where pCursor is an IFeatureCursor Object Q is an IQueryFilter Object True / False determines how the records are allocated to the Cursor set to False.
IQueryFilter Objects
You can get everything by setting these to Nothing.
Set pC = pFeatureLayer.Search(Nothing, False)
By default the fields are set to * i.e. all fields, so if you use just AddFields youll have to set SubFields to first.
pFeature.Fields.FindField("SCHOOL")
To get the Features you need IMaps FeatureSelection Method, or an ISelectionSet Object see handout for example.
Getting data
Various levels
Map AttributeTable
FID Data 234 875
Layer
1 2
Feature
234
Values
Summary
Get the Applications Document. Get the Maps from it. Pick the one you want or loop through them. Get a Layer from the Map, or Loop through all of them. Generate an Attribute table and use Rows / Fields to get data. Or use the Layers search routine to search for Features.
So far
Data access.
Getting Maps and Layers Getting Attributes Selecting Features
Now:
More GUIs : Forms
Forms
Even easier than UIControls. Instead of a Module, add a Form. Brings up the Form editor drag stuff in. Change its properties (which are variables you can alter on the fly) Double click on Objects to alter Event Methods.
Running Forms
So far
Data access.
Getting Maps and Layers Getting Attributes Selecting Features
Now:
Help
Alternatives
The ESRI Object Browser The Object Help Files / Online Help The Object Diagrams
However, just as easy, and more up to date are the online help files at ArcGIS Developer Online
http://edndoc.esri.com/arcobjects/9.1/
Library Reference
Lists of all the Interfaces and Classes for the Core bits (Application, ArcMap/Editor, ArcCatalog)
Help Files
Understanding UML
http://edndoc.esri.com/arco bjects/8.3/ ArcObjects online > Object Models Diagrams > How to read
Summary
Get the Applications Document. Get the Maps from it. Pick the one you want or loop through them. Get a Layer from the Map, or Loop through all of them. Generate an Attribute table and use Rows / Fields to get data. Or use the Layers search routine to search for Features.
Next Lecture
Editing data, running commands. VB.Net, ActiveX/Com and ModelBuilder.
Practical
Data manipulation