Beruflich Dokumente
Kultur Dokumente
Introduction to ArcObjects
Content
1. Introduction to ArcObjects ................................................................................................... 3
1.1. Using VBA objects ........................................................................................................ 4
1.1.1. Designing a form .................................................................................................... 5
1.1.2. Setting form and control properties ........................................................................ 8
1.1.3. Writing code ........................................................................................................... 9
1.1.4. Run the form ........................................................................................................... 11
1.1.5. Further development .............................................................................................. 13
1.2. Use of ArcObjects ......................................................................................................... 14
1.2.1. Import a shapefile ................................................................................................... 15
1.2.2. Buffer and Data Export ........................................................................................... 18
1.3. Glossary ........................................................................................................................ 19
1. Introduction to ArcObjects
This tutotial gives a general outlook on the development environment created by ESRI in ArcGIS
using Visual Basic for Application.
The following text is based on the ESRI-Course "ArcObjects for beginners".
Learning Objectives
• Visual Basic for Applications
• Using ArcGIS objects
1.1. Overview
Visual Basic is a high level programming language evolved from the earlier DOS version called
BASIC 1. It is a fairly easy programming language to learn. Visual Basic is a visual and events
driven Programming Language.
The VBA development environment consists of two primary tools:
• The Customize dialog box for interactively modifying the user interface.
The Customize dialog box is a powerful tool tha allows you to customize ArcMap and
ArcCatalog without writing a single line of code. You can create, add, move, and remove
toolbars and commands, and even add tools others have created.
• The Visual Basic Editor for creating user forms and for writing and debugging the code.
1
Beginners' All-purpose Symbolic Instruction Code
After creating the form, you will test your application in an ArcMap document.
Settings
In the ArcMap and ArcCatalog Customize dialog box, you will find utilities for adding new toobars,
menus, and commands to the user interface. The Customize dialog box contains all ArcMap and
ArcCatalg commands. These commands are available on the Commands tab and are organized
into categories.
Only pictures can be viewed in the PDF version! For flashes etc. see the online
version. Only screenshots of animations are displayed.
Costumizations can be stored in the current map document (*.mxd). Costumizations stored in the
map are available only in that particular document. If you want to load your costumizations every
time you use ArcMap, store the costumizations in the normal template (normal.mxt).
The Visual Basic Project Editor window organizes all code written for a particular ArcMap
document or for the ArcCatalog application.
Use the Project Explorer to access all available Visual Basic programs.
Projects are like root directories that organize several subfolders of code documents within the
Project Explorer. In ArcMap, the projects define the level of customization for code you write
(Normal -vs- current document).
A Module is simply a document that contains code.
UserForm modules are code modules associated with a form (dialog). In the Visual Basic Editor,
you can design a form by adding and rearranging controls (CommandButtons, TextBoxes,
OptionButtons, etc.) and setting their properties. After the form is designed, you can write code in
the associated form code module to make the controls work.
After the desired controls have been added to the form, position them so they are intuitive for the
user to work with.
• Dim ension a variable dblBBE as double and assign it the value 169028.66 (Lat. Bern)
• Dim ension a variable dblLBE as double and assign it the value 26782.5 (Long. Bern)
To create a variable, you can declare it. Declaring a variable accomplishes two things:
1. It specifies the name for your variable
2. It defines the type of data to be stored in the variable
Although it is not technically required, it is good programming technique to declare all variables
before you use them.
Remember that controls are Visual Basic objects, and the syntax for working with object properties
is Objects.Property
In the example above, the value entered by the users is referenced using the TextBox control's
Text property (e.g. TXT1.Value)
• Calculate the coordinates transformation (WGS -> CH) with the following formula:
TXT7.Text = 600072.37 + 211455.93 * dblL - 10938.51 * dblL *
dblB - 0.36 * dblL * dblB * dblB - 44.54 * dblL * dblL * dblL
TXT8.Text= 200147.07 + 308807.95 * dblB + 3745.25 * dblL * dblL
+ 76.63 * dblB * dblB - 194.56 * dblL * dblL * dblB + 119.79 *
dblB * dblB * dblB
Once the your code is debbuged and runs properly, you can test the regularity of the conversion
using following data.
WGS coordinates CH03 coordinates
Lat: 46° 2' 38.87" Easting: 699 999.76 m
Long: 8° 43' 49.79" Nothing: 99 999.97 m
While the Customize dialog box is open, the user interface is in design mode, which allows you to
change the properties of your new Button
In a similar way as you did to add code to your form, you can edit the code for your button, which
will open your form.
1.2. Overview
ArcGIS objects are saved in libraries and usable through ArcObjects, which is the development
platform for the ArcGIS family for applications such as ArcMap, ArcCatalog etc. The ArcObjects
software components expose the full range of functionality available in ArcInfo and ArcView to
software developers. The ArcObjects components collaborate to serve every data management
and map presentation function common to most GIS applications.
Writing application programs for ArcGIS requires knowledge of both:
• VBA which provides the programming language
• ArcObjects which provide objects and their build-in properties and methodes.
In this Chapter you will learn how to work with VBA and ArcObjects. You will learn the basics of
working with maps and layers in ArcMap using ArcObjects. You will create 3 BUTTONS and code
different procedures associated to them.
Learning Objectives
• Program a tool used to import a shapefile as a new layer in an ArcMap document.
• Develope a tool used to create graphic buffers around polygons.
• Implement a tool to export the active view as an image.
Only pictures can be viewed in the PDF version! For flashes etc. see the online
version. Only screenshots of animations are displayed.
• All code powering your UIControls will be written with the Visual Basic Editor in the
ThisDocument code module
• Using the given printed document, write your code in the "CLICK EVENT" of your new
button
The objects discussed in this exercise can be found on two separate Object Model Diagrams:
• Geodatabase and DataSourcesFile which provide the programming API for the geodatabase
and for file-based data sources
• Carto which supports the creation and display of maps
Always use the Object Browser (F2) to check the unknown commands and/or viste the ESRI
Developer Network (EDN).
Step 3: Test the button
As you can notice the program adds a shapefile to the Data Frame "Layers" but without assigning
it a name. In Step 4 you will find out what is still missing in your code.
Step 4: Explore object models
You will now explore through EDN the two Object Model Diagrams used for your button coding.
The Carto library contains the objects for displaying data. The PageLayout and Map objects are in
this library along map layers, renders for all the supported data types.
• Using the search tool look for the IMap and the IFeatureLayer
• Give a name to the Data Frame (pMap) of your map
• Give a name to the shapefile (pFeatureLayer) that you added to the project
The next paragraphs show the implementation of two typical GIS-fuctions getting support from the
script collections available on the EDN site.
Buffer
Now you will search for a sample that creates buffers around polygons.
• Always on EDN, search in the category Code Exchange for Buffer Features and
Create Graphic Elements
• Add a new button to the ArcMap toolbar named BufferPoly
• Copy the code from the EDN site in the "CLICK EVENT" of the button
• Test the button
Data export
Now you will search for a sample that exports the active view to an image.
1.3. Glossary
BASIC:
B eginners' A ll-purpose S ymbolic I nstruction C ode