Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 3 Introducing ArcObjects

Similar presentations


Presentation on theme: "Lecture 3 Introducing ArcObjects"— Presentation transcript:

1 Lecture 3 Introducing ArcObjects
ArcObjects is the development platform for the ArcGIS family of applications such as ArcMap, ArcCatalog, and ArcScene. ArcObjects is built using Microsoft’s Component Object Model (COM) technology. Therefore – VBA is embedded within ArcCatalog and ArcMap, and can be used to customize the ArcGIS Desktop applications. 2018/11/17 Jun Liang, UNC

2 Jun Liang, Geography @ UNC
ArcObjects (Cont.) A set of components of the ArcGIS platform which can be accessed through programming environment (VBA, C++, Python, etc.) Have characteristics which can be queried or set Have the ability to perform operations Have the ability to respond to changes in the application framework in which they are deployed Object Model Diagrams (OMD’s)in PDF format (ALLOMDS.pdf) 2018/11/17 Jun Liang, UNC

3 Reading the object model diagrams
2018/11/17 Jun Liang, UNC

4 Reading the object model diagrams (Cont.)
Types of Classes An abstract class cannot be used to create new objects but is a specification for instances of subclasses (through type inheritance.) A CoClass can directly create objects by declaring a new object. A Class cannot directly create objects, but objects of this class can be created as a property of another class or instantiated by objects from another class. 2018/11/17 Jun Liang, UNC

5 Jun Liang, Geography @ UNC
Associations Relationships 1. Associations Associations represent relationships between classes. They have defined multiplicities at both end. 2018/11/17 Jun Liang, UNC

6 Jun Liang, Geography @ UNC
Multiplicity 2. Multiplicity A Multiplicity is a constraint on the number of objects that can be associated with another object. This is the notation for multiplicities: 1 – One and only one. 0..1 – Zero or one M..N – From M to N (positive integers) * Or 0..* - From zero to any positive integer 1..* - From one to any positive integer 2018/11/17 Jun Liang, UNC

7 Jun Liang, Geography @ UNC
Inheritance Type inheritance defines specialized classes that share properties and methods with the superclass and have additional properties and methods. This diagram shows that a primary line (creatable class) and secondary line (creatable class) are types of a line (abstract class). 2018/11/17 Jun Liang, UNC

8 Instantiation Instantiation specifies that one object from one class has a method with which it creates an object from another class. A pole object might have a method to create a transformer object. Pole Transformer OverviewWindowFactory OverviewWindow 2018/11/17 Jun Liang, UNC

9 Jun Liang, Geography @ UNC
Composition Composition is a stronger form of aggregation in which objects from the “whole” class control the lifetime of objects from the “part” class. Pole 1..* Crossarm A pole contains one or many crossarms. In This design, a crossarm cannot be recycled before the pole is removed. The pole object controls the lifetime of the crossarm object. 2018/11/17 Jun Liang, UNC

10 Jun Liang, Geography @ UNC
Composition (Cont.) A MxDocument object contains none or many TOCView object: MxDocument * TOCView 2018/11/17 Jun Liang, UNC

11 Jun Liang, Geography @ UNC
Interface key Property Get: Read Property Put: Write Property Get/Put: Read/Write Property Put by Reference: Write 2018/11/17 Jun Liang, UNC

12 Jun Liang, Geography @ UNC
Making Decisions Coding for making decisions Making a case for branching Select Case theTrafficSignalValue Case Red Stop the car Case Green Continue with caution Case Yellow Stop the car if you can not make if before red Case Else Treat the intersection as if it has a stop sign End Select 2018/11/17 Jun Liang, UNC

13 Coding for making decisions (Cont.)
If Then Statement If Today = aWorkDay Then Turn left to work in the city ElseIf Weather = Bad Then Go ahead for the library Else Turn right to drive in the countryside End IF 2018/11/17 Jun Liang, UNC

14 Using subroutines and functions
Calling a subroutine (example - ex6a) Public Sub Message() MsgBox “Geography is terrific” End Sub Public Sub GetMessages() Call Message One procedure can call many others. A procedure may call a procedure that calls another procedure 2018/11/17 Jun Liang, UNC

15 Using subroutines and functions (Cont.)
Passing values to a subroutines PublicSub PrintMap (aPageSize As String) .. End When you call the PrintMap subroutine, you must enter a value for its argument: Call PrintMap (“Letter”) Example in ArcGIS: Call CreateNewChart(userTitle) You can also make several calls to a single subroutine (example - ex6c) 2018/11/17 Jun Liang, UNC

16 Using subroutines and functions (Cont.)
Returning values with functions (ex6d) Question: What is the difference between subroutines and functions? strValue = InputBox (“Enter a Parcel Value”) Example: Public Function KilometersToMiles (km As Double) As Double KilometersToMiles = km * End Function Dim x As Double x = KilometersToMiles(10) 2018/11/17 Jun Liang, UNC

17 Jun Liang, Geography @ UNC
Looping your code Coding a For loop (ex7a) For x=1 to 10 ‘Code here to print map MsgBox “Printing map” & x Next For x=1 to Step 20 cboFavoriteNumber.AddItem x end 2018/11/17 Jun Liang, UNC

18 Looping your code (Cont.)
Coding a Do loop (ex7b) Do While Expression -Code here runs as long as the expression is true Loop Do Until Expression -Code here runs as long as the expression is false Do While Msgbox (“Print the map?”, vbYesNo) = vbYes ‘Code here to print map MsgBox “Printing Map” 2018/11/17 Jun Liang, UNC

19 Jun Liang, Geography @ UNC
Fixing bugs Before VBA code runs, it is automatically translated into machine language. This translation is called compiling. (1)Syntax Error: When there is a problem in the translation, you get a compile error and the code does not run. Examples? (2) Instruction Error: Run time errors occur after the code has successfully complied and is being run. Examples? 2018/11/17 Jun Liang, UNC

20 Jun Liang, Geography @ UNC
Fixing bugs (Cont.) Using the debug tools Step Into button – when will you need this? Toggle Breakpoint – you can also add a breakpoint by clicking in the code window’s margin. Either way, a red circle marks the spot and the line of code turn red. Please try exercise 8 for debugging experiences. 2018/11/17 Jun Liang, UNC

21 Making your own objects
How did you make objects in Avenue? Examples: aPointList = List.Make aFileName = FileName.Make(“$HOME/data/test.data”) aCircle = Circle.Make(aPoint, aRadius) In Visual Basic: Dim d1 As Dog Set d1 = New Dog d1.Name = “Sparky” d1.Bark 2018/11/17 Jun Liang, UNC

22 Making your own objects (Cont.)
How to create classes? In VBA, you create a new class by making a new class module. You can store the module in any of the three projects: the current map document, the normal template, or a base template. Class created in the current map document – client side programmers will only be able to create objects from it. If you want the class to b e available to any map document, you should store the class module in the normal project. 2018/11/17 Jun Liang, UNC

23 Making your own objects (Cont.)
To create a class, you need (exercise 9ab) Create properties of this class Create methods of this class Example: Public Value As Currency Public Zoning As String Public Function CalculateTax() …… End Function 2018/11/17 Jun Liang, UNC

24 Programming with Interfaces
Programming Interface – different from a user interface. An interface is a logical grouping of properties and methods for a class. It might be based on the level of generality or on some other similarity of use or purpose. Elephant IElephant TuskLength: Integer Trumpet IAnimal Age: Integer Name: String Sleep 2018/11/17 Jun Liang, UNC

25 Programming with Interfaces (Cont.)
Interfaces are part of the Component Object Model (COM) COM is a set of programming standards developed by Microsoft. COM allows code written in one language (like visual basic) to work with code written in another language, like C++. ArcObjects interfaces and classes are created with C++ As you work with classes that have interfaces, you have to find out which interfaces a property or method is on before you use it. 2018/11/17 Jun Liang, UNC

26 Programming with Interfaces (Cont.)
Map IMap Layer: ILayer MapScale: Double Name: String AddLayer: ILayer MoveLayer: ILayer IActiveView Extent: IEnvelope ShowSelection: Boolean Dim pMap As IMap Set pMap = New Map pMap.Name = “Ryan’s Map” 2018/11/17 Jun Liang, UNC

27 Programming with Interfaces (Cont.)
Using IApplication and IDocument When you start ArcMap and open a map document, a couple of objects are already in use: Application object : Application MxDocument object : ThisDocument These two are the only predefined object variables there are. All ArcObjects classes have interfaces. All ArcObjects variables are pointer variables that point to interfaces. See page 152 for IApplication Please finish Exercise 10a on class. 2018/11/17 Jun Liang, UNC

28 Programming with Interfaces (Cont.)
Using multiple interfaces ArcObjects classes can have several interfaces You can work with multiple interfaces pointing to multiple classes You may also want to work with different interfaces from the same variable. Check examples on Page 159 Learn how you can define different interfaces which point to the same object. Please finish exercise 10b 2018/11/17 Jun Liang, UNC


Download ppt "Lecture 3 Introducing ArcObjects"

Similar presentations


Ads by Google