Advanced GIS ObjectsInterfaces - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

Advanced GIS ObjectsInterfaces

Description:

For example, Human and Dog (by convention, interface names start with the letter ' ... You want to set a Human or Dog's name, you need to go through the ... – PowerPoint PPT presentation

Number of Views:157
Avg rating:3.0/5.0
Slides: 25
Provided by: Pete8
Category:

less

Transcript and Presenter's Notes

Title: Advanced GIS ObjectsInterfaces


1
Advanced GISObjects/Interfaces
  • Week 5
  • Spring 2005

2
Objects - create your own
  • The object templates is called class modules
  • Object is an instance of a class
  • There are tangible objects, such as control on a
    form and intangible objects - used in a code,
    like a collection object.
  • A class defines properties, methods, events for
    all the objects created from that class.
    Instances from same class have same set of
    properties but different values
  • Object variable is only a pointer.
  • Such as Map Class in ArcMap/ArcView. One map
    object points to world map with small scale and
    another points to Tennessee with larger scale and
    different projection.

3
Object Variables
  • Refer an object variable to existing tangible
    object use Set keyword.
  • Set lstMyListBox frmMain.lstSlides
  • For Intangible Objects, object variables act as
    the handles for reaching the objects. To create
    an intangible object, declare a variable as the
    object class, then set this variable as New
    instance of the class.
  • Dim MyCollection As Collection
  • Set MyCollection New Collection point to new
    instance
  • Dim YourCollection As Collectioin
  • Set YourCollection MyCollection point to
    existing object variable
  • Set MyCollection Nothing release an object
    variable from pointing to an object

4
Generic and specific object types
  • Object, Form and Control are generic object type.
    Specific forms and types of controls are called
    specific object types.
  • The Object class is the most generic, with two
    subclasses , Form and Control (frmMain,
    txtMyText)
  • You can create instances from any form in the
    project.- Create a new project with cmdCreate
  • Private Sub cmdCreate_Click()
  • Dim frmNew As frmMain
  • Set frmNew New frmMain
  • End Sub click cmdCreate 3 times, you will
    create 3 identical forms

5
Keyword New
  • Dim X As New Collection one-step approach,slow
  • Dim X As Collection two-step approach
  • Set X New Collection
  • Generic objects and controls can not be created
    with the New keyword
  • Set X New Object
  • Set X New Form
  • Set X ListBox
  • Set X New TextBox
  • Set X New ListBox
  • Set X New txtTitle
  • Set X New lstSlides

This is ok!
Dim X As Control Dim Y As Control Set X
frmMain.lstSlides Set Y X
6
Create a Class
  • Project Add Class Module. The name of the class
    module is the name of the class to be created.
    Class module is saved as .cls files. A .cls file
    can be added to any VB project, where instances
    of the class can be created.
  • Create a Title property for Class1
  • Type in codes as in the box
  • mvarTitle is used to store the
  • property value within the class module
  • Suppose you have a class named
  • Slide, and an instance named
  • aSlide.
  • aSlide.Title My Slide Show
  • strTitle aSlide.Title

Option Explicit Public Title As String 'General
Declaration section Private mvarTitle As
String 'Write property Public Property Let
Title(NewTitle As String) mvarTitle
NewTitle End Property 'Read property Public
Property Get Title() As String Title
mvarTitle End Property
ClassCreate
7
Class Property
  • Default value for title (if a property has a
    default value) type in code in Class_Initialize()
    procedure
  • Private Sub Class_Initialize()
  • mvarTitle Default Title
  • End Sub
  • To create a read-only property, you dont need to
    supply the Property Let procedure. For write-only
    property, no need for Get procedure
  • Read-only procedure e.g. Count property of a
    class
  • Write-only property user change password but
    doesnt show existing password

8
Create methods
  • Simply create a procedure or function within
    Class code window
  • Public Sub Welcome()
  • MsgBox "Welcomes to the slide show!"
  • End Sub
  • Public Sub SpecialWelcome(strName As String)
  • MsgBox strName ", welcome to the slide
    show!"
  • End Sub
  • Call methods from frmMaincmdClick()
  • Dim CallClass As Class1
  • Set CallClass New Class1
  • CallClass.Welcome
  • CallClass.SpecialWelcome Peter

9
clsMyFirstClass Create a class in your project
  • Option Explicit
  • 'Public Title As String
  • 'General Declaration section
  • Private mvarTitle As String
  • 'Write property
  • Public Property Let Title(NewTitle As String)
  • mvarTitle NewTitle
  • End Property
  • Public Sub Welcome(strMsg As String) method
  • MsgBox strMsg
  • End Sub
  • 'Read property
  • Public Property Get Title() As String
  • Title mvarTitle
  • End Property

10
Instance of Object (Form with cmdCall control)
  • Private Sub cmdCall_Click()
  • Dim myObject As Object
  • Set myObject New objFirst
  • Dim mTitle As String
  • Dim nTitle As String
  • mTitle InputBox("Type in title here")
  • 'Set myObject's title as mTitle
  • myObject.Title mTitle
  • 'Get title from myObject
  • nTitle myObject.Title
  • 'Show title of myObject using MsgBox
  • MsgBox "The title of object is " nTitle
  • myObject.Welcome "Hello World, Hello World"

11
Interface - part of Component Object Model(COM)
  • A logical group of methods and properties for a
    class. It may be based on the level of generality
    or on some other similarity of use or purpose.
    For example, Human and Dog (by convention,
    interface names start with the letter I, shown
    w/ lollipops)

Dog
IBehavior
IAnimal
Both Human and Dog class have IAnimal interface.
The IBehavior in Dog and IGreeting in Human are
unique to themselves. You want to set a Human or
Dogs name, you need to go through the IAnimal
interface
12
Interfaceless Class and Interfaced Class
  • Dim e As Elephant
  • Set e New Elephant
  • E.Name Big Ears
  • 1)Choose appropriate Interface to work with, such
    as Name property in IMap interface of Map.
  • 2) Declare the variable as IMap instead of Map
    class, but still set to New Map.
  • Dim pMap as IMap
  • Set pMap New Map
  • pMap.Name My Map
  • Accessing Extent property, then a new Interface
    will be used.
  • Dim pActiveView As IActiveView
  • Set pActiveView New Map
  • pActiveView.Extent someNewExent

To view diagram - Open ArcMap-diagram.pdf from
g\classes\4850\
13
Using IApplication and IDocument
  • ArcMap starts, two objects are in use
    Application and MxDocument. The name of
    Application object variable is Application and
    the name of the MxDocument object variable is
    ThisDocument (all begin with p).

Application
IApplication
CaptionString
Name String
Two-sided barbell get and set values Left-sided
barbell get value only
PrintPreview
14
Procedure for accessing methods/properties of
components
  • To access the methods/properties of components
  • 1) Declare an object as the interface (Dim pHuman
    As IGreeting)
  • 2) point the object variable to a new instance of
    the component (Set pHuman New Human)
  • 3) Access the methods/properties
    (pHuman.HandShake, pHuman.Smile)
  • 4) you can only access those properties/methods
    supported by the declared interface. If you want
    to access other methods/properties, you need to
    use the QueryInterface process.

15
QueryInterface
  • Allows an object variable of one interface to
    access properties/methods of other interfaces of
    the same component.
  • Dim pHuman As IGreeting
  • Set pHuman New Human
  • pHuman.HandShake
  • pHuman.Smile
  • Using QueryInterface to access properties and
    methods of the IAnimal interface
  • Dim pAnimal As IAnimal
  • Set pAnimal pHuman
  • pAnimal.Eat
  • pAnimal.Breathe

or do the error-checking first If TypeOf pHuman
Is IAnimal Then
point the variable to the object variable of
other interface
16
QueryInterface examples from book and
arcobjectonline.esri.com, (g/classes/4850/w_arcOb
jectStartSlides.pdf)
17
(No Transcript)
18
(No Transcript)
19
(No Transcript)
20
(No Transcript)
21
(No Transcript)
22
(No Transcript)
23
Point Geometry
  • A Geometry is an abstraction of all the
    ArcObjects geometrical classes.
  • A geometry is empty when first created.
  • Use following statement to confirm
  • If Not pGeometry Is Nothing Then
  • If Not pGeometry.IsEmpty Then
  • Use the pGeometry here
  • End If
  • End If
  • Use SetEmpty to delete pGeometry

24
Another Example of QI
  • Dim pPoint As IPoint
  • Set pPoint New Point
  • pPoint.X 100 You may use pPoint.PutCoords
    100,100
  • pPoint.Y 100
  • Dim pTopoOptr As ITopologicalOperator
  • Set pTopoOptr pPt
  • Dim pBufferGeo As IPolygon
  • Set pBufferGeo pTopoOptr.Buffer(20)
Write a Comment
User Comments (0)
About PowerShow.com