Você está na página 1de 28

GIS Programming

Why Do We Want to Program GIS? AML ARC Macro Language ArcObject, VBA, COM and Custom Interfaces

Why Do We Want to Program GIS


Automate repetitive tasks To present a custom interface for users Document work Maintain Consistency

AML 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.

AML Directive
AML Directives Begin with an &
&system &type &do &end Runs an OS Command Types output Starts a loop of block of code Ends a loop or block of code
&if %x% > 50 &then &do &type %x% &end &end

&do x = 1 &to 100

AML 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]

AML 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

Watch Files
&WATCH <watch_file> {&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: |> lc <| Workspace C:\GIS_CLASS\GIS_PROGRAMMING does not exist Arc: |> &watch off <| Arc:

Converting 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

Mosaic.aml
This part of the aml extracts the DEM files in a directory to a grid
&args subset &severity &error &ignore /* takes an argument from the command line /*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% &do x = 1 &to %count% /* output the count /* start a loop to extract the dem to grids /* get the next file /* output the file being processed /* arc command to convert to a grid /* end the loop

&sv name = [extract %x% %list%] &ty %name% c%x% demlattice %name% c%x% &end

Grid &sv hw = %count% / 2 &sv hw = [trunc %hw%] &sv l1 = c1 &do x = 2 &to %hw% &sv l1 = %l1%,c%x% &end &ty %l1% &sv l2 = c%x% &sv z = %hw% + 2 &do x = %z% &to %count% &sv l2 = %l2%,c%x% &end &ty %l2% t1 = mosaic(%l1%) t2 = mosaic(%l2%) m%subset% = mosaic(t1,t2) Q

/* starts grid /* splits the list into to parts to avoid length problems /* converts hw to an integer /* builds the first half of grids to mosaic

/* outputs the first list /* builds the list of the second half of the grids to mosaic

/* outputs the second list /* mosaic the first list into a single grid /* mosaic the second list into a single grid /* mosaic the two halves into a single gird /* quits gird

kill t1 all kill t2 all

/* kill the first half /* kill the second half

&do x = 1 &to %count% kill c%x% all &end

/* start a loop to kill the single girds

/* end the loop to kill the single grids

Customize 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

ArcObjects, 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

Custom 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.

ArcObjects
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 domainspecific 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

ObjectObject-oriented programming 101


There are 3 principales that all OOP languages share. Encapsulation Inheritance Polymorphism

Inheritance
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. DOG:pet 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.eat;

mydog.name = REX

Polymorphism
Operators can work differently with different objects Dim x, y as integer Dim rex, fluffy as dog X = 1; y = 2; x+y = 3 Rex + fluffy = puppies

Encapsulation
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

Object 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

VBA 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

Macro Example
Public Sub toggle() Dim pMxDocument As IMxDocument Set pMxDocument = ThisDocument Dim pMap As IMap Set pMap = pMxDocument.FocusMap 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

ArcObjects 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

Você também pode gostar