' ' Name: Spatial.DEMFill ' ' Title: Creates a grid theme by filling all sinks in another grid theme. ' ' Topics: Spatial Analyst, Hydrological modeling ' ' Description: Takes a grid theme and fills all sinks, areas of ' internal drainage, contained within it. The aGrid.FlowDirection, ' aGrid.Sink, aGrid.Watershed, aGrid.ZonalFill, and aGrid.Con ' requests is used to fill the sinks. The process of filling ' sinks can create sinks, so a looping process is used until all ' sinks are filled. One cell sinks are not filled. Sinks of ' any depth are filled. ' ' Requires: The Spatial Analyst extension to be loaded. The script ' also requires an active view with an active grid theme that ' represents a surface. The grid theme should be the only active ' theme in the view. ' ' Self: ' ' Returns: ' theView = av.GetActiveDoc ' fill active GTheme theTheme = theView.GetActiveThemes.Get(0) ' fill sinks in Grid until they are gone elevGrid = theTheme.GetGrid sinkCount = 0 numSinks = 0 while (TRUE) flowDirGrid = elevGrid.FlowDirection(FALSE) sinkGrid = flowDirGrid.Sink if (sinkGrid.GetVTab = NIL) then ' check for errors if (sinkGrid.HasError) then return NIL end sinkGrid.BuildVAT end ' check for errors if (sinkGrid.HasError) then return NIL end if (sinkGrid.GetVTab <> NIL) then theVTab = sinkGrid.GetVTab numClass = theVTab.GetNumRecords newSinkCount = theVTab.ReturnValue(theVTab.FindField("Count"),0) else numClass = 0 newSinkCount = 0 end if (numClass < 1) then break elseif ((numSinks = numClass) and (sinkCount = newSinkCount)) then break end waterGrid = flowDirGrid.Watershed(sinkGrid) zonalFillGrid = waterGrid.ZonalFill(elevGrid) fillGrid = (elevGrid < (zonalFillGrid.IsNull.Con(0.AsGrid,zonalFillGrid))).Con(zonalFillGrid,elevGrid) elevGrid = fillGrid numSinks = numClass sinkCount = newSinkCount end ' rename data set aFN = av.GetProject.GetWorkDir.MakeTmp("fill", "") elevGrid.Rename(aFN) ' create a theme theGTheme = GTheme.Make(elevGrid) ' set name of theme theGTheme.SetName("Filled"++theTheme.GetName) ' add theme to the view theView.AddTheme(theGTheme)