Ejemplo n.º 1
0
    # Repeat is sometimes needed
    r.mapcalc(DEM + ' = if(isnull(' + accumulation_onmap + '),null(),' + DEM +
              ')',
              overwrite=True)
    r.mapcalc(accumulation_onmap + ' = if(isnull(' + DEM + '),null(),' +
              accumulation_onmap + ')',
              overwrite=True)

# Set region
g.region(raster=DEM_original_import)

# Build streams and sub-basins
r.stream_extract(elevation=DEM,
                 accumulation=accumulation_onmap,
                 stream_raster=streams_all,
                 stream_vector=streams_all,
                 threshold=Settings.drainage_threshold,
                 direction=draindir,
                 d8cut=0,
                 overwrite=True)
r.stream_basins(direction=draindir,
                stream_rast=streams_all,
                basins=basins_all,
                overwrite=True)
r.to_vect(input=basins_all,
          output=basins_all,
          type='area',
          flags='v',
          overwrite=True)

# Build stream network
v.stream_network(map=streams_all)
            overwrite=True)
# for irregular outlines on topo
r.mapcalc("drainageArea_m2 = drainageArea_m2 + 0*" + elevation, overwrite=True)
#r.watershed(elevation=elevation, flow='cellArea_km2', accumulation='drainageArea_km2', drainage='drainageDirection', stream='streams', threshold=thresh, flags='s', overwrite=True)
# Remove areas of negative (offmap) accumulation
#r.mapcalc('drainageArea_km2 = drainageArea_km2 * (drainageArea_km2 > 0)', overwrite=True)
#r.null(map='drainageArea_km2', setnull=0)
#r.mapcalc(elevation+" = "+elevation+"*drainageArea_km2*0", overwrite=True)

# Get watershed
print "Building drainage network"
r.stream_extract(elevation=elevation,
                 accumulation='drainageArea_m2',
                 threshold=thresh,
                 d8cut=0,
                 mexp=0,
                 stream_raster='streams',
                 stream_vector='streams',
                 direction='draindir',
                 overwrite=True)
"""
# Get slope and area
v.db_addcolumn(map='streams_points', columns=('slope double precision, area_km2 double precision'))
v.what_rast(map='streams_points', type='point', raster='slope', column='slope')
v.what_rast(map='streams_points', type='point', raster='drainageArea_km2', column='area_km2')
"""
"""
~~~~~~~~~~~~~~~~~~~~~
awickert@dakib:~$ Now that I have a good ordering scheme, find adjacency between units based on starting and ending points and then convert each of these to points and get the slopes and areas between them. Concatenate these all into a single line and see what kind of averaging is needed -- of position, slope, and area. Poisition should include a base downstream distance as well, so we can keep averaged lines on the same course.
06 NOV
~~~~~~~~~~~~~~~~~~~~~