User Tools

Site Tools


python:howto:hillshade

Automatisierte Reliefschummerung

Zur Schummerungsberechnung wird ein Verfahren der multiplen Beleuchtung verwendet. Sie unterstützt die visuelle Interpretation von eindeutigen Geländestrukturen erheblich. Hier die Python Funktion.

def hillshade(idcode):
    ''' generates a basic hillshading for a google free print version of DEM data
    
    very time consuming due to the mdenoise filtering
    Input: DEM (GEOTIFF)
    Output: GeoTIFF Hillshading file  
    '''
    # read configuration    
    WorkHomePath ='/home/gisma/webcalcrisk/' 
    WorkDataPath='/home/gisma/webcalcrisk/input/ASTER/UTM/ascii/shade/'
    DEMFile='DEM.tif'
    
    # denoise parameter fuer DGM Rauschfiltern default 
    dnoi=0.81 
    dnoi_it=5
    
    gdal_trans_cmd='gdal_translate -of AAIGrid  '+WorkDataPath+DEMFile+' '+WorkDataPath+'DEMmap.asc'
    os.system(gdal_trans_cmd)  
    
    denoise_cmd='/home/gisma/webcalcrisk/script/mdenoise -i '+WorkDataPath+'DEMmap.asc -e -n '+dnoi_it+' -t '+dnoi+'  -o ' +WorkDataPath+'DEMdenoise.asc'
    os.system(denoise_cmd)  
                                                                                 
    gdal_trans_cmd='gdal_translate -of Gtiff  '+WorkDataPath+'DEMdenoise.asc '+WorkDataPath+'hillshadeDEM'+TIF
    os.system(gdal_trans_cmd)  

    # generating a hillshade base map
    # hillshade #1 340 45
    gdalhillshade ='gdaldem hillshade '+WorkDataPath+'hillshadeDEM.tif '+WorkDataPath+'hs340_45.tif -az 340 -alt 45 -of GTiff'    
    os.system(gdalhillshade)
    # hillshade #1 160 45
    gdalhillshade ='gdaldem hillshade '+WorkDataPath+'hillshadeDEM.tif '+WorkDataPath+'hs160_45.tif -az 160 -alt 45 -of GTiff'    
    os.system(gdalhillshade)
    
    # hillshade #3 295 45
    gdalhillshade ='gdaldem hillshade '+WorkDataPath+'hillshadeDEM.tif '+WorkDataPath+'hs295_45.tif -az 295 -alt 45 -of GTiff'    
    os.system(gdalhillshade)
    # hillshade #4 250 45
    gdalhillshade ='gdaldem hillshade '+WorkDataPath+'hillshadeDEM.tif '+WorkDataPath+'hs250_45.tif -az 250 -alt 45 -of GTiff'    
    os.system(gdalhillshade)
    
    # colorize hillshade
    gdalcolor='gdaldem color-relief '+WorkDataPath+'hs160_45.tif '+WorkHomePath+'script/16045.txt ' +WorkDataPath+'c16045.tif  -nearest_color_entry -of GTiff' 
    os.system(gdalcolor)
    # colorize hillshade    
    gdalcolor='gdaldem color-relief '+WorkDataPath+'hs340_45.tif '+WorkHomePath+'script/34045.txt ' +WorkDataPath+'c34045.tif  -nearest_color_entry -of GTiff' 
    os.system(gdalcolor)
    # colorize hillshade    
    gdalcolor='gdaldem color-relief '+WorkDataPath+'hs295_45.tif '+WorkHomePath+'script/grey.txt ' +WorkDataPath+'g29545.tif  -nearest_color_entry -of GTiff' 
    os.system(gdalcolor)
    # colorize hillshade    
    gdalcolor='gdaldem color-relief '+WorkDataPath+'hs250_45.tif '+WorkHomePath+'script/250_45.txt ' +WorkDataPath+'g25045.tif  -nearest_color_entry -of GTiff' 
    os.system(gdalcolor)
    
##    # generate Hillshadecomposite using imagemagick with different opacity
##    imcomposite = ' composite -blend 60 '+WorkDataPath+'c16045.tif '+WorkDataPath+'c34045.tif  -alpha Set '+WorkDataPath+'tmp1.tif'  #blend 70 
##    os.system(imcomposite) 
##    imcomposite = ' composite -blend 60 '+WorkDataPath+'tmp1.tif '+WorkDataPath+'g29545.tif -alpha Set '+WorkDataPath+'tmp2.tif'     #blend 60 grey
##    os.system(imcomposite)
##    imcomposite = ' composite -blend 90 '+WorkDataPath+'tmp2.tif '+WorkDataPath+'g25045.tif -alpha Set '+WorkDataPath+'tmp3.tif'     # blend 60 grey
##    os.system(imcomposite)

    # generate Hillshadecomposite using imagemagick with different opacity
    imcomposite = ' composite -blend 60 '+WorkDataPath+'hs160_45.tif '+WorkDataPath+'hs340_45.tif  -alpha Set '+WorkDataPath+'tmp1.tif'  #blend 70 
    os.system(imcomposite) 
    imcomposite = ' composite -blend 60 '+WorkDataPath+'tmp1.tif '+WorkDataPath+'hs295_45.tif -alpha Set '+WorkDataPath+'tmp2.tif'     #blend 60 grey
    os.system(imcomposite)
    imcomposite = ' composite -blend 90 '+WorkDataPath+'tmp2.tif '+WorkDataPath+'hs250_45.tif -alpha Set '+WorkDataPath+'tmp3.tif'     # blend 60 grey
    os.system(imcomposite)


    #   extract geotiff header data using listgeo from geotiff-bin 
    os.system('listgeo -tfw '+WorkDataPath+'hs340_45.tif')
    #  add geotiff header to the final hillshade base map using geotifcp    
    os.system('geotifcp  -e '+WorkDataPath+'hs340_45.tfw '+WorkDataPath+'tmp3.tif '+WorkDataPath+ASTER_ID+'shade.tif') 
python/howto/hillshade.txt · Last modified: 2019/08/20 19:16 (external edit)