Title: Arc Objects
1Arc Objects
- Arc Objects is the development platform for the
ArcGIS family of applications such as Arc Map,
Arc Catalog, and Arc Scene. - Arc Objects is a framework that lets you create
domain-specific components from other components. - Arc Objects provides an infrastructure for
- application customization that lets you
concentrate on serving the specific needs of your
clients.
2ARCOBJECTS AND THE ARCGIS DESKTOP
- ArcObjects is the development platform for Arc
GIS Desktop. - The Arc GIS Desktop systems each contain a
configuration of applications,such as Arc
Catalog, Arc Map, Arc Toolbox, and Arc Scene, and
can host a variety of extension products such as
ArcGIS Spatial Analyst,ArcGIS Geostatistical
Analyst, ArcGIS 3D Analyst and others.
3Arc Map , Arc Catalog
- Arc Map is used for mapping and editing tasks as
well as map-based analysis. - Arc Catalog is used for managing your spatial
- data holdings, defining your geographic data
- custom schemas, and recording and viewing
metadata.
4ARCOBJECTS FRAMEWORK
- Arc Objects is built using Microsofts Component
Object Model (COM) technology. - It is possible to extend Arc Objects by writing
COM components using any COM-compliant
development language. - You can extend every part of the Arc Objects
architecture in exactly the same way as ESRI
developers do.
5Interpreting object model diagrams
- Arc Objects object model diagrams are based on
the UML notation, an industry-diagramming
standard for object-oriented analysis and design. - The development environment,Visual Basic or
other, lists all of the many classes and members
but does not show the structure of those classes. - These diagrams complete your understanding of
the Arc Objects components.
6Classes and objects
- There are 3 types of classes shown in the UML
diagrams - abstract classes, co classes, and classes.
- A coclass represents objects that you can
directly create using the object declaration
syntax in your development environment. In Visual
Basic, this is written with the - Dim pFoo As New FooObject syntax.
- A class cannot directly create new objects, but
objects of a class can be created as a property
of another class or by functions from another
class. Eg. FeatureCursor - An abstract class cannot be used to create new
objects, but it is a specification for
subclasses.Eg line could be an abstract class
for primary line and secondary line
7Type inheritance
- Type inheritance defines specialized classes that
share properties and methods with the super class
and have additional properties and methods.
Line
Primary Line
Secondary Line
This diagram shows that a primary line (creatable
class) and secondary line (creatable class) are
types of a line (abstract class).
8Instantiation
- Instantiation specifies that one object from one
class has a method with which it creates an
object from another class.
Pole
Transformer
A pole object might have a method to create a
transformer object.
9Customization
- Showing and hiding toolbars using the Customize
dialog box - 1. Click the Tools menu and click Customize.
- The Customize dialog box appears.
- You can also double-click any unoccupied area
of any toolbar to display the Customize dialog
box. - 2. If it is not visible, click the Toolbars
tab. - The presence or absence of a check mark next
to the toolbar name indicates its visible
state. - 3. Check and uncheck the check boxes.
10Creating a new toolbar
- In the Toolbars tab of the Customize dialog box,
click New. - In the dialog box that appears, specify Chapter
One Examples as the name of the new toolbar or
use the default setting. - Store the toolbar in the document by changing the
name of the Save in dropdown list from Normal.mxt
to Untitled or the name of the current project. - Click OK.
- The newly created toolbar appears near the top of
the application window.
11Adding buttons to a toolbar
- Make sure the toolbar you just created is
visible. - If it is not visible, display the Customize
dialog box. - Click the Commands tab of the Customize dialog
box. - Select the Pan/Zoom category from the Categories
list. - Scroll to the bottom of the Commands list.
- Select the Zoom in command and drag it to the
toolbar. Release the command when the arrow
cursor with a small box below it appears. - Continue adding commands from the Pan/Zoom
category - You may switch to other categories to select
commands. - Resize the toolbar so that its width allows the
display of two commands per row. - Note that you can dock the toolbar or drag it to
any of the toolbar drop sites on the application
window.
12Renaming a toolbar
- In the Toolbars tab, click the name of the
toolbar whose name you want to change. - Click the Rename button.
- In the dialog box that appears, specify My Own
Tools as the new name. - Note that you can only rename toolbars youve
created. - Click OK.
- If you decide not to rename the toolbar, click
Cancel.
13Removing buttons from a toolbar
- Make sure the toolbar you just renamed, My Own
Tools, is visible. - If it is not visible, display the Customize
dialog box. - Drag some of the commands off the toolbar.
- Even though youve removed the buttons from the
toolbar, they are still available in the
Customize dialog box.
14Adding a menu to a toolbar
- Make sure the My Own Tools toolbar is visible.
- If it is not visible, display the Customize
dialog box. - Click the Commands tab and choose the Menus
category from the Categories list on the
left-hand side of the dialog box. - In the Commands list at the right-hand side of
the dialog box, click Selection. - Drag and drop it to the left of the Zoom In
button on the My Own Tools toolbar. - Click Close in the Customize dialog box.
- Click Selection on the My Own Tools toolbar and
note the menu that appears.
15Saving changes to a template
- You can save your work to a document or template.
Changes saved to a document are specific to the
document, whereas changes saved to a template
will be reflected in all documents based on the
template. - Click the File menu and click Save As.
- Navigate to the Templates folder of the
ltinstallation directorygt\bin folder. - Click the Create New Folder button.
- Type a new name for the folder and double-click
it. - Type the template name, click ArcMap Templates
(.mxt) from the Save as type dropdown menu, then
click Save.
16WRITING MACROS IN VBA
- You can use the VBA integrated development
environment to create macros to help you automate
tasks you perform repeatedly or to extend the
applications built-in functionality. - With the Visual Basic Editor, you can edit
macros, copy macros from one module to another,
rename the modules that store the macros, or
rename the macros.
17Creating a macro
- Click the Tools menu, point to Macros, then click
Macros. - In the Macros dialog, type name in the Macro
name text box and click Create. - The application creates a new module named
Module1 and stubs in the Sub procedure. - Enter some code.
- Switch back to ArcMap by clicking the File menu,
clicking Close, and clicking Return to ArcMap. - Click the Tools menu, point to Macros, then click
Macros. - Select the Module1. Name macro and click Run.
18Adding a macro to a toolbar
- Click the Tools menu and click Customize.
- In the Toolbars tab, ensure that the toolbar is
visible. - Click the Commands tab and select the Macros
category. - Click the name of project in the Save in
dropdown menu. - The commands list to the right of the dialog box
lists Project.Module1.Name. - Drag the macro name to the toolbar you created.
- The macro appears with a default icon.
- To change its properties, right-click the icon.
- In the context menu that appears, click Change
Button Image and choose a button from the palette
of icons. - Close the Customize dialog box.
- Click the button to run the macro.
19Calling built-in Commands
- Calling existing commands involves working with
the ArcID module. - Using the Find method, the code locates the
unique identifier (UID) of the command in the
ArcID module. - Steps
- 1. Click the Tools menu, point to Macros, then
click Visual Basic Editor. - 2. In the Module1 module, create a Sub
procedure with the following code - 3. Add the macro to a toolbar or menu.
- 4. Run the macro.
20Code for FullExtent
- Sub FullExtentPlus()
- Dim intAns As Integer
- Dim pItem As ICommandItem
- With ThisDocument.CommandBars
- Set pItem .Find(ArcID.PanZoom_FullExtent)
- pItem.Execute
- intAns MsgBox(Zoom to previous extent?,
vbYesNo) - If intAns vbYes Then
- Set pItem .Find(ArcID.PanZoom_ZoomToLastExten
tBack) - pItem.Execute
- End If
- End With
- End Sub
21Creating a Command in VBA
- Once invoked, a command usually performs some
direct action without user intervention. - A command is a type of UIControl.
- Click the Tools menu and click Customize.
- In the Customize dialog box, click the Commands
tab and change the Save in dropdown menu to the
name of your project or to Untitled. - In the Categories list, select UIControls.
- Click New UIControl.
- In the dialog box that appears, choose
UIButtonControl as the UIControl Type, then click
Create and Edit.
22Adding code for the UIControl
- The application adds an entry in the Object Box
for the UIButtonControl and stubs in an event
procedure for the UIButtonControls Click event. - Youll add code to this event to zoom the display
to the extents of the dataset. - Private Sub UIButtonControl1_Click()
- Dim pDoc As IMxDocument
- Set pDoc ThisDocument
- pDoc.ActiveView.Extent pDoc.ActiveView.FullExten
t - pDoc.ActiveView.Refresh
- End Sub
23Adding code for the UIControl
- Click the Tools menu, click Customize, then click
the Commands tab. - In the Customize dialog box, click the Commands
tab and change the Save in dropdown menu to the
name of your project or to Untitled. - In the Categories list, choose UIControls and
drag the UIButtonControl you created to a
toolbar. Close the Customize dialog box. - Try the new command by zooming in on the map and
clicking the button.
24Creating a tool in VBA
- 1. Click the Tools menu and click Customize.
- 2. Click the Commands tab and change the Save in
combo box to the name of your project or
Untitled. - 3. Choose UIControls from the Categories list.
- 4. Click New UIControl.
- 5. In the dialog box that appears, choose
UIToolControl as the UIControl Type, then click
Create and Edit.
25Changing button properties
- Right-click any toolbar and click Customize in
the context menu that appears. Click the right
mouse button to determine whether a context menu
is available. - Right-click the button whose properties you want
to change. - In the context menu that appears, click Change
Button Image and choose an image. The image you
chose appears on the face of the button. - Close the Customize dialog box.
26Thank you..
27Arc Objects Problem Solving Guide
- DEFINE THE ARCOBJECTS PROGRAMMING TASK
- 1. Describe the problem in Arc Objects terms.
- 2. Identify subtasks.
- 3. Decide where to write the code.
- 4. Search for a related sample or recommended
methodology. - LOCATE THE CORRECT OBJECT MODEL
- 1. Identify a subtask.
- 2. Extract keywords.
- 3. Search for the correct object model diagrams.
- 4. Review all related documentation.
- NAVIGATE THE OBJECT MODEL DIAGRAM
- 1. Review the structure of the object model
diagram. - 2. Trace the flow between classes and assemble
code. -
28Writing Code Using Arc Objects
- In general, there are three ways to write Arc
Objects code - As a VBA macro in an ArcGIS application
- As an ActiveX COM component such as a DLL or
OCX - As a standalone EXE
29Writing VBA macros in ArcGIS
- Advantages
- Its fast and easy to create, test, and debug
macros inside Arc Map and Arc Catalog. - The standard ESRI type libraries are already
referenced. - Important global variables, such as the
Application and Document, are available. - Its simple to assemble UI forms using VBA
and ActiveX components. - Its straightforward to integrate VBA code
with new Arc Objects UIControls. - Its relatively easy to migrate VBA code to
VB ActiveX DLL projects.
30Writing ActiveX COM components
- Advantages
- They can be easily delivered to end users via
custom setup programs. - You can hide Arc Objects code in a binary file
and then deliver the functionality to end users
with a setup program. - You can extend and customize virtually every
aspect of the ArcGIS technology. - Disadvantages
- Have to acquire and use another COM-compliant
development tool - Do not have direct access to the Application
and ThisDocument global variables. - It is often more difficult to debug the code.
-
31Standalone Applications
- Advantages
- You can use the ESRI Arc Objects Map control
to simplify the embedding of Arc Objects
functionality in your application. - You can design a highly customized user
interface specific to your application. - You can quickly create small, lightweight
applications. - Disadvantages
- You cannot take advantage of the extensive
functionality that ESRI has built into the
existing ArcGIS applications such as Arc Map or
Arc Catalog. - You cannot use Arc Map documents or templates
to their fullest capacity. - None of the extensions, including the Editor,
can be used.
32Arc Map Core Objects
33Arc Map Document
34APPLICATION COCLASS
- The Application object directly manages a
collection of objects, MxDocument,
AppDisplay,SelectionEnvironment. - When you first start Arc Map, the Application
object is first created, and then it in turn
instantiates all of the objects it manages. - The IApplication interface provides access to the
MxDocument object, the StatusBar object, the
Templates object, the currently selected tool,
the Visual Basic Editor. - The IMxApplication interface provides access to
the remainder of the objects the Application
automatically creates, including AppDisplay,Paper
Co Class, Printer, and SelectionEnvironment.
Additionally, IMxApplication exposes methods for
exporting the current map document or copying it
to the system clipboard.
35(No Transcript)
36MXDOCUMENT COCLASS
- The Arc Map document is called MxDocument its
role is to control the representation of data. - The Arc Map application automatically creates
this object when the application first starts. - MxDocument specifically creates and manages the
following objects an empty Map, a PageLayout,
the TOCCatalogView, the TOCDisplayView. - You can obtain a reference to the MxDocument
through IApplicationDocument.
37Views
- View is the main application window, or the place
where all data is drawn. - Arc Map currently has two different views,data
view and layout view - Objects implement the IActiveView interface to
establish themselves as views. - The data view corresponds to a Map object, and
the layout view corresponds to the PageLayout
object. - Either of these objects can be set as the
documents active view, and only one view is
visible at a time. -
38Checking Type of View
- The following VBA code checks the type of active
view - Dim pMxDoc As IMxDocument
- Set pMxDoc Application.Document
- If TypeOf pMxDoc.ActiveView Is IMap Then
- MsgBox "Active View is a Map"
- ElseIf TypeOf pMxDoc.ActiveView Is IPageLayout
Then - MsgBox "Active view is the PageLayout"
- End If
39Application Extensions
- The Application object directly manages the life
of all application extensions. - Application extensions are those extensions
registered in the ESRI MxExtension objects - All extensions are automatically created and
destroyed in synchronization with an Application
object. - Use the IExtension interface to query the
properties of an extension or implement this
interface to create your own custom extension.
40Getting Reference to an Extension
- Public Sub CheckEditState()
- Dim pEditor As IEditor
- Dim pUID As New UID
- pUID "esriCore.Editor"
- Set pEditor Application.FindExtensionByCLSID(pU
ID) - If pEditor.EditState esriStateEditing Then
- MsgBox "Active Edit Session Present"
- End If
- End Sub
41TOCDISPLAYVIEW AND TOCCONTENTSVIEW COCLASSES
- Contents views are tabs in the Arc Map table of
contents. - ArcMap ships with two contents views display
view and source view. - The Display tab is the TOCDisplayView object, and
the Source tab is the TOCCatalogView object. - Developers can add new contents views by
creating their own custom object that implements
the IContentsView interface.
42MAP COCLASS
- Every map document contains at least one Map
object. - Only one Map can have focus at a time, and this
Map is called the focus map. - IMxDocument provides access to all of the Map
objects loaded in the document - IMxDocumentFocusMap returns a reference to the
Map currently with focus, and IMxDocument.Maps
returns the entire collection of Map objects. - MapSurround objects are elements that are related
to a Map. Types of map surrounds include Legends,
NorthArrows, and ScaleBars.
43SELECTIONENVIRONMENT COCLASS
- Controls properties related to creating and
drawing selections. - A SelectionEnvironment object is automatically
created by the Application object when the
application starts. - Access to the Application objects
SelectionEnvironment is through
IMxApplicationSelectionEnvironment.
44Change Default Selection Color
- Public Sub ChangeDefaultSelectionColor()
- Dim pMxDoc As IMxDocument
- Dim pMxApp As IMxApplication
- Dim pSelectionEnv As ISelectionEnvironment
- Dim pRgbColor As IRgbColor
- Set pMxApp Application 'QI
- Set pMxDoc Application.Document
- Set pSelectionEnv pMxApp.SelectionEnvironment
- Set pRgbColor New RgbColor
- pRgbColor.Red 255
- Set pSelectionEnv.DefaultColor pRgbColor
- End Sub
45Display Objects
- FEATURE RENDERER
- A feature renderer is a method for drawing
feature layers. - Use symbols and colors to visually display
features, possibly based on one or more
attributes. - Types of feature renderers
- SimpleRenderer uses the same symbol for each
feature. - ClassBreaksRenderer allows classes of numeric
attribute values to be defined. A different
symbol is specified for each class. - UniqueValueRenderer uses a different symbol
for each unique attribute value. - ProportionalSymbolRenderer modifies the size
of the symbol in proportion to an attribute from
a field. - DotDensityRenderer displays a scattering of
marker symbols in polygon features, the density
of which reflects the value of an attribute. - ChartRenderer displays pie, bar, or stacked
bar charts that are comprised from one or more
attribute fields. - ScaleBreaksRenderer switches renderers
depending on the map viewing scale.
46Get a Feature Renderer
- To get to a feature renderer object in Arc Map
from a layer, QI to IGeoFeatureLayer and get the
Renderer property. - A simple renderer is the default renderer object
when a new feature class is loaded. - ' Check if the layer is a feature layer
- If Not TypeOf pLayer Is IGeoFeatureLayer Then
Exit Sub - Set pGeoFeatureLayer pLayer
- ' Check if there is a simple renderer and get a
reference to it - If Not TypeOf pGeoFeatureLayer.Renderer Is
ISimpleRenderer Then Exit Sub - Set pSimpleRenderer pGeoFeatureLayer.Renderer
47Color Objects
- Objects that support the IColor interface allow
precise control over any color used within the
ArcObjects model. - You can get and set colors using a variety of
standard color modelsRGB, CMYK, HSV, HLS, and
Grayscale. - RGBCOLOR COCLASS
- To get and set the red,green, and blue
components of a color - Interface- IRGBColor
- CMYKCOLOR COCLASS
- Colors can be specified for output in terms of
Cyan, Magenta, Yellow, and Black. - Interface- ICMYKColor
48Symbol Objects
49Types of Symbols
- ArcObjects uses three categories of symbols to
draw geographic features - Marker symbols,
- Line symbols,
- Fill symbols.
50Display Objects
51Display Objects
- Allow application developers to easily draw
graphics on a variety of output devices. - Allow you to render shapes stored in real-world
coordinates to the screen, the printer, and
export files. - Use the IDisplay interface to draw points, lines,
polygons, rectangles,and text on a device. - Access to the display objects DisplayTransformati
on object is provided by this interface.
52To Pan Map Display
- Private Sub UIToolControl1_MouseDown(ByVal button
As Long, _ByVal shift As Long, ByVal x As Long,
ByVal y As Long) - Dim pScreenDisplay As IScreenDisplay
- Dim pActiveView As IActiveView
- Dim pMxDoc As IMxDocument
- Set pMxDoc Application.Document
- Set pActiveView pMxDoc.FocusMap
- Set pScreenDisplay pActiveView.ScreenDisplay
- pScreenDisplay.TrackPan
- End Sub
53DISPLAYTRANSFORMATION COCLASS
- Manages the map-to-device transformation
- Defines how real-world coordinates are mapped to
an output space. - Maps DisplayTransformation has a
SpatialReference - object that manages the Maps current coordinate
system. - A reference to the SpatialReference object is set
through IDisplayTransformationSpatialReference.
54IDisplayTransformation
- To prepare a transform for use, follow these
steps - 1. Set the full map extent with the Bounds
property. - 2. Set the visible map extent (zoom rectangle)
with the VisibleBounds property. - 3. Set the output area of the device using the
DeviceFrame property. - 4. Set the resolution of the output device using
the Resolution property.
55Rubber Band Objects
56IRubberBand Interface
- IRubberBand interface, allow the user to digitize
geometries on the display using the mouseeither
to create whole new geometry objects or to update
existing ones. - Examples-Dragging an envelope, forming a new
polyline, or moving a point. - IRubberband interface has two methods
- TrackExisting
- Move existing geometries
- TrackNew
- Create new geometries
57TrackNew method
- Private Sub UIToolControl1_MouseDown(ByVal button
As Long, _ - ByVal shift As Long, ByVal x As Long, ByVal y As
Long) - Dim pRubberLine As IRubberBand
- Dim pGeom As IGeometry
- Dim pMXDoc As IMxDocument
- Set pMXDoc ThisDocument
- Set pRubberLine New RubberLine
- Set pGeompRubberLine.TrackNew
- (pMXDoc.ActiveView.ScreenDisplay, Nothing)
- End Sub