Introduction to Arcobjects
-
Upload
patrick-go -
Category
Documents
-
view
227 -
download
0
Transcript of Introduction to Arcobjects
-
8/16/2019 Introduction to Arcobjects
1/57
-
8/16/2019 Introduction to Arcobjects
2/57
ARCOBJECTS AND THEARCGIS DESKTOP
ArcObjects is the development platform forArc GIS %es!top.
&he Arc GIS %es!top systems each containa con#guration of applications,such as ArcCatalog, Arc Map, Arc &oolbo', and ArcScene, and can host a variety of e'tensionproducts such as ArcGIS SpatialAnalyst,ArcGIS Geostatistical Analyst,ArcGIS (% Analyst and others.
-
8/16/2019 Introduction to Arcobjects
3/57
Arc Map , Arc CatalogArc 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.
-
8/16/2019 Introduction to Arcobjects
4/57
-
8/16/2019 Introduction to Arcobjects
5/57
n erpre ng o ec o e!i#gr#$
Arc Objects object model diagrams are based on the )M*
notation, an industry-diagramming standard for object-
oriented analysis and design.
&he development environment,)isual *asic orother, lists all of the many classes andmembers but does not sho the structure ofthose classes.
&hese diagrams complete yourunderstanding of the Arc Objects components.
-
8/16/2019 Introduction to Arcobjects
6/57
C"#$$e$ #n! object$
+here are types of classes shown in the )M* diagrams
abstract classes, co classes, and classes.
A coclass represents objects that you can directly createusing the object declaration synta$ in your development
environment. #n isual /asic, this is written with the
Dim pFoo As New FooObject synta$.
A class cannot directly create new objects, but objects of
a class can be created as a property of another class or byfunctions from another class. &g. 0eatureCursor
An abstract class cannot be used to create new objects,
but it is a specification for subclasses.&g1 2line3 could be
an abstract class for 2primary line3 and 2secondary line3
-
8/16/2019 Introduction to Arcobjects
7/57
T%pe in&erit#nce Type inheritance de#nes speciali$ed
classes that share properties andmethods ith the super class andhave additional properties and
methods. *ine
'econdary *ine4rimary *ine
&his diagram shos that a primary line +creatableclass and secondary line +creatable class are types
of a line +abstract class.
-
8/16/2019 Introduction to Arcobjects
8/57
In$t#nti#tion
Instantiation speci#es that oneobject from one class has amethod ith hich it creates anobject from another class.
4ole +ransformer
A pole object might have a method to create a transfo
-
8/16/2019 Introduction to Arcobjects
9/57
Customi5ationCustomi5ation
Showing and hiding toolbars using the Customizedialog box
6. Click the +ools menu and click Customi5e.
+he Customi5e dialog bo$ appears.%ou can also double-click any unoccupied areaof any toolbar to display the Customi5e dialog bo$.
7. #f it is not visible, click the +oolbars tab.
+he presence or absence of a check mark ne$t to thetoolbar name indicates its visible state.
. Check and uncheck the check bo$es.
-
8/16/2019 Introduction to Arcobjects
10/57
-
8/16/2019 Introduction to Arcobjects
11/57
-
8/16/2019 Introduction to Arcobjects
12/57
-
8/16/2019 Introduction to Arcobjects
13/57
Removing buttons from a toolbar
Make sure the toolbar you just renamed, My Own+ools, is visible.
#f it is not visible, display the Customi5e dialog
bo$.
:rag some of the commands off the toolbar.
&ven though youve removed the buttons from the
toolbar, they are still available in the Customi5e
dialog bo$.
-
8/16/2019 Introduction to Arcobjects
14/57
ng # en( o #too"b#r
Ma!e sure the My On &ools toolbar is visible. If it is not visible, display the Customi$e dialog
bo'. Clic! the Commands tab and choose the
Menus category from the Categories list onthe left"hand side of the dialog bo'.
In the Commands list at the right"hand side ofthe dialog bo', clic! Selection.
%rag and drop it to the left of the /oom Inbutton on the My On &ools toolbar.
Clic! Close in the Customi$e dialog bo'. Clic! Selection on the My On &ools toolbar
and note the menu that appears.
-
8/16/2019 Introduction to Arcobjects
15/57
#) ng c #nge$ o #tep"#te
%ou 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 0ile menu and click 'ave As. 8avigate to the +emplates folder of the ;installation
directory.m$t"
from the 'ave as type dropdown menu, then click 'ave.
-
8/16/2019 Introduction to Arcobjects
16/57
WRITING MACRS IN !"A
%ou can use the /A integrated development
environment to create macros to help you automate
tasks you perform repeatedly or to e$tend the
applications built-in functionality. 5ith the )isual *asic 6ditor, you can edit
macros, copy macros from one module toanother, rename the modules that store themacros, or rename the macros.
C ti
-
8/16/2019 Introduction to Arcobjects
17/57
Cre#ting # #cro
Click the +ools menu, point to Macros, then click Macros.
#n the Macros dialog, type name in the Macro name te$t
bo$ and click Create.
+he application creates a new module named Module6and stubs in the 'ub procedure.
&nter some code.
'witch back to ArcMap by clicking the 0ile menu,clicking Close, and clicking (eturn to ArcMap.
Click the +ools menu, point to Macros, then click Macros.
'elect the Module1. Name macro and click (un.
-
8/16/2019 Introduction to Arcobjects
18/57
too"b#r Click the +ools menu and click Customi5e.
#n the +oolbars tab, ensure that the toolbar is visible. Click the Commands tab and select the Macros category.
Click the name of project in the 'ave in dropdown menu.
+he commands list to the right of the dialog bo$ lists
4roject.Module6.8ame. :rag the macro name to the toolbar you created.
+he macro appears with a default icon.
+o change its properties, right-click the icon. #n the conte$t menu that appears, click Change /utton
#mage and choose a button from the palette of icons.
Close the Customi5e dialog bo$.
Click the button to run the macro.
C lli b il i C d
-
8/16/2019 Introduction to Arcobjects
19/57
Calling built#in Commands
Calling e$isting commands involves working with the
ArcID module.
)sing the Find method, the code locates the uni?ue
identifier !)#:" of the command in the ArcID module.
'teps
6. Click the +ools menu, point to Macros, then
click isual /asic &ditor.
7. #n the Module1 module, create a 'ub procedure with the following code1
. Add the macro to a toolbar or menu.
@. (un the macro.
-
8/16/2019 Introduction to Arcobjects
20/57
Code for 0ull&$tentCode for 0ull&$tent
'ub 0ull&$tent4lus!"
:im intAns As #nteger
:im p#tem As #Command#tem
ith +his:ocument.Command/ars
'et p#tem B .0ind!Arc#:.4anoomD0ull&$tent"
p#tem.&$ecute
intAns B Msg/o$!2oom to previous e$tentE3, vb%es8o"
#f intAns B vb%es +hen
'et p#tem B .0ind!Arc#:.4anoomDoom+o*ast&$tent/ack"
p#tem.&$ecute
&nd #f
&nd ith
&nd 'ub
-
8/16/2019 Introduction to Arcobjects
21/57
A!!ing co!e *or t&e
-
8/16/2019 Introduction to Arcobjects
22/57
A!!ing co!e *or t&e+IContro"
+he application adds an entry in the Object /o$ for theUIButtonControl and stubs in an event procedure for theUIButtonControl s Click event.
%oull add code to this event to 5oom the display to thee$tents of the dataset.
4rivate 'ub )#/uttonControl6DClick!"
:im p:oc As #M$:ocument
'et p:oc B +his:ocument
p:oc.Activeiew.&$tent Bp:oc.Activeiew.0ull&$te
p:oc.Activeiew.(efresh
&nd 'ub
-
8/16/2019 Introduction to Arcobjects
23/57
A!!ing co!e *or t&e+IContro"
Click the +ools menu, click Customi5e, then clickthe Commands tab.
#n the Customi5e dialog bo$, click the Commands
tab and change the 'ave in dropdown menu to thename of your project or to )ntitled.
#n the Categories list, choose )#Controls and dragthe UIButtonControl you created to a toolbar.
Close the Customi5e dialog bo$. +ry the new command by 5ooming in on the map
and clicking the button.
-
8/16/2019 Introduction to Arcobjects
24/57
Cre#ting # too" in ,BA
7. Clic! the &ools menu and clic! Customi$e.
8. Clic! the Commands tab and change theSave in combo bo' to the name of your
project or 9ntitled. (. Choose 9IControls from the Categories list.
:. Clic! 2e 9IControl.
;. In the dialog bo' that appears, choose9I&oolControl as the 9IControl &ype, then clic!Create and 6dit.
#ng ng ( on
-
8/16/2019 Introduction to Arcobjects
25/57
#ng ng ( onpropertie$
0ight"clic! any toolbar and clic! Customi$ein the conte't menu that appears. Clic!the right mouse button to determinehether a conte't menu is available.
0ight"clic! the button hose propertiesyou ant to change.
In the conte't menu that appears, clic!Change *utton Image and choose animage. &he image you chose appears onthe face of the button.
Close the Customi$e dialog bo'.
-
8/16/2019 Introduction to Arcobjects
26/57
+hank you..
-
8/16/2019 Introduction to Arcobjects
27/57
Arc Objects 4roblem 'olving FuideArc Objects 4roblem 'olving Fuide $%&IN% T'% ARC"(%CTS )RGRAMMING TAS*
7. %escribe the problem in Arc Objects terms.8. Identify subtas!s.
(. %ecide here to rite the code.
:. Search for a related sample or recommended methodology.
-OCATE THE CORRECT OBJECT MODE-
7. Identify a subtas!.
8. 6'tract !eyords.(. Search for the correct object model diagrams.
:. 0evie all related documentation.
NA,IGATE THE OBJECT MODE- DIAGRAM
7. 0evie the structure of the object model diagram.
8. &race the
-
8/16/2019 Introduction to Arcobjects
28/57
riting Code )sing Arc Objectsriting Code )sing Arc Objects
#n general, there are three ways to write Arc Objects
code1
G As a /A macro in an ArcF#' application
G As an ActiveH COM component such as a :** or
OCH
G As a standalone &H&
iti /A i A F#'
-
8/16/2019 Introduction to Arcobjects
29/57
riting /A macros in ArcF#'
AdvantagesAdvantages
= It3s fast and easy to create, test, and debugmacros inside Arc Map and Arc Catalog.
= &he standard 6S0I type libraries are already
referenced.= Important global variables, such as the
Application and Document , are available.
= It3s simple to assemble 9I forms using )*A
and Active> components. = It3s straightforard to integrate )*A code
ith ne Arc Objects 9IControls.
= It3s relatively easy to migrate )*A code to)* Active> %?? projects.
iti A ti H COM t
-
8/16/2019 Introduction to Arcobjects
30/57
riting ActiveH COM components AdvantagesAdvantages
G +hey can be easily delivered to end users via customsetup programs.
G %ou can hide Arc Objects code in a binary file and thendeliver the functionality to end users with a setup program.
G %ou can e$tend and customi5e virtually every aspect ofthe ArcF#' technology.
:isadvantages:isadvantages
G IIave to ac@uire and use another COM"compliant development tool
G %o not have direct access to the Applicationand ThisDocument global variables.
G It is often more dicult to debug the code.
Standalone Applications
-
8/16/2019 Introduction to Arcobjects
31/57
Standalone Applications
AdvantagesAdvantages
G %ou can use the &'(# Arc Objects Map control to simplify theembedding of Arc Objects functionality in your application.
G %ou can design a highly customi5ed user interface specific toyour application.
G %ou can ?uickly create small, lightweight applications. :isadvantages:isadvantages
G %ou cannot take advantage of the e$tensive functionality that&'(# has built into the e$isting ArcF#' applications such as
Arc Map or Arc Catalog.
= 1ou cannot use Arc Map documents or templatesto their fullest capacity.
= 2one of the e'tensions, including the Editor , can
be used.
-
8/16/2019 Introduction to Arcobjects
32/57
Arc Map Core ObjectsArc Map Core Objects
A M :A M :
-
8/16/2019 Introduction to Arcobjects
33/57
Arc Map :ocumentArc Map :ocument
A))+ICATIN CC+ASS
-
8/16/2019 Introduction to Arcobjects
34/57
A))+ICATIN CC+ASS
+he Application object directly manages a collection of
objects, MDocument , AppDispla!,"election#n$ironment . hen you first start Arc Map, the Application object is first
created, and then it in turn instantiates all of the objects itmanages.
+he IApplication interface provides access to the MDocumentobject, the "tatusBar object, the %emplates object, the currentlyselected tool, the isual /asic &ditor.
+he IMApplication interface provides access to the remainderof the objects the Application automatically creates, including
AppDispla!, &aper Co Class, &rinter , and"election#n$ironment . Additionally, IMApplication e$posesmethods for e$porting the current map document or copying itto the system clipboard.
-
8/16/2019 Introduction to Arcobjects
35/57
-
8/16/2019 Introduction to Arcobjects
36/57
M,$C-M%NT CC+ASS
+he Arc Map document is called MDocument J its role
is to control the representation of data.
+he Arc Map application automatically creates this
object when the application first starts. MDocument specifically creates and manages the
following objects1 an empty Map, a &a'e(a!out , the
%OCCatalo')iew, the %OCDispla!)iew.
%ou can obtain a reference to the MDocument through
IApplication**Document .
-
8/16/2019 Introduction to Arcobjects
37/57
iewsiews
iew 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 IActi$e)iew interface to establish themselves as views.
&he data vie corresponds to a Map object, and the layoutvie corresponds to the PageLayout object.
6ither of these objects can be set as the document3s activevie, and only one vie is visible at a time.
-
8/16/2019 Introduction to Arcobjects
38/57
Checking +ype of iewChecking +ype of iew
&he folloing )*A code chec!s the type of activevieB
%im pM'%oc As IM'%ocument
Set pM'%oc Application.%ocumentIf &ypeOf pM'%oc.Active)ie Is IMap &hen
Msg*o' DActive )ie is a MapD
6lseIf &ypeOf pM'%oc.Active)ie Is I-age?ayout &he
Msg*o' DActive vie is the -age?ayoutD
6nd If
li i i
-
8/16/2019 Introduction to Arcobjects
39/57
Application 6'tensions
+he Application object directly manages the life ofall application e$tensions.
Application e$tensions are those e$tensions
registered in the &'(# M#tension objectsJ All e$tensions are automatically created and
destroyed in synchroni5ation with an Applicationobject.
)se the I#tension interface to ?uery the properties of an e$tension or implement thisinterface to create your own custom e$tension.
-
8/16/2019 Introduction to Arcobjects
40/57
TC$IS)+A.!I%W AN$
-
8/16/2019 Introduction to Arcobjects
41/57
TC$IS)+A.!I%W AN$
TCCNT%NTS!I%W CC+ASS%S
Contents vies are tabs in the Arc Maptable of contents.
ArcMap ships ith to contents viesB
display vie and source vie. &he %isplay tab is the TOCDisplayView
object, and the Source tab is theTOCCatalogView object.
%evelopers can add ne contents viesby creating their on custom object thatimplements the IContentsView interface.
-
8/16/2019 Introduction to Arcobjects
42/57
MA) CC+ASS
6very map document contains at least one Mapobject.
Only one Map can have focus at a time, and thisMap is called the focus map.
IMxDocument provides access to all of the Mapobjects loaded in the documentF
IMxDocument!ocusMap returns a reference to theMap currently ith focus, and IMxDocument"Maps
returns the entire collection of Map objects. Map#urround objects are elements that are related
to a Map. &ypes of map surrounds include Legends$%orthArrows$ and #cale&ars.
-
8/16/2019 Introduction to Arcobjects
43/57
S%+%CTIN%N!IRNM%NT CC+ASS
Controls properties related to creating and drawing
selections.
A "election#n$ironment object is automatically created
by the Application object when the application starts. Access to the Application objects
"election#n$ironment is through
IMApplication**"election#n$ironment .
-
8/16/2019 Introduction to Arcobjects
44/57
Change :efault 'election Color Change :efault 'election Color
-ublic Sub Change%efaultSelectionColor+%im pM'%oc As IM'%ocument
%im pM'App As IM'Application
%im pSelection6nv As ISelection6nvironment
%im p0gbColor As I0gbColorSet pM'App Application HI
Set pM'%oc Application.%ocument
Set pSelection6nv
pM'App.Selection6nvironmentSet p0gbColor 2e 0gbColor
p0gbColor.0ed 8;;
Set pSelection6nv.%efaultColor p0gbColor
6nd Sub
:isplay Objects:isplay Objects
-
8/16/2019 Introduction to Arcobjects
45/57
:isplay Objects:isplay Objects&%AT-R% R%N$%R%R
A feature renderer is a method for drawing feature layers.
)se symbols and colors to visually display features, possibly based on one ormore attributes.
+ypes of feature renderers1
G "imple+enderer uses the same symbol for each feature.
G ClassBreaks+enderer allows classes of numeric attribute values to be defineA different symbol is specified for each class.
G Uni,ue)alue+enderer uses a different symbol for each uni?ue attribute valu
G &roportional"!mbol+enderer modifies the si5e of the symbol in proportion tan attribute from a field.
G DotDensit!+enderer displays a scattering of marker symbols in polygonfeatures, the density of which reflects the value of an attribute.
G C-art+enderer displays pie, bar, or stacked bar charts that are comprised froone or more attribute fields.
G "caleBreaks+enderer switches renderers depending on the map viewing scal
-
8/16/2019 Introduction to Arcobjects
46/57
Fet a 0eature (enderer Fet a 0eature (enderer
+o get to a feature renderer object in Arc Map from a layer, I to I/eoFeature(a!er and get the +enderer property.
A simple renderer is the default renderer objecthen a ne feature class is loaded.
K Check if the layer is a feature layer #f 8ot +ypeOf p*ayer #s #Feo0eature*ayer +hen &$it 'ub
'et pFeo0eature*ayer B p*ayer
Chec! if there is a simple renderer and get a reference to itIf 2ot &ypeOf pGeoEeature?ayer.0enderer Is ISimple0enderer
&hen 6'it Sub
Set pSimple0enderer pGeoEeature?ayer.0enderer
-
8/16/2019 Introduction to Arcobjects
47/57
Color ObjectsColor Objects
Objects that support the IColor interface allow precise controlover any color used within the ArcObjects model.
%ou can get and set colors using a variety of standard colormodels(F/, CM%9, I', I*', and Frayscale.
RGBCOLOR CC+ASS
+o get and set the red,green, and blue components of a color
#nterface- #(F/Color
CMYKCOLOR CC+ASS
Colors can be speci#ed for output in terms ofCyan$ Magenta$ 'ellow$ and &lac( .
Interface" ICM14Color
' b l Obj' b l Obj t
-
8/16/2019 Introduction to Arcobjects
48/57
'ymbol Objects'ymbol Objects
-
8/16/2019 Introduction to Arcobjects
49/57
+ypes of 'ymbols+ypes of 'ymbols
ArcObjects uses three categories of symbols to draw
geographic features1
Marker symbols,
*ine symbols,
0ill symbols.
i l Obj:i l Obj
-
8/16/2019 Introduction to Arcobjects
50/57
:isplay Objects:isplay Objects
-
8/16/2019 Introduction to Arcobjects
51/57
:isplay Objects:isplay 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 e$port files. )se the IDispla! interface to draw points, lines,
polygons, rectangles,and te$t on a device.
Access to the display objects Displa!%rans0ormation
object is provided by this interface.
+ 4 M :i l+ 4 M :i l
-
8/16/2019 Introduction to Arcobjects
52/57
+o 4an Map :isplay+o 4an Map :isplay
4rivate 'ub )#+oolControl6DMouse:own!/yal button As*ong, D/yal shift As *ong, /yal $ As *ong, /yal yAs *ong"
:im p'creen:isplay As #'creen:isplay
:im pActiveiew As #Activeiew
:im pM$:oc As #M$:ocument
'et pM$:oc B Application.:ocument
'et pActiveiew B pM$:oc.0ocusMap
'et p'creen:isplay B pActiveiew.'creen:isplay
p'creen:isplay.+rack4an
&nd 'ub
-
8/16/2019 Introduction to Arcobjects
53/57
$IS)+A.TRANS&RMATIN CC+ASS
Manages the map-to-device transformation
:efines how real-world coordinates are mapped to an
output space.
Maps Displa!%rans0ormation has a "patial+e0erence
object that manages the Maps current coordinate system.
A reference to the #patial)e*erence object is set
throughIDisplayTrans*ormation#patial)e*erence .
IDisplayTrans*ormation
-
8/16/2019 Introduction to Arcobjects
54/57
IDisplayTrans*ormation
&o prepare a transform for use, follo thesestepsB
7. Set the full map e'tent ith the &ounds
property.8. Set the visible map e'tent +$oom
rectangle ith the Visi+le&ounds property.
(. Set the output area of the device using the
De,ice!rame property.:. Set the resolution of the output device
using the )esolution property.
-
8/16/2019 Introduction to Arcobjects
55/57
(ubber /and Objects(ubber /and Objects
-
8/16/2019 Introduction to Arcobjects
56/57
#(ubber/and #nterface#(ubber/and #nterface
I+ubberBand interface, allow the user to digiti5e geometrieson the display using the mouseeither to create whole newgeometry objects or to update e$isting ones.
&$amples-:ragging an envelope, forming a new polyline, ormoving a point.
I)u++er+and interface has to methods Trac(Existing
Move e'isting geometries Trac(%ew
Create ne geometries
Trac(%ew method
-
8/16/2019 Introduction to Arcobjects
57/57
Trac(%ew methodrivate Sub 9I&oolControl7Mouse%on+*y)al button As
?ong, y)al shift As ?ong, *y)al ' As ?ong, *y)al y As ?ong
im p0ubber?ine As I0ubber*and
im pGeom As IGeometry
im pM>%oc As IM'%ocumentet pM>%oc &his%ocument
et p0ubber?ine 2e 0ubber?ine
et pGeomp0ubber?ine.&rac!2e
pM>%oc.Active)ie.Screen%isplay, 2othingnd Sub