Presentation is loading. Please wait.

Presentation is loading. Please wait.

Extending ArcGIS via programming

Similar presentations


Presentation on theme: "Extending ArcGIS via programming"— Presentation transcript:

1 Extending 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

2 Three 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

3 Examples TauDEM – ArcMap toolbar using Visual Basic/C++ (implementation of functionality not available in ArcGIS) Visual Basic Programming of simple grid calculations

4 TauDEM 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 193:204) 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, 255:826) Local curvature based (using Peuker and Douglas, 1975, Comput. Graphics Image Proc. 4:375) 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

5 TauDEM 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 Shapelib TauDEM Gridio ESRI gridio API (Spatial analyst) Data formats Vector shape files ASCII text grid Binary direct access grid ESRI binary grid

6 Implementation 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 CtkTauDEM::Areadinf(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; }

8 Visual 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(tdfiles.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

9 Using TauDEM - Exercise

10 Calculating the distance to a drain point (e. g
Calculating 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

11 Distance from each grid cell to outlet along flow path Write program to do this

12 Distances 30 42.4 42.4 42.4 30 30 30 42.4 42.4 42.4 30 30 30 30 42.4 42.4 42.4 30 30 30 30 42.4 30 30

13 Summing the distances down from each grid cell
30 72.4 102.4 132.4

14 Summing the distances down from each grid cell
30 Number of additions

15 Recursive Approach 30 72.4 102.4 132.4

16 Recursive Approach 30 Number of additions N

17 This requires (assumes) that the distance for cell i,j is initialized or has been calculated to start the process

18 Programming the calculation of distance to the outlet
5 1 8 7 6 3 2 4 5 6 7 Direction encoding 1 2 3 Distances to outlet 72.4 102.4 30 42.4 72.4

19 Visual 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 >= 0 And inb < nrow And jnb >= 0 And jnb < ncol) Then   ' guard ' against out of domain         If pPixels(jnb, inb) > 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

20 Steps 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.

21 Distance Calculation VBA Exercise

22 Visual 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.

23 Are there any questions ?
AREA 1 AREA 2 3 12


Download ppt "Extending ArcGIS via programming"

Similar presentations


Ads by Google