230 likes | 251 Views
Learn how programming in ArcGIS boosts efficiency, automates tasks, and unlocks new functionalities not available through standard tools. Customize your GIS experience with scripts and interfaces for tailored solutions.
E N D
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
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 www.esri.com
Examples • TauDEM – ArcMap toolbar using Visual Basic/C++ (implementation of functionality not available in ArcGIS) • Visual Basic Programming of simple grid calculations
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
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 http://www.engineering.usu.edu/dtarb/ TauDEM Gridio Shapelib ESRI gridio API (Spatial analyst) Vector shape files ASCII text grid Binary direct access grid ESRI binary grid Data formats
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);
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; }
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
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
Distance from each grid cell to outlet along flow path Write program to do this
Distances 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
30 30 30+42.4 72.4 102.4 30+30+42.4 132.4 30+30+42.4+30 Summing the distances down from each grid cell
Summing the distances down from each grid cell 30 30+42.4 30+30+42.4 30+30+42.4+30 Number of additions
30 30 30+42.4 72.4 102.4 30+72.4 132.4 30+102.4 Recursive Approach
Recursive Approach 30 30+42.4 30+72.4 30+102.4 Number of additions N
This requires (assumes) that the distance for cell i,j is initialized or has been calculated to start the process
4 3 2 5 1 6 7 8 Direction encoding 1 2 3 1 7 6 5 2 7 6 5 3 6 7 7 Distances to outlet Programming the calculation of distance to the outlet 102.4 72.4 30 72.4 42.4 0
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
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.
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.
AREA 2 3 AREA 1 12 Are there any questions ?