Title: GIS Programming
1GIS Programming
- Why Do We Want to Program GIS?
- AML ARC Macro Language
- ArcObject, VBA, COM and Custom Interfaces
2Why Do We Want to Program GIS
- Automate repetitive tasks
- To present a custom interface for users
- Document work
- Maintain Consistency
3AML ARC Macro Language
- Most often used for scripting repetitive tasks.
It is possible to create a custom interface but
this is now easier with ArcObjects. - It is the command line scripting environment
- It is an interpreted language that can be very
slow. Looping is exceptionally slow. Slow for a
computer is still much faster than I can type.
4AML Directive
- AML Directives Begin with an
- system Runs an OS Command
- type Types output
- do Starts a loop of block of code
- end Ends a loop or block of code
do x 1 to 100 if x gt 50 then do
type x end end
5AML Functions
- AML functions arc enclosed in
- abs 3 returns 3
- listfile -grid returns all of the grids in
the working dir - quote string places quotation marks around the
quoted or unquoted string - open opens a system file for reading or
writing - setvar fileunit open c\temp\temp outvar
read
6AML Variables
- AML variables arc surrounded by
- sv x x 1 increments x by 1
- AML variables are not typed
- They can hold Character Strings, Integers, Real
Numbers, and Boolean Expressions
Arc sv x abcdefg Arc ty x abcdefg Arc
sv x 3 3 Arc ty x 6
7Watch Files
- WATCH ltwatch_filegt APPEND COMMANDS
COORDINATES - Watch files capture the system input an output to
a file - Useful for documenting procedures and creating
aml
Arc watch test Arc lc Workspace
C\GIS_CLASS\GIS_PROGRAMMING does not exist Arc
watch off Arc sys more test Arc gt lc lt
Workspace C\GIS_CLASS\GIS_PROGRAMMING does not
exist Arc gt watch off lt Arc
8Converting watch files to amls
- Arc conv_watch_to_aml test test.aml
- Arc sys more test.aml
- lc
- watch off
- r test
Workspace C\WORKSPACE\NM_500K Available
Coverages ------------------- TIC_GEO
TIC_LAM
9Mosaic.aml
This part of the aml extracts the DEM files in a
directory to a grid
args subset / takes an argument from the
command line severity error ignore /ignore
the errors sv list listfile subset
-file / get a list of the files in the dir sv
count token list -count / count the files
to be processed ty count / output the
count do x 1 to count / start a loop to
extract the dem to grids sv name extract
x list / get the next file ty name
cx / output the file being processed
demlattice name cx / arc command to convert
to a grid end / end the loop
10Grid / starts grid sv hw count / 2 /
splits the list into to parts to avoid length
problems sv hw trunc hw / converts hw to
an integer sv l1 c1 / builds the first half
of grids to mosaic do x 2 to hw sv l1
l1,cx end ty l1 / outputs the first
list sv l2 cx / builds the list of the
second half of the grids to mosaic sv z hw
2 do x z to count sv l2
l2,cx end ty l2 / outputs the second
list t1 mosaic(l1) / mosaic the first list
into a single grid t2 mosaic(l2) / mosaic
the second list into a single grid msubset
mosaic(t1,t2) / mosaic the two halves into a
single gird Q / quits gird
11kill t1 all / kill the first half kill t2
all / kill the second half do x 1 to
count / start a loop to kill the single
girds kill cx all end / end the loop to
kill the single grids
12Customize the Interface
- Click tools
- Select customize
- Commands tab
- Select the category Pan/Zoom
- Drag the tool to a toolbar
- These tools will be save in the normal.mxt and
will be present when ArcMap is restarted - To remove a tool drag it off a toolbar
- You can make you own toolbar
13ArcObjects, VBA, and COM
- ArcObjects is a collection of COM objects that
can be used to create custom programs and VBA
macros. - ArcGIS Desktop is made from the same COM objects.
- VBA Visual Basic for Applications
- COM Component Object Model is a Microsoft
programming standard
14Custom Interfaces
- You can add and remove tools from toolbars and
create your own toolbars. - You can create custom applications using the
components(ArcObjects) from ArcGIS.
15ArcObjects
- Introduction to ArcObjects
- 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. - From arcobjectsonilne.esri.com
16Object-oriented programming 101
- There are 3 principales that all OOP languages
share. - Encapsulation
- Inheritance
- Polymorphism
17Inheritance
- Classes can inherit properties and method from
the class they are derived from - If you have a class called pet with the fallowing
properties and methods - Name
- Eat
- You can declare a new class that is a type of
pet. This class has aditional properties. - DOGpet
- Bark
- Eat
- You can use the dog object to do the fallowing
- Dim mydog as dog
- Set mydog new dog
- MYDog.bark mydog.eat mydog.name REX
- myDOG.EAT
18Polymorphism
- Operators can work differently with different
objects - Dim x, y as integer
- Dim rex, fluffy as dog
- X 1 y 2 xy 3
- Rex fluffy puppies
19Encapsulation
- Encapsulation Code, Properties, and Methods are
grouped into groups called classes. Properties
and Methods can be declared Public or Private. - Public properties and methods can be used by any
code. - Private properties and methods can ONLY be call
from the class in which they exist
20Object model diagrams
- Abstract class- you can not create object from
an abstract class - Class objects you must find another class to
create an object from a class - Coclass you can declare variables of coclass
21(No Transcript)
22VBA Macros
- Start the VBA editor by clicking
- Tools
- Macros
- Visual Basic Editor
- A Macro is a public subroutine
- PUBLIC SUB MYMACRO()
- MSGBOX HELLO WORLD
- END SUB
23Macro Example
Public Sub toggle() Dim pMxDocument As
IMxDocument Set pMxDocument ThisDocument
Dim pMap As IMap Set pMap pMxDocument.FocusMa
p Dim player As ILayer Dim x As Integer
For x 0 To pMap.LayerCount - 1 Set
player pMap.Layer(x) If player.Visible
True Then player.Visible
False Else player.Visible
True End If Next x
pMxDocument.ActivatedView.Refresh
pMxDocument.ActiveView.ContentsChanged End Sub
24(No Transcript)
25(No Transcript)
26(No Transcript)
27(No Transcript)
28ArcObjects Help
- http//arcobjectsonline.esri.com
- Getting Started
- Object Model Diagrams
- Samples
- Exploring ArcObjects by Michael Zeiller
- PDF is on the cd
- Getting to Know ArcObjects by Robert Burke
- Esri Press ISBN 1-58948-018-x