Title: ArcObjects
1ArcObjects
- Sara Alspaugh
- EVSC 468
- 27 March 2007
2- What? Why? How?
- Where? When? What? Why? What?
3What
- ArcObjects is the development platform for the
ArcGIS family of applications such as ArcMap,
ArcCatalog, and ArcScene. The ArcObjects software
components expose the full range of functionality
available in ArcInfo and ArcView to software
developers. - ArcObjects is a framework that lets you create
domain-specific components from other components.
The ArcObjects components collaborate to serve
every data management and map presentation
function common to most GIS applications.
ArcObjects provides an infrastructure for
application customization that lets you
concentrate on serving the specific needs of your
clients. - ESRIs ArcObjects Online help system
- Built using Microsofts Component Object Model
(COM) technology.
4What?
5Hmmlets start with just Objects
- Look at it like this
- What do we use computers to do?
- Store data
- Perform functions
- So they came up with this new way to think
about and design software - Objects!
- Encapsulate data and functions
- Just like objects in the real worldcan be any
sort of object - For instance, imagine a list. No,a List.
- Its an object
- We want to use it to store various pieces of
information, likethe length of the list (a
number), the items in the list (other objects
maybe?) - Also we want it to perform certain functionslike
clear() itself, insert(anItem), and tell us its
length().
6You may be thinking
- Wow thats pretty obvious.
- What did they do before?
- Answer
- Functional programming
- Instead of objects containing data and
procedures, just have procedures, that take as
input other procedures and output other
procedures and have rules for evaluating those
procedures and blah blah blah blah - Like algebra. Kind of.
- Much harder (!) to write programs this way.
Yucky!
7Anywayan Example Object
- Say we need some way to write a program that
keeps the time - We can make a Clock object!
- How create a type of that object that generally
specifies how all clocks are to work, then create
an instancean actual individual objectof that
type
Class (or Interfce) Clock Data Integer
hours Integer minutes Integer
seconds String meridiem Functions makeClock(
) makeCopy(aClock) getTime() resetTime(newHo
ur, new Minute, new Second)
8So back to ArcObjects
9What about the rest of the definition?
- Component Object Model (COM) a platform for the
realization of Object-Oriented Development and
Deployment - Microsoft lackey who wrote the Wikipedia article
on Component Object Model
- A protocol or standard
- More than a technology
- A methodology
- A client-server architecture
10(cont.)
- A way to produce reliable, reusable,
language-independent codeat the binary level - Essentially, the server is this binary file that
contains this code needed to create classes of
objects and run their methods or procedures - The objects are the building blocks of any
software system, and the COM specifies the model
and requirements for creating them that allows
them to do what they do
11How?
- RPC remote procedure call technology
- IDL interface description language
- GUID globally unique identifier
- Type Library
- ClassFactories
12Remote Procedure Call technology
- Allows a computer program to cause a procedure to
execute in another address space - A.k.a. in another computer
- A.k.a. the program makes something happen on
another computer - In other words, it is the paradigm for
implementing this client-server architecture we
talked about - A remote procedure call starts by the client
(you, or the developeractually your computer)
sending a request message to a known server
(ArcObjects!) in order to execute some procedure
you want to execute using parameters you supply.
The server then gives a response to the client
and the client continues along with what it was
doing.
13Hey! I want to do this one thing. Here, use
these parameters or whatever.
parameters
Ok...go ahead. Heres how to do it, I guess.
There, its done.
14Interface Description Language
- The client and server may not be speaking the
same language. They may not even be operating on
the same system. How do they get around that? - A computer language to describe software
components interface (the specification thing
that says what they are supposed to look like and
do) in a language-neutral way - Thereby enabling communication between software
components that are written in different
languages! - Interface Description Language files are used to
generate the code to interface between the client
and the server.
15Hei! Ik wil dit een ding doen. Gebruik hier deze
parameters of wat dan ook.
parameters
Ok ... ??????????????,???????,????
The language-neutral IDL file
16Ok
- COM provides an IDL file
- This allows developers to define their objects in
a language-independent manner - P.S
- COM is a run-time framework
- What does that mean?
- Means the types of objects must be identifiable
at run-time - Oh ok.
17GUID
- How can we ever possibly identify ever single
different type of object there is? - Globally Unique IDever object has one.
- Amounts to a 128-bit number guaranteed to be
unique in the world. - An example number
- E6BDAA76-4D35-11D0-98BE-00805F7CED21
- 1110 0110 1011 1101 1010 1010 0111 0110 0100 1101
0011 0101 0001 0001 1101 0000 1001 1000 1011 1110
0000 0000 1000 0000 0101 1111 0111 1100 1110 1101
0010 0001 - Interesting fact It is possible to generate 10
million GUIDs per second until the year 5770 A.D.
and each one would be unique.
18One other thing
- COM provides a Type Library
- Compiled from the IDL definition provided by the
developer - Once this library is compiled the language
compiler must read and appropriately interpret it
to produce the code necessary for the developer
to produce the binary code which can be deemed by
COM part of the COM interface
19How do we start making (COM)/(Arc) objects?
- Need two things
- GUID
- ClassFactory
- This is itself a COM object that is contained
within the servers executable code that creates
other objects given their unique ID - Each object type has its own ClassFactory
- Waitif you need a ClassFactory to produce an
object but a ClassFactory is itself an object? - DLLdynamic link libraries
- EXEexecutables
- Basically there are two different ways to expose
class factories but we wont get into that
20(No Transcript)
21My Graphical Overview
Framework
CoRegisterClassObject()
Components
DllGetClassObject()
SimpleDisplay
SimpleMarkerSymbol
GUID
ClassFactory
Tool
IndexGrid
GUID
GUID
GUID
PolygonElement
GUID
SimpleRenderer
Type Library
My Application
GUID
GUID
Client
Server
22Common Approaches
- Customize ArcGIS Desktop applications through
Visual Basic for Applications (VBA) which is
embedded in ArcMap and ArcCatalog - Building targeted applications that bypass the
application framework of ArcMap and ArcCatalog
23Some of the many topics I didnt cover involving
some of what you might need to know to start
developing using Visual Basic (first approach)
- User-interface standardsVariable
declarationSuggested naming standardsParentheses
Order of conditional determinationIndentationDe
fault propertiesIntermodule referencingMultiple
property operationsArraysBitwise operatorsType
suffixesAmbiguous type matchingSimple image
displayError handlingEvent functions
- While Wend constructsThe Visual Basic Virtual
MachineInteracting with the IUnknown
InterfaceAccessing ArcObjectsWorking With
HRESULTsWorking with propertiesWorking with
methodsWorking with eventsPointers to valid
objects as parametersPassing data between
modulesUsing the TypeOf keywordUsing the Is
operatorIterating through a collection
24Some of the many topics I didnt cover involving
some of what you might need to do it the second
way
- CODING STANDARDSGENERAL CODING TIPS AND
RESOURCES   Class diagrams   Object
browsers   Component help   Code
wizards   Indexing of collections   Accessing
collection elements   Enumerator use   Error
handling   Notification interfaces   Client
side storage   Property By Value and By
Reference   Initializing Outbound Interfaces
- DATABASE CONSIDERATIONS   Edit sessions   Edit
operations   Recycling and nonrecycling
cursors   Fetching properties using query
filters   Marking changed objects   Update and
insert cursors   Shape and ShapeCopy geometry
propertyUSING A TYPE LIBRARYCOM DATA
TYPESUSING COMPONENT CATEGORIESWHICH
DEVELOPMENT ENVIRONMENT
25Programming in VB.NET--a simple walkthrough
- Create a new class library
- Reference the ESRI object libraries
- Create a zoom-in command
- Add Imports statements
- Implement the ICommand interface
- Adding code to the members of ICommand
- Returning the ICommandBitmap property
- Expose the ZoomIn class to COM
- Adding COM category registration functions
- Compiling the project
- Use the command in ArcMap
- Stepping through the command with the debugger
26- Public Class ZoomIn
- Â Â Â Implements ICommand
- Â Â Â
- Â Â Â Private m_app As IApplication
- Â Â Â Private m_enabled As Boolean
- Â Â Â Private m_bitmap As System.Drawing.Bitmap
-    Private m_hBitmap As IntPtr   Â
- Â Â Â Region "COM GUIDs"Â Â Â ...
- Public Sub OnCreate(ByVal hook As Object)
Implements ICommand.OnCreate - Â Â Â Â If Not (hook Is Nothing) Then
- Â Â Â Â Â Â Â If TypeOf (hook) Is IMxApplication Then
- Â Â Â Â Â Â Â Â Â Â m_app CType(hook, IApplication)
- Â Â Â Â Â Â Â Â Â Â m_enabled True
- Â Â Â Â Â Â Â End If
- Â Â Â Â End If
- Â Â End Sub
- Â
27- Public Sub OnClick() Implements ICommand.OnClick
- Â Â Â Â Dim mxDoc As IMxDocument
CType(m_app.Document, IMxDocument) - Â Â Â Â Dim activeView As IActiveView
mxDoc.ActiveView - Â
- Â Â Â Â Dim currExtent As IEnvelope
activeView.Extent - Â Â Â Â currExtent.Expand(0.5D, 0.5D, True)
- Â Â Â Â activeView.Extent currExtent
- Â Â Â Â activeView.Refresh()
- Â Â End Sub
- Public ReadOnly Property Caption() As String
Implements ICommand.Caption - Â Â Â Â Get
- Â Â Â Â Â Â Â Return "Zoom In x 0.5 VB.NET"
- Â Â Â Â End Get
- Â Â End Property
- Â
- Â Â Public ReadOnly Property Category() As String
Implements ICommand.Category - Â Â Â Â Get
- Â Â Â Â Â Â Â Return "Developer Samples"
- Â Â Â Â End Get
28- Public ReadOnly Property Enabled() As Boolean
Implements ICommand.Enabled - Â Â Â Â Get
- Â Â Â Â Â Â Â Return m_enabled
- Â Â Â Â End Get
- Â Â End Property
- Â
- Â Â Public ReadOnly Property HelpContextID() As
Integer Implements ICommand.HelpContextID - Â Â Â Â Get
- Â Â Â Â Â Â Â Return 0
- Â Â Â Â End Get
- Â Â End Property
- Â
- Â Â Public ReadOnly Property HelpFile() As String
Implements ICommand.HelpFile - Â Â Â Â Get
- Â Â Â Â Â Â Â
- Â Â Â Â End Get
- Â Â End Property
- Â
- Â Â Public ReadOnly Property Message() As String
Implements ICommand.Message
29Programming in C--a simple walkthrough
- Create a new class library
- Reference the ESRI object libraries
- Create a zoom-in command
- Add a using directive
- Adding code to the members of ICommand
- Returning the ICommandBitmap property
- Expose the ZoomIn class to COM
- Adding COM category registration functions
- Compiling the project
- Use the command in ArcMap
- Stepping through the command with the debugger
30- public class ZoomIn ICommand   private
IApplication m_app private bool m_enabled
private System.Drawing.Bitmap m_bitmap private
IntPtr m_hBitmap - Â Â public void OnCreate(object hook)
- Â Â
- Â Â Â Â if (hook ! null)
- Â Â Â Â
- Â Â Â Â Â Â Â if (hook is IMxApplication)
- Â Â Â Â Â Â Â
- Â Â Â Â Â Â Â Â Â Â m_app (IApplication) hook
- Â Â Â Â Â Â Â Â Â Â m_enabled true
- Â Â Â Â Â Â Â
- Â Â Â Â
- Â Â
31- public void OnClick()
- Â Â
- Â Â Â Â IMxDocument mxDoc (IMxDocument)
m_app.Document - Â Â Â Â IActiveView activeView mxDoc.ActiveView
- Â Â Â Â
- Â Â Â Â IEnvelope currExtent (IEnvelope)
activeView.Extent - Â Â Â Â currExtent.Expand(0.5D, 0.5D, true)
- Â Â Â Â activeView.Extent currExtent
- Â Â Â Â activeView.Refresh()Â Â
- Â Â
- public string Caption
-
- Â Â get
- Â Â
- Â Â Â Â Â Â return "Zoom In x 0.5 C"
- Â Â Â
-
- public string Category
32- public bool Checked
- Â Â
- Â Â Â Â get
- Â Â Â Â
- Â Â Â Â Â Â Â return false
- Â Â Â Â
- Â Â
- Â Â public bool Enabled
- Â Â
- Â Â Â Â get
- Â Â Â Â
- Â Â Â Â Â Â Â return m_enabled
- Â Â Â Â
- Â Â
- Â Â public string Message
- Â Â
- Â Â Â Â get
- Â Â Â Â
- Â Â Â Â Â Â Â return "Zooms the display to half the
current extent."
33(No Transcript)
34Review!
- What is/are ArcObjects?
- A framework
- A collection of component objects
- Fairly useful depending on who you are
- All of the above
- What does COM stand for?
- Corruption of Microsoft
- Communicatiemiddel Oot Maandag
- Component Object Model
- Computer Operating Machinery
35References
- http//edndoc.esri.com/arcobjects/8.3/
- http//en.wikipedia.org/wiki/Component_Object_Mode
l - http//en.wikipedia.org/wiki/Remote_procedure_call
- http//www.songwriting-software.com/images/iMac20
computer.jpg - http//i.cnn.net/cnn/2003/TECH/05/26/your.tech.del
l/story.dellcomputer.jpg