Visual Basic: Data - PowerPoint PPT Presentation

Loading...

PPT – Visual Basic: Data PowerPoint presentation | free to download - id: 148c15-NDRkZ



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Visual Basic: Data

Description:

Dim pMap As IMap. Set pMap = pDoc.FocusMap ... You can loop through all the IMap Interface objects in an IMaps Interface object ... – PowerPoint PPT presentation

Number of Views:163
Avg rating:3.0/5.0
Slides: 43
Provided by: andrew58
Learn more at: http://www.geog.leeds.ac.uk
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Visual Basic: Data


1
Lecture 10
  • Visual Basic Data

2
This Lecture
  • Data access.
  • Getting Maps and Layers
  • Getting Attributes
  • Selecting Features
  • More GUIs Forms
  • Help

3
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.

4
Getting data
  • Various levels

Map
AttributeTable
Layer
Feature
234
Values
5
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.

6
Getting all Maps
  • You can also get an Object containing all the
    Maps.
  • Dim pDoc As IMxDocument
  • Set pDoc ThisDocument
  • Dim pMaps As IMaps
  • Set pMaps pDoc.Maps
  • The Maps object is exposed by the IMxDocument
    Interface.
  • It returns an IMaps Interface type Object

7
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
  • Other IMaps Methods include
  • Add, Create, Remove(IMap), RemoveAt(index), Reset
    Remove all.

8
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
Layer
Feature
234
Values
9
Getting Layers
  • If you know what the type of the Layers are, you
    can get them thus
  • Dim pMxDocument As IMxDocument
  • Set pMxDocument Application.Document
  • Dim pMap As IMap
  • Set pMap pMxDocument.FocusMap
  • Dim pLayer As ILayer
  • For i 0 To pMap.LayerCount - 1
  • Set pLayer pMap.Layer(i)
  • Do something
  • Next

10
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.

11
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
    .

12
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.

13
Standard use of Enumerations
  • Dim pEnumSomething As IEnumSomething
  • Set pEnumSomething someEnumGettingMethod
  • pEnumSomething.Reset
  • Dim variable As Something
  • Set variable pEnumSomething.Next
  • Do While Not variable Is Nothing
  • Do stuff with Layer
  • Set variable pEnumSomething.Next
  • Loop

14
How to filter Layers
Dim pMxDoc As IMxDocument Dim pMap As IMap Set
pMxDoc Application.Document Set pMap
pMxDoc.FocusMap
  • Get an Enumeration of Layers
  • Dim pUID As IUID
  • Set pUID New UID
  • pUID "E156D7E5-22AF-11D3-9F99-00C04F6BC78E
  • Dim pEnumLayer As IEnumLayer
  • Set pEnumLayer pMap.Layers(pUID, True)
  • pEnumLayer.Reset
  • Dim pGeoFeatureLayer As IGeoFeatureLayer
  • Set pGeoFeatureLayer pEnumLayer.Next
  • Do While Not pGeoFeatureLayer Is Nothing
  • Do stuff with Layer
  • Set pGeoFeatureLayer pEnumLayer.Next
  • Loop

15
The TypeOf Keyword
  • You can check whether an Object implements an
    Interface using VBs TypeOf keyword.
  • For example, if the users selected something in
    ArcMap's tree of contents, you can test whether
    its a GeoFeatureLayer, thus
  • Dim pUnk As IUnknown
  • Set pUnk pEnumLayer.Next
  • If TypeOf pUnk Is IGeoFeatureLayer Then
  • Set pFeatLayer pUnk
  • 'Do something with pFeatLayer
  • End If

16
Getting data
  • Once we have our Layer, we want to get data from
    it.

Map
AttributeTable
Layer
Feature
234
Values
17
Getting Features from Layers
  • Assign your Layer to an appropriate Interface.
  • IGeoFeatureLayer Treat as Geographical data
  • IFeatureLayer Treat as a general Layer
  • IAttributeTable Treat as an Attribute table
  • Search the Layer, or get the Attribute Table.

18
Getting the Attribute Table
  • Assuming we have a Layer Enumeration, we set the
    Layer to an IAttributeTable.
  • Dim pAttributeTable As IAttributeTable
  • Set pAttributeTable pEnumLayer.Next
  • Dim pTable As ITable
  • Set pTable pAttributeTable.AttributeTable
  • Dim pRow As IRow
  • 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

19
Getting the Attribute Table
  • Assuming we have an Enumeration of Layers
  • Dim pAttributeTable As IAttributeTable
  • Set pAttributeTable pEnumLayer.Next
  • Dim pTable As ITable
  • Set pTable pAttributeTable.AttributeTable
  • Dim pRow As IRow
  • 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

20
Getting data
  • Alternative is to get data from a Feature.

Map
AttributeTable
Layer
Feature
234
Values
First though, we need to get only the features we
are interested in. We can search for these.
21
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.

22
Search Methods
  • IFeatureLayer / IGeoFeatureLayer
  • Set pCursor pFeatureLayer.Search(Q, False)
  • ITable from an IAttributeTable
  • Set pCursor pTable.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.

23
IQueryFilter Objects
  • You can get everything by setting these to
    Nothing.
  • Set pC pFeatureLayer.Search(Nothing, False)
  • IQueryFilter Objects store fields you want
    returned and query strings.
  • pQueryFilter.SubFields SCHOOL,LEA
  • pQueryFilter.AddField (POSTCODE)
  • pQueryFilter.WhereClause LEA Leeds
  • By default the fields are set to i.e. all
    fields, so if you use just AddFields youll have
    to set SubFields to first.

24
Getting Data from a Feature
  • Use the cursor to get the next feature
  • Dim pFeature As IFeature
  • Set pFeature pC.NextFeature
  • Do While Not pFeature Is Nothing
  • Set pFeature pC.NextFeature
  • Do stuff to pFeature
  • Loop
  • The Feature Method getValue(i) takes in an
    integer number equalling the position of the
    field column.
  • If you dont know it, there are lookup methods
    that return integers
  • pFeature.Fields.FindField("SCHOOL")

25
Setting/Getting Features Selected
  • An alternative is to get the selected Features.
  • IMaps SelectFeature method takes in an ILayer
    and IFeature.
  • Refresh the display using the MxDocuments
    refresh.
  • pDoc.ActiveView.Refresh
  • To get the Features you need IMaps
    FeatureSelection Method, or an ISelectionSet
    Object see handout for example.

26
Getting data
  • Various levels

Map
AttributeTable
Layer
Feature
234
Values
27
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.

28
So far
  • Data access.
  • Getting Maps and Layers
  • Getting Attributes
  • Selecting Features
  • Now
  • More GUIs Forms

29
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.

30
The Text Box
  • One useful item you get with Forms is a TextBox.
  • For multiple lines you need to set MultiLine as
    True in its Behaviour properties and give it
    scrollbars.
  • You can then set the text in an Event handling
    method, thus
  • MyForm.TextBox1.Text Its huge vbCrLf
    Its green

31
Running Forms
  • Add in a Macro to the document
  • Sub startF ()
  • MyForm.Show
  • End Sub

32
So far
  • Data access.
  • Getting Maps and Layers
  • Getting Attributes
  • Selecting Features
  • More GUIs Forms
  • Now
  • Help

33
Finding out about Objects
  • The Object Browser / Autocompletion lists
  • Unfortunately, these dont display methods of
    Class Objects whos default Interface is
    IUnknown. As this is most of the ESRI Objects
    this is not so useful.
  • Alternatives
  • The ESRI Object Browser
  • The Object Help Files / Online Help
  • The Object Diagrams

34
ESRI Object Browser
  • The ESRI Object Browser EOBrowser.exe
  • In C\Program Files\ArcGIS\DeveloperKit\tools
  • Starts empty of references.

35
ESRI Object Browser
  • Click whether you want CoClasses, Interfaces etc.
  • Search for a term.
  • Pick a Class from the list and display it.

36
The Object Help Files / Online Help
  • The standard VB Editor help files help you with
    VBA but not ArcObjects.
  • Two ways to access the ArcObjects help
  • Click in a Class or Object and hit the F1 key
    brings up help about that thing.
  • Go to the DeveloperKit/help/ directory all the
    help files.
  • 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/

37
The Help Files
  • ArcGIS Desktop gt Developer Guide
  • A good starting point for good practice when
    using ArcObjects naming standards, code to
    avoid etc.
  • Object Model / Overview
  • Basic descriptions of the branches of the
    Framework and their major classes.
  • Library Reference
  • Lists of all the Interfaces and Classes for the
    Core bits (Application, ArcMap/Editor, ArcCatalog)

38
Help Files
  • List Classes / Interfaces and their methods /
    variables

Access
Class List
Click for more info and example uses
39
The Object Diagrams
  • Notoriously vast pdf UML diagrams. Can get to
    them via the Object Model Diagrams tree in the
    Help or in Arcs DeveloperKit/Diagrams/
    directory.
  • Best to open the AllDesktopOMDs.pdf diagram and
    use Ctrl-F to search for an object class.

40
Understanding UML
  • http//edndoc.esri.com/arcobjects/8.3/
  • ArcObjects online gt Object Models Diagrams gt How
    to read

41
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.

42
Next Lecture
  • Editing data, running commands.
  • VB.Net, ActiveX/Com and ModelBuilder.
  • Practical
  • Data manipulation
About PowerShow.com