HAND and Flood Emergency Response

This Jupyter notebook illustrates the HAND workflow and its use in example flood emergency scenarios. The study area is Onion Creek (HUC10 code 1209020504).

This is also a demonstration of conducting geospatial anlysis with opensource toolkits (gdal) using an online Jupyter interface.

Environment required: CyberGIS-Jupyter for Water

  • We use CyberGIS' accelerated TauDEM version for d8 and d$\infty$ flow direction calculation.

    More about TauDEM

  • The USGS 3DEP Elevation dataset (a.k.a. National Elevation Dataset) is deployed on ROGER as a VRT raster.

  • The NHDPlus and associated water boundary dataset (WBD) are in Esri FileGDB format.

1. Data preparation and pre-processing

In [1]:
# Program file path
import os
data_dir = '/home/jovyan/shared_data/data/onion-hand'
    
# Format and performance parameters
np=4 #os.cpu_count()
dsepsg="EPSG:4269"
bufferdist='0.2' 

  Fetch the hands-on example data, from GIS in Water Resources (USU CEE6440, UT Austin CE 394K.3)

In [2]:
!cp -r {data_dir} data
                            

  The study area is Onion Creek in Texas. This watershed is a HUC10 unit with code 1209020504.

In [3]:
!ogrinfo data/OnionHand.gdb
INFO: Open of `data/OnionHand.gdb'
      using driver `OpenFileGDB' successful.
1: StreamGage (3D Measured Point)
2: NHDFlowline (3D Measured Multi Line String)
3: Catchment (Multi Polygon)
4: Watershed (Multi Polygon)
5: AddressPt (Point)
In [4]:
!gdalinfo data/Onion3.tif
Driver: GTiff/GeoTIFF
Files: data/Onion3.tif
Size is 7864, 2761
Coordinate System is:
GEOGCS["GCS_North_American_1983",
    DATUM["D_North_American_1983",
        SPHEROID["GRS_1980",6378137.0,298.257222101]],
    PRIMEM["Greenwich",0.0],
    UNIT["Degree",0.017453292519943295],
    VERTCS["Unknown VCS",
        VDATUM["Unknown"],
        PARAMETER["Vertical_Shift",0.0],
        PARAMETER["Direction",1.0],
        UNIT["Meter",1.0]]]
Origin = (-98.307685185190977,30.270277778898251)
Pixel Size = (0.000092592593000,-0.000092592593000)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  COMPRESSION=LZW
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  ( -98.3076852,  30.2702778) (  1d42'56.85"W,  0d31'41.94"N)
Lower Left  ( -98.3076852,  30.0146296) (  1d42'56.85"W,  0d31'25.87"N)
Upper Right ( -97.5795370,  30.2702778) (  1d42'11.10"W,  0d31'41.94"N)
Lower Right ( -97.5795370,  30.0146296) (  1d42'11.10"W,  0d31'25.87"N)
Center      ( -97.9436111,  30.1424537) (  1d42'33.98"W,  0d31'33.91"N)
Band 1 Block=7864x1 Type=Float32, ColorInterp=Gray
  Min=113.184 Max=513.462 
  Minimum=113.184, Maximum=513.462, Mean=277.847, StdDev=90.398
  NoData Value=-1
  Metadata:
    STATISTICS_COVARIANCES=8171.746395834145
    STATISTICS_MAXIMUM=513.4619140625
    STATISTICS_MEAN=277.84672138896
    STATISTICS_MINIMUM=113.18444061279
    STATISTICS_SKIPFACTORX=1
    STATISTICS_SKIPFACTORY=1
    STATISTICS_STDDEV=90.397712337394

More about ogrinfo and gdalinfo

  To visualize a GeoTIFF, we need to:

  • Render color from values.
  • Make tiles (pyramids) from the colored image.
In [5]:
# Colorize using hillshade
                    !gdaldem hillshade data/Onion3.tif Onion3-hillshade.tif
                    
0...10...20...30...40...50...60...70...80...90...100 - done.
In [6]:
# Make tiles with gdal2tiles (this is needed for visualization)
!gdal2tiles.py -t "Onion Creek DEM" -e -z 9-14 -a 0,0,0 -s epsg:4326\
    -r bilinear Onion3-hillshade.tif Onion3-hillshade 
Warning 1: VRTDataset>, band 1: NODATA_VALUES metadata item doesn't have the same number of values as the number of bands.  Ignoring it for mask.
Generating Base Tiles:
Warning 1: /tmp/tmp5ojrt2un/5022a680-99c8-4578-bf96-38e5285f1110.vrt, band 1: NODATA_VALUES metadata item doesn't have the same number of values as the number of bands.  Ignoring it for mask.
0...10...20...30...40...50...60...70...80...90...100
Generating Overview Tiles:
0...10...20...30...40...50...60...70...80...90...100

More about gdaldem and gdal2tiles.py

  To visualize a Shapefile, we only need to convert it to GeoJson

In [7]:
# Extract flowline.shp from GeoDatabase (which will be used later)
                    !ogr2ogr -f "ESRI Shapefile" flowline.shp data/OnionHand.gdb NHDFlowline 2>/dev/null
                    
In [8]:
# Convert the Shapefile to GeoJson for visualization
!ogr2ogr -f geojson flowline.json flowline.shp
Warning 1: The output driver does not natively support Date type for field FDATE. Misconversion can happen. -mapFieldType can be used to control field type conversion.

More about ogr2ogr

In [9]:
from cybergis import Floret
Floret('Onion Creek DEM', 'input')\
.addTMSLayer('DEM','Onion3-hillshade')\
.addGeoJson('Flowline','flowline.json').display()
Out[9]:

2. Workflow for computing HAND

2.1 Find inlets

  Use the dangle operation to find channel heads (inlets) of streams. They will guide the DEM-based stream calculation.

In [10]:
!find_inlets_mr -flow flowline.shp -dangle flow-inlets0.shp
!ogr2ogr -t_srs "EPSG:4269" flow-inlets.shp flow-inlets0.shp
In [11]:
!ogr2ogr -f geojson flow-inlets.json flow-inlets.shp
In [12]:
from cybergis import Floret
Floret('Flow Inlets', 'inlet').addTMSLayer('DEM','Onion3-hillshade')\
.addGeoJson('Flowline', 'flowline.json')\
.addGeoJson('Inlets','flow-inlets.json')\
.display()
Out[12]:

  Rasterize inlet points to the same spatial extent as the input DEM. The output is the weight grid.

In [13]:
ls data/getRasterInfo.py
data/getRasterInfo.py*
In [14]:
# Getting format info of the reference tif
import sys
names='fsizeDEM colsDEM rowsDEM nodataDEM xmin ymin xmax ymax cellsize_resx cellsize_resy'.split()
values=!{sys.executable} data/getRasterInfo.py data/Onion3.tif
print(zip(names, values))
for name,value in dict(zip(names,values)).items():
   para='%s="%s"'%(name,value)
   print (para)
   exec(para)
<zip object at 0x7ff2a0368108>
fsizeDEM="84.6MB"
colsDEM="7864"
rowsDEM="2761"
nodataDEM="-1.0"
xmin="-98.30768518519098"
ymin="30.01462962962525"
xmax="-97.57953703383897"
ymax="30.27027777889825"
cellsize_resx="0.000092592593000"
cellsize_resy="0.000092592593000"
In [15]:
!gdal_rasterize -ot Int16 -of GTiff -burn 1 -tr {cellsize_resx} {cellsize_resy} -te {xmin} {ymin} {xmax} {ymax} flow-inlets.shp weights.tif
0...10...20...30...40...50...60...70...80...90...100 - done.

More about gdal_rasterize

2.2 Pitremove

  Taudem pitremove: hydro-condition the DEM

In [16]:
!mpirun -np {np} pitremove -z data/Onion3.tif -fel fel.tif
                    
PitRemove version 5.3.9
Input file data/Onion3.tif has geographic coordinate system.
Nodata value input to create partition from file: -1.000000
Nodata value recast to float used in partition raster: -1.000000
This run may take on the order of 1 minutes to complete.
This estimate is very approximate. 
Run time is highly uncertain as it depends on the complexity of the input data 
and speed and memory of the computer. This estimate is based on our testing on 
a dual quad core Dell Xeon E5405 2.0GHz PC with 16GB RAM.
Processes: 4
Header read time: 0.038959
Data read time: 0.182190
Compute time: 3.339371
Write time: 0.971504
Total time: 4.532024

2.3 Compute flow direction

  Taudem d$\infty$: calc flow routing info that is used later to find the nearest stream from each cell

In [17]:
!mpirun -np {np} dinfflowdir -fel fel.tif -ang ang.tif -slp slp.tif 
DinfFlowDir version 5.3.9
Input file fel.tif has geographic coordinate system.
Nodata value input to create partition from file: -300000000549775575777803994281145270272.000000
Nodata value recast to float used in partition raster: -300000000549775575777803994281145270272.000000
This run may take on the order of 5 minutes to complete.
This estimate is very approximate. 
Run time is highly uncertain as it depends on the complexity of the input data 
and speed and memory of the computer. This estimate is based on our testing on 
a dual quad core Dell Xeon E5405 2.0GHz PC with 16GB RAM.
All slopes evaluated. 405327 flats to resolve.
Draining flats towards lower adjacent terrain
...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Draining flats away from higher adjacent terrain
......................................................
Setting directions
Iteration complete. Number of flats remaining: 10307
Draining flats towards lower adjacent terrain
..................
Draining flats away from higher adjacent terrain
.............
Setting directions
Iteration complete. Number of flats remaining: 10
Draining flats towards lower adjacent terrain
.
Draining flats away from higher adjacent terrain
..
Setting directions
Processors: 4
Header read time: 0.041497
Data read time: 0.174925
Compute Slope time: 3.639224
Write Slope time: 1.071055
Resolve Flat time: 36.327434
Write Flat time: 0.957851
Total time: 42.211987

 TauDEM d8: calc d8 flow directions for the computing of a stream grid weighted by the weight grid

In [18]:
!mpirun -np {np} d8flowdir -fel fel.tif -p p.tif -sd8 sd8.tif
                    
D8FlowDir version 5.3.9
Input file fel.tif has geographic coordinate system.
Nodata value input to create partition from file: -300000000549775575777803994281145270272.000000
Nodata value recast to float used in partition raster: -300000000549775575777803994281145270272.000000
This run may take on the order of 5 minutes to complete.
This estimate is very approximate. 
Run time is highly uncertain as it depends on the complexity of the input data 
and speed and memory of the computer. This estimate is based on our testing on 
a dual quad core Dell Xeon E5405 2.0GHz PC with 16GB RAM.
All slopes evaluated. 405327 flats to resolve.
Draining flats towards lower adjacent terrain
...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Draining flats away from higher adjacent terrain
......................................................
Setting directions
Iteration complete. Number of flats remaining: 10307
Draining flats towards lower adjacent terrain
..................
Draining flats away from higher adjacent terrain
.............
Setting directions
Iteration complete. Number of flats remaining: 10
Draining flats towards lower adjacent terrain
.
Draining flats away from higher adjacent terrain
..
Setting directions
Processors: 4
Header read time: 0.039101
Data read time: 0.168164
Compute Slope time: 1.162696
Write Slope time: 1.091292
Resolve Flat time: 37.154027
Write Flat time: 0.341309
Total time: 39.956589

 TauDEM aread8: calc contributing area with the weight grid. i.e., only the contributing area starting from the channel heads denoted in the weight grid

In [19]:
!mpirun -np {np} aread8 -p p.tif -ad8 ssa.tif -wg weights.tif -nc
                    
AreaD8 version 5.3.9
Input file p.tif has geographic coordinate system.
Nodata value input to create partition from file: -32768.000000
Nodata value recast to int16_t used in partition raster: -32768
This run may take on the order of 1 minutes to complete.
This estimate is very approximate. 
Run time is highly uncertain as it depends on the complexity of the input data 
and speed and memory of the computer. This estimate is based on our testing on 
a dual quad core Dell Xeon E5405 2.0GHz PC with 16GB RAM.
Input file weights.tif has geographic coordinate system.
Nodata value input to create partition from file: -10000000000.000000
Nodata value recast to float used in partition raster: -10000000000.000000
Number of Processes: 4
Read time: 0.185556
Compute time: 2.355156
Write time: 0.128742
Total time: 2.669453

 From the contributing area, extract streams areas (cellvalue = 1)

In [20]:
!mpirun -np {np} threshold -ssa ssa.tif -src src.tif -thresh 1
                    
Threshold version 5.3.9
Input file ssa.tif has geographic coordinate system.
Nodata value input to create partition from file: -1.000000
Nodata value recast to float used in partition raster: -1.000000
This run may take on the order of 1 minutes to complete.
This estimate is very approximate. 
Run time is highly uncertain as it depends on the complexity of the input data 
and speed and memory of the computer. This estimate is based on our testing on 
a dual quad core Dell Xeon E5405 2.0GHz PC with 16GB RAM.
Compute time: 0.070297
In [21]:
!gdaldem color-relief src.tif data/src.clr src-color.tif -of GTiff -alpha -nearest_color_entry
!gdal2tiles.py -e -z 9-14 -a 0,0,0 -s epsg:4326 -r bilinear src-color.tif src-color 
0...10...20...30...40...50...60...70...80...90...100 - done.
Generating Base Tiles:
0...10...20...30...40...50...60...70...80...90...100
Generating Overview Tiles:
0...10...20...30...40...50...60...70...80...90...100
In [22]:
from cybergis import Floret
Floret('DEM-Derived streamline','src')\
.addTMSLayer('Derived Streamline', 'src-color')\
.addGeoJson('Flowline','flowline.json').display()
Out[22]:

2.4 Calculate HAND

 With the d$\infty$ flowing routing and a stream grid that we know water flows on, calc HAND. We use vertical distance here; but horizontal distance or the combination can be used.

In [23]:
!mpirun -np {np} dinfdistdown -fel fel.tif -ang ang.tif -src src.tif -dd hand.tif -m ave v
                    
DinfDistDown -v version 5.3.9
Input file ang.tif has geographic coordinate system.
This run may take on the order of 1 minutes to complete.
This estimate is very approximate. 
Run time is highly uncertain as it depends on the complexity of the input data 
and speed and memory of the computer. This estimate is based on our testing on 
a dual quad core Dell Xeon E5405 2.0GHz PC with 16GB RAM.
Nodata value input to create partition from file: -340282346638528859811704183484516925440.000000
Nodata value recast to float used in partition raster: -340282346638528859811704183484516925440.000000
Input file fel.tif has geographic coordinate system.
Nodata value input to create partition from file: -300000000549775575777803994281145270272.000000
Nodata value recast to float used in partition raster: -300000000549775575777803994281145270272.000000
Input file src.tif has geographic coordinate system.
Nodata value input to create partition from file: -32768.000000
Nodata value recast to int16_t used in partition raster: -32768
Processors: 4
Read time: 0.494329
Compute time: 9.471183
Write time: 0.733075
Total time: 10.698587
In [24]:
# Colorization and tiling
!rm -rf ang-color
!gdaldem color-relief ang.tif data/ang.clr ang-color.tif -of GTiff -alpha
!gdal2tiles.py -e -z 9-14 -a 0,0,0 -s epsg:4326 -r bilinear ang-color.tif ang-color 
0...10...20...30...40...50...60...70...80...90...100 - done.
Generating Base Tiles:
0...10...20...30...40...50...60...70...80...90...100
Generating Overview Tiles:
0...10...20...30...40...50...60...70...80...90...100
In [25]:
from cybergis import Floret
Floret('Dinf Distancedown','ang')\
.addTMSLayer('Dinf', 'ang-color')\
.addGeoJson('Flowline','flowline.json').display()
Out[25]:
In [26]:
# Colorization and tiling
!gdaldem color-relief hand.tif data/HAND-blues.clr hand-color.tif -of GTiff -alpha
!gdal2tiles.py -e -z 9-14 -a 0,0,0 -s epsg:4326 -r bilinear hand-color.tif hand-color 
0...10...20...30...40...50...60...70...80...90...100 - done.
Generating Base Tiles:
0...10...20...30...40...50...60...70...80...90...100
Generating Overview Tiles:
0...10...20...30...40...50...60...70...80...90...100
In [27]:
from cybergis import Floret
Floret('Onion Creek HAND', 'onion-hand')\
.addTMSLayer('DEM', 'Onion3-hillshade')\
.addTMSLayer('HAND', 'hand-color')\
.addGeoJson('Flowline', 'flowline.json')\
.display()
Out[27]:

3. Application

  Whose homes will be flooded if a 5m flood take place?

In [28]:
# Filtering the HAND tif with threshold value
                    !gdal_calc.py -A hand.tif --outfile=depth.tif --calc="A<=5"
                    
0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 0.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 1.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 2.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 3.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 4.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 5.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 6.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 7.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 8.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 9.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 10.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 11.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 12.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 13.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 14.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 15.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 16.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 17.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 18.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 19.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 20.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 21.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 22.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 23.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 24.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 25.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 26.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 27.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 28.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 29.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 30.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 31.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 32.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 33.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 34.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 35.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 36.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 37.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 38.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 39.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 40.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 41.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 42.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 43.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 44.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 45.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 46.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 47.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 48.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 49.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 50.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 51.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 52.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 53.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 54.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 55.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 56.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 57.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 58.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 59.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 60.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 61.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 62.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 63.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 64.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 65.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 66.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 67.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 68.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 69.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 70.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 71.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 72.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 73.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 74.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 75.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 76.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 77.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 78.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 79.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 80.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 81.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 82.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 83.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 84.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 85.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 86.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 87.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 88.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 89.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 90.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 91.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 92.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 93.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 94.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 95.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 96.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 97.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 98.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 99.. 100 - Done
In [29]:
# Convert the result into polygons
!gdal_polygonize.py depth.tif depth.shp # ed Becky
Creating output depth.shp of format ESRI Shapefile.
0...10...20...30...40...50...60...70...80...90...100 - done.
In [30]:
!ogrinfo -al -so depth.shp
INFO: Open of `depth.shp'
      using driver `ESRI Shapefile' successful.

Layer name: depth
Metadata:
  DBF_DATE_LAST_UPDATE=2019-12-20
Geometry: Polygon
Feature Count: 700
Extent: (-98.297685, 30.024259) - (-97.579630, 30.270185)
Layer SRS WKT:
GEOGCS["NAD83",
    DATUM["North_American_Datum_1983",
        SPHEROID["GRS 1980",6378137,298.257222101,
            AUTHORITY["EPSG","7019"]],
        TOWGS84[0,0,0,0,0,0,0],
        AUTHORITY["EPSG","6269"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4269"]]
DN: Integer (9.0)
In [31]:
# Filter the target areas from background
!ogr2ogr filtered_depth.shp depth.shp -where "DN=1"
In [32]:
# Convert the result to a GeoJson
!ogr2ogr -f geojson filtered_depth.json filtered_depth.shp
In [33]:
# The catchment of interest and the addressPoints in that catchment
!ogr2ogr -f geojson catchment.json data/catchment.shp
!ogr2ogr -f geojson addressPoints.json data/addressPoints.shp
In [34]:
from cybergis import Floret
m = Floret('Catchment addresses and 5m-flood', '5m')
m.addTMSLayer('HAND', 'hand-color')
m.addGeoJson('Vunerable Areas', 'filtered_depth.json')
m.addGeoJson('Catchment', 'catchment.json')
m.addGeoJson('Address Points', 'addressPoints.json')
m.display()
Out[34]:
In [35]:
from cybergis import Editor
area = Editor('filtered_depth.shp')
addr = Editor('data/addressPoints.shp')
result=[]
for i in range(addr.lens):
    if -1 != area.index_of_first_feature_contains_point(*addr.shape(i).points[0]):
        result.append(i)
ans=addr.subshp(result)
ans.save('vunerableAddr')
!ogr2ogr -f geojson vunerableAddr.json vunerableAddr.shp
In [36]:
from cybergis import Floret
m = Floret('Flooded addresses', 'flooded')
m.addTMSLayer('HAND', 'hand-color')
m.addGeoJson('Vunerable Areas', 'filtered_depth.json')
m.addGeoJson('Catchment', 'catchment.json')
m.addGeoJson('Vunerable Addresses', 'vunerableAddr.json')
m.display()
Out[36]:

Congratulations on reaching the end!