GIS Programming
GIS Programming
Why Do We Want to Program GIS? AML ARC Macro Language ArcObject, VBA, COM and Custom Interfaces
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
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:
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 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
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
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
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
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
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