Title: Extending ArcGIS via programming
1Extending ArcGIS via programming
- Why Programming
- Automation of repetitive tasks
- Implementation of functionality not available
- Programming functionality
- Scripts (AML, VB, Python, Avenue)
- Interfaces for application programmers
- Model Builder
- ArcObjects
- COM Integration
2Three Views of GIS
Geodatabase view Structured data sets that
represent geographic information in terms of a
generic GIS data model. Geovisualization view
A GIS is a set of intelligent maps and other
views that shows features and feature
relationships on the earth's surface. "Windows
into the database" to support queries, analysis,
and editing of the information. Geoprocessing
view Information transformation tools that
derives new geographic data sets from existing
data sets.
adapted from www.esri.com
3Examples
- TauDEM ArcMap toolbar using Visual Basic/C
(implementation of functionality not available in
ArcGIS) - Visual Basic Programming of simple grid
calculations
4TauDEM Software Functionality
- Pit removal (standard flooding approach)
- Flow directions and slope
- D8 (standard)
- D? (Tarboton, 1997, WRR 33(2)309)
- Flat routing (Garbrecht and Martz, 1997, JOH
193204) - Drainage area (D8 and D?)
- Network and watershed delineation
- Support area threshold/channel maintenance
coefficient (Standard) - Combined area-slope threshold (Montgomery and
Dietrich, 1992, Science, 255826) - Local curvature based (using Peuker and Douglas,
1975, Comput. Graphics Image Proc. 4375) - Threshold/drainage density selection by stream
drop analysis (Tarboton et al., 1991, Hyd. Proc.
5(1)81) - Wetness index and distance to streams
- Water Quality Functions
5TauDEM in ArcGIS
Visual Basic ESRI ArcGIS 8.3, 9.0 Toolbar
Standalone command line applications
C COM DLL interface
Available from
TauDEM C library
Fortran (legacy) components
http//www.engineering.usu.edu/dtarb/
TauDEM Gridio
Shapelib
ESRI gridio API (Spatial analyst)
ESRI binary grid
ASCII text grid
Vector shape files
Binary direct access grid
Data formats
6Implementation Details
Spatial Analyst includes a C programming API
(Application Programming Interface) that allows
you to read and write ESRI grid data sets
directly.
Excerpt from gioapi.h / GetWindowCell - Get a
cell within the window for a layer,
Client must interpret the type of the output
32 Bit Ptr to be the type of
the layer being read from. PutWindowCell -
Put a cell within the window for a layer.
Client must ensure that the type of
the input 32 Bit Ptr is the
type of the layer being read from. / int
GetWindowCell(int channel, int rescol, int
resrow, CELLTYPE cell) int PutWindowCell(int
channel, int col, int row, CELLTYPE cell)
7 C COM Methods used to implement functionality
using Microsoft Visual C
STDMETHODIMP CtkTauDEMAreadinf(BSTR angfile,
BSTR scafile, long x, long y, int doall, BSTR
wfile, int usew, int contcheck, long result)
USES_CONVERSION //needed to convert from BSTR
to Char or String result area(
OLE2A(angfile), OLE2A(scafile), x,y,doall,
OLE2A(wfile), usew, contcheck) return
S_OK
8Visual Basic for the GUI and ArcGIS linkage
Private TarDEM As New tkTauDEM Private
Function runareadinf(Optional toadd As Boolean
False) As Boolean Dim i As Long
runareadinf False i TarDEM.Areadinf(tdfile
s.ang, tdfiles.sca, 0, 0, 1, "", 0, 1) If
TDerror(i) Then Exit Function If toadd Then
AddMap tdfiles.sca, 8 End If
runareadinf True End Function
9Using TauDEM - Exercise
10Calculating the distance to a drain point (e.g.
watershed outlet or gage)
- Introduce VB scripting
- Introduce Recursion
- Isolate the Watershed draining to a point
- Could be done with the Flow Path function
(maybe), but a programmed solution is instructive
and can be generalized to other applications
11Distance from each grid cell to outlet along flow
path Write program to do this
12Distances
42.4
42.4
42.4
30
30
30
42.4
42.4
42.4
30
30
30
42.4
42.4
42.4
30
30
30
42.4
30
30
30
30
30
13Summing the distances down from each grid cell
14Summing the distances down from each grid cell
30
3042.4
303042.4
303042.430
Number of additions
15Recursive Approach
16Recursive Approach
30
3042.4
3072.4
30102.4
Number of additions N
17This requires (assumes) that the distance for
cell i,j is initialized or has been calculated to
start the process
18Programming the calculation of distance to the
outlet
102.4
72.4
30
72.4
42.4
0
19Visual Basic Implementation
'RECURSIVE DISTANCE CALCULATION FUNCTION Sub
DistCalc(i, j) Dim k As Integer, inb As Long,
jnb As Long For k 1 To 8Â ' for each neighbor
   inb i di(k)    jnb j dj(k)    If
(inb gt 0 And inb lt nrow And jnb gt 0 And jnb lt
ncol) Then  ' guard ' against out of domain
       If pPixels(jnb, inb) gt 0 Then  ' guard
against no data            If (pPixels(jnb,
inb) - 4 k Or pPixels(jnb, inb) 4 k) Then
           ' Here we have a grid cell that
drains back to the grid cell we are at
               dPixels(jnb, inb) dPixels(j,
i) dd(k) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â DistCalc inb, jnb '
Call the function for the neighbor pixel
           End If        End If    End If
Next k End Sub
20Steps for distance to outlet program
- Read the outlet coordinates
- Read the DEM flow direction grid. This is a set
of integer values 1 to 8 indicating flow
direction - Initialize a distance to outlet grid with a no
data value - Convert outlet to row and column references
- Start from the outlet point. Set the distance to
0. - Call the DistCalc function at the outlet.
21Distance Calculation VBA Exercise
22Visual Basic Programming in ArcMAP
- References
- ESRI, (1999), ArcObjects Developers Guide
ArcInfo 8, ESRI Press, Redlands, California. - Zeiler, M., (2001), Exploring ArcObjects. Vol 1.
Applications and Cartography. Vol 2. Geographic
Data Management, ESRI, Redlands, CA.
23Are there any questions ?