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

GIS Programming

Embed Size (px)

Citation preview

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 1/28

GIS ProgrammingGIS Programming

Why Do We Want to Program GIS?Why Do We Want to Program GIS?

 AML AML ± ± ARC Macro Language ARC Macro Language

 ArcObject, VBA, COM and Custom Interfaces ArcObject, VBA, COM and Custom Interfaces

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 2/28

Why Do We Want to Program GISWhy Do We Want to Program GIS

 Automate repetitive tasks

To present a custom interface for users

Document work Maintain Consistency

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 3/28

 AML AML ± ± ARC Macro Language 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.

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 4/28

 AML Directive AML 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% > 50 &then

&do

&type %x%

&end

&end

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 5/28

 AML Functions AML Functions

 AML functions arc enclosed in []

 ± [abs ±3] returns 3

  ± [listfile * -grid] returns all of the grids inthe 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]

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 6/28

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

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 7/28

Watch FilesWatch 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:

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 8/28

Converting watch files to amlsConverting 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

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 9/28

Mosaic.amlMosaic.aml

&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% c%x% /* output the file being processed

demlattice %name% c%x% /* arc command to convert to a grid

&end /* end the loop

This part of the aml extracts the DEM files in a directory to a grid

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 10/28

Grid /* 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%,c%x%

&end

&ty %l1% /* outputs the first list&sv l2 = c%x% /* builds the list of the second half of the grids to mosaic

&sv z = %hw% + 2

&do x = %z% &to %count%

&sv l2 = %l2%,c%x%

&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

m%subset% = mosaic(t1,t2) /* mosaic the two halves into a single gird

Q /* quits gird

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 11/28

kill 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 c%x% all

&end /* end the loop to kill the single grids

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 12/28

Customize the InterfaceCustomize 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 andwill be present when ArcMap is restarted

To remove a tool drag it off a toolbar 

You can make you own toolbar 

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 13/28

 ArcObjects, VBA, and COM ArcObjects, VBA, and COM

 ArcObjects is a collection of COM objectsthat can be used to create customprograms and VBA macros.

 ArcGIS Desktop is made from the sameCOM objects.

VBA ± Visual Basic for Applications COM ± Component Object Model is a

Microsoft programming standard

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 14/28

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

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 15/28

 ArcObjects ArcObjects

Introduction to ArcObjects

ArcObjects is the development platform for the ArcGISfamily of applications such as ArcMap, ArcCatalog, andArcScene. The ArcObjects software components expose

the full range of functionality available in ArcInfo andArcView ® to software developers.

ArcObjects is a framework that lets you create domain-specific components from other components. TheArcObjects components collaborate to serve every data

management and map presentation function common tomost GIS applications. ArcObjects provides aninfrastructure for application customization that lets youconcentrate on serving the specific needs of your clients.

From arcobjectsonilne.esri.com

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 16/28

ObjectObject--oriented programming 101oriented programming 101

There are 3 principales that all OOP

languages share.

Encapsulation Inheritance

Polymorphism

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 17/28

InheritanceInheritance

Classes can inherit properties and method from the class they are derivedfrom

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

 ± 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.name = µREX¶

 ± myDOG.EAT

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 18/28

PolymorphismPolymorphism

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

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 19/28

EncapsulationEncapsulation

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

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 20/28

Object model diagramsObject model diagrams

 Abstract class- you can not create object froman abstract class

Class objects ± you must find another class tocreate an object from a class

Coclass ± you can declare variables of coclass

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 21/28

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 22/28

VBA MacrosVBA 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

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 23/28

Macro ExampleMacro ExamplePublic 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

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 24/28

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 25/28

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 26/28

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 27/28

8/3/2019 GIS Programming

http://slidepdf.com/reader/full/gis-programming 28/28

 ArcObjects Help 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 RobertBurke

 ± Esri Press ISBN 1-58948-018-x