Skip to content

Instantly share code, notes, and snippets.

@cquest
Last active July 5, 2022 06:30

Revisions

  1. cquest revised this gist Dec 26, 2016. 1 changed file with 29 additions and 1 deletion.
    30 changes: 29 additions & 1 deletion hillshade-transparent-overlay.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    - some computer

    ## compute grayscale hillshade using gdaldem
    gdaldem hillshade -compute_edges you_dem_file hillshade.tif
    gdaldem hillshade -compute_edges your_dem_file hillshade.tif

    ## color-ramp to compute transparency (alpha channel)
    In another bowl, prepare the following shade.ramp file:
    @@ -40,3 +40,31 @@ and third one if you want only shades
    ## stir together using gdaldem color-relief
    gdaldem color-relief hillshade.tif -alpha shade.ramp hillshade-overlay.tif

    # DEM smooth/blur using .vrt

    Here is a .vrt example applying a gaussian blur on the source (srtm.vrt)
    The resulting .vrt can be use to compute the hillshade instead of the original DEM file.
    It is also possible to smooth/blur the hillshade output instead of the DEM.

    ````
    <VRTDataset rasterXSize="10801" rasterYSize="10801">
    <SRS>GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]]</SRS>
    <GeoTransform> 9.9986111111111109e-01, 2.7777777777777778e-04, 0.0000000000000000e+00, 5.0000138888888891e+01, 0.0000000000000000e+00, -2.7777777777777778e-04</GeoTransform>
    <VRTRasterBand dataType="Int16" band="1">
    <NoDataValue>-32768</NoDataValue>
    <ColorInterp>Gray</ColorInterp>
    <KernelFilteredSource>
    <SourceFilename relativeToVRT="1">srtm.vrt</SourceFilename>
    <SourceBand>1</SourceBand>
    <SourceProperties RasterXSize="10801" RasterYSize="10801" DataType="Int16" BlockXSize="128" BlockYSize="128" />
    <SrcRect xOff="0" yOff="0" xSize="10801" ySize="10801" />
    <DstRect xOff="0" yOff="0" xSize="10801" ySize="10801" />
    <NODATA>-32768</NODATA>
    <Kernel normalized="1">
    <Size>9</Size>
    <Coefs>0 0.000001 0.000014 0.000055 0.000088 0.000055 0.000014 0.000001 0 0.000001 0.000036 0.000362 0.001445 0.002289 0.001445 0.000362 0.000036 0.000001 0.000014 0.000362 0.003672 0.014648 0.023205 0.014648 0.003672 0.000362 0.000014 0.000055 0.001445 0.014648 0.058434 0.092566 0.058434 0.014648 0.001445 0.000055 0.000088 0.002289 0.023205 0.092566 0.146634 0.092566 0.023205 0.002289 0.000088 0.000055 0.001445 0.014648 0.058434 0.092566 0.058434 0.014648 0.001445 0.000055 0.000014 0.000362 0.003672 0.014648 0.023205 0.014648 0.003672 0.000362 0.000014 0.000001 0.000036 0.000362 0.001445 0.002289 0.001445 0.000362 0.000036 0.000001 0 0.000001 0.000014 0.000055 0.000088 0.000055 0.000014 0.000001 0</Coefs>
    </Kernel>
    </KernelFilteredSource>
    </VRTRasterBand>
    </VRTDataset>
    ````
  2. cquest revised this gist Dec 26, 2016. 1 changed file with 8 additions and 4 deletions.
    12 changes: 8 additions & 4 deletions hillshade-transparent-overlay.md
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,7 @@
    ## compute grayscale hillshade using gdaldem
    gdaldem hillshade -compute_edges you_dem_file hillshade.tif

    ## color-ramp to compute transparency (alpha channel)
    In another bowl, prepare the following shade.ramp file:
    - first value is the hillshade grey level, 220 is the value for flat areas
    - 2nd, 3rd, 4th value are the output RGB components (0 0 0 = black)
    @@ -21,18 +22,21 @@ In another bowl, prepare the following shade.ramp file:
    255 255 255 255 192
    ````

    #other option (smoother shades)
    other option (smoother shades)
    ````
    0 0 0 0 255
    220 0 0 0 0
    221 255 255 255 0
    255 255 255 255 192
    ````

    #and third one if you want only shades
    and third one if you want only shades
    ````
    0 0 0 0 255
    220 0 0 0 0
    255 0 0 0 0
    ````


    # stir together using gdaldem color-relief
    ## stir together using gdaldem color-relief
    gdaldem color-relief hillshade.tif -alpha shade.ramp hillshade-overlay.tif

  3. cquest renamed this gist Dec 26, 2016. 1 changed file with 9 additions and 3 deletions.
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,25 @@
    Ingredients:
    # Ingredients
    - a decent DEM
    - gdal
    - some computer

    # compute grayscale hillshade using gdaldem
    ## compute grayscale hillshade using gdaldem
    gdaldem hillshade -compute_edges you_dem_file hillshade.tif

    # in another bowl, prepare the following shade.ramp file
    In another bowl, prepare the following shade.ramp file:
    - first value is the hillshade grey level, 220 is the value for flat areas
    - 2nd, 3rd, 4th value are the output RGB components (0 0 0 = black)
    - last value is the alpha channel: 255 = opaque, 0 = transparent

    ````
    0 0 0 0 255
    32 0 0 0 240
    64 0 0 0 180
    96 0 0 0 120
    220 0 0 0 0
    221 255 255 255 0
    255 255 255 255 192
    ````

    #other option (smoother shades)
    0 0 0 0 255
  4. cquest revised this gist Dec 25, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion hillshade-transparent-overlay
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ gdaldem hillshade -compute_edges you_dem_file hillshade.tif

    #and third one if you want only shades
    0 0 0 0 255
    128 0 0 0 0
    220 0 0 0 0
    255 0 0 0 0


  5. cquest revised this gist Dec 25, 2016. 1 changed file with 4 additions and 6 deletions.
    10 changes: 4 additions & 6 deletions hillshade-transparent-overlay
    Original file line number Diff line number Diff line change
    @@ -11,16 +11,14 @@ gdaldem hillshade -compute_edges you_dem_file hillshade.tif
    32 0 0 0 240
    64 0 0 0 180
    96 0 0 0 120
    128 0 0 0 0
    129 255 255 255 0
    160 255 255 255 32
    224 255 255 255 128
    220 0 0 0 0
    221 255 255 255 0
    255 255 255 255 192

    #other option (smoother shades)
    0 0 0 0 255
    128 0 0 0 0
    129 255 255 255 0
    220 0 0 0 0
    221 255 255 255 0
    255 255 255 255 192

    #and third one if you want only shades
  6. cquest revised this gist Jan 12, 2014. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions hillshade-transparent-overlay
    Original file line number Diff line number Diff line change
    @@ -17,6 +17,18 @@ gdaldem hillshade -compute_edges you_dem_file hillshade.tif
    224 255 255 255 128
    255 255 255 255 192

    #other option (smoother shades)
    0 0 0 0 255
    128 0 0 0 0
    129 255 255 255 0
    255 255 255 255 192

    #and third one if you want only shades
    0 0 0 0 255
    128 0 0 0 0
    255 0 0 0 0


    # stir together using gdaldem color-relief
    gdaldem color-relief hillshade.tif -alpha shade.ramp hillshade-overlay.tif

  7. cquest revised this gist Dec 31, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion hillshade-transparent-overlay
    Original file line number Diff line number Diff line change
    @@ -18,5 +18,5 @@ gdaldem hillshade -compute_edges you_dem_file hillshade.tif
    255 255 255 255 192

    # stir together using gdaldem color-relief
    gdaldem color-relief - hillshade.tif -alpha shade.ramp hillshade-overlay.tif
    gdaldem color-relief hillshade.tif -alpha shade.ramp hillshade-overlay.tif

  8. cquest revised this gist Dec 31, 2013. 1 changed file with 7 additions and 8 deletions.
    15 changes: 7 additions & 8 deletions hillshade-transparent-overlay
    Original file line number Diff line number Diff line change
    @@ -8,15 +8,14 @@ gdaldem hillshade -compute_edges you_dem_file hillshade.tif

    # in another bowl, prepare the following shade.ramp file
    0 0 0 0 255
    32 0 0 0 250
    64 0 0 0 210
    96 0 0 0 128
    32 0 0 0 240
    64 0 0 0 180
    96 0 0 0 120
    128 0 0 0 0
    160 255 255 255 0
    192 255 255 255 0
    224 255 255 255 96
    255 255 255 255 128
    nv 0 0 0 0
    129 255 255 255 0
    160 255 255 255 32
    224 255 255 255 128
    255 255 255 255 192

    # stir together using gdaldem color-relief
    gdaldem color-relief - hillshade.tif -alpha shade.ramp hillshade-overlay.tif
  9. cquest renamed this gist Dec 30, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. cquest created this gist Dec 30, 2013.
    23 changes: 23 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    Ingredients:
    - a decent DEM
    - gdal
    - some computer

    # compute grayscale hillshade using gdaldem
    gdaldem hillshade -compute_edges you_dem_file hillshade.tif

    # in another bowl, prepare the following shade.ramp file
    0 0 0 0 255
    32 0 0 0 250
    64 0 0 0 210
    96 0 0 0 128
    128 0 0 0 0
    160 255 255 255 0
    192 255 255 255 0
    224 255 255 255 96
    255 255 255 255 128
    nv 0 0 0 0

    # stir together using gdaldem color-relief
    gdaldem color-relief - hillshade.tif -alpha shade.ramp hillshade-overlay.tif