コード例 #1
0
no_data_out = '-9999'
output_format = 'GTiff'
output_type = 'Int16'
aw3d30_tif = '{}proc/AW3D30_Z.tif'.format(folder_aw3d30)
if os.path.exists(aw3d30_tif): os.remove(aw3d30_tif)
merge_command = [
    'python', gdal_merge, '-a_nodata', no_data_out, '-ot', output_type, '-of',
    output_format, '-o', aw3d30_tif
] + ['{}raw/{}'.format(folder_aw3d30, tile) for tile in tiles_available]
merge_result = subprocess.run(merge_command, stdout=subprocess.PIPE)
if merge_result.returncode != 0: print(merge_result.stdout)

# 1b. Generate slope raster based on the AW3D30 DEM

# Extract projection & resolution info from the AW3D30 raster
aw3d30_proj, aw3d30_res_x, aw3d30_res_y, aw3d30_x_min, aw3d30_x_max, aw3d30_y_min, aw3d30_y_max, aw3d30_width, aw3d30_height = extract_projection_info(
    aw3d30_tif)

# Project AW3D30 raster to NZTM2000 (EPSG:2193) so that both horizontal & vertical units are metres (for slope calculation)
nztm2000_proj = 'EPSG:2193'
aw3d30_tif_NZTM2000 = '{}proc/AW3D30_Z_NZTM2000.tif'.format(folder_aw3d30)
project_command = [
    gdal_warp, '-overwrite', '-ot', 'Float32', '-s_srs', aw3d30_proj, '-t_srs',
    nztm2000_proj, '-dstnodata', '-9999', '-r', 'bilinear', aw3d30_tif,
    aw3d30_tif_NZTM2000
]
project_result = subprocess.run(project_command, stdout=subprocess.PIPE)
if project_result.returncode != 0: print(project_result.stdout)

# Generate a slope raster (using the NZTM2000 version of the AW3D30 raster)
slope_NZTM2000 = '{}proc/AW3D30_Slope_NZTM2000.tif'.format(folder_aw3d30)
if os.path.exists(slope_NZTM2000): os.remove(slope_NZTM2000)
コード例 #2
0
        return 8


###############################################################################
# 3. Resample LCDB rasters to match padded SRTM grids for each zone           #
###############################################################################

# Loop through all available DTM survey zones
for zone in zones:

    print('\nProcessing {} zone:'.format(zone))

    # Open a template raster (DEM for that zone, with pad=44) & extract its properties
    print(' - Analysing zonal SRTM raster to align grids...')
    srtm_filename = '{}proc/{}/SRTM_{}_Z.tif'.format(folder_srtm, zone, zone)
    srtm_proj, srtm_res_x, srtm_res_y, srtm_x_min, srtm_x_max, srtm_y_min, srtm_y_max, srtm_width, srtm_height = extract_projection_info(
        srtm_filename)

    # Define a new bounding box, including the padding required for the 2D convnet data pre-processing
    pad_x_min = srtm_x_min - pad * srtm_res_x
    pad_x_max = srtm_x_max + pad * srtm_res_x
    pad_y_min = srtm_y_min - pad * -srtm_res_y
    pad_y_max = srtm_y_max + pad * -srtm_res_y
    pad_width = srtm_width + 2 * pad
    pad_height = srtm_height + 2 * pad

    # Rasterise the Manaaki Whenua land cover SHP to a raster (aligning it with the others, in terms of resolution & extent)
    print(' - Rasterising land cover SHP to zone GeoTIFF...')
    LCDB_shp = '{}/proc/LCDB_v50_WGS84.shp'.format(folder_lcdb)
    LCDB_tif = '{}/proc/LCDB_GroupID_{}_Pad44.tif'.format(folder_lcdb, zone)
    rasterise_command = [
        gdal_rasterise, '-a', 'GrpID_2018', '-l',
コード例 #3
0
# Build gdal_merge command
no_data_out = '-9999'
output_format = 'GTiff'
output_type = 'Int16'
aster_tif = '{}proc/ASTER_Z.tif'.format(folder_aster)
if os.path.exists(aster_tif): os.remove(aster_tif)
merge_command = ['python', gdal_merge, '-a_nodata', no_data_out, '-ot', output_type, '-of', output_format, '-o', aster_tif] + ['{}raw/{}'.format(folder_aster, tile) for tile in tiles_available]
merge_result = subprocess.run(merge_command, stdout=subprocess.PIPE)
if merge_result.returncode != 0: print(merge_result.stdout)


# 1b. Generate slope raster based on the ASTER DEM

# Extract projection & resolution info from the ASTER raster
aster_proj, aster_res_x, aster_res_y, aster_x_min, aster_x_max, aster_y_min, aster_y_max, aster_width, aster_height = extract_projection_info(aster_tif)

# Project ASTER raster to NZTM2000 (EPSG:2193) so that both horizontal & vertical units are metres (for slope calculation)
nztm2000_proj = 'EPSG:2193'
aster_tif_NZTM2000 = '{}proc/ASTER_Z_NZTM2000.tif'.format(folder_aster)
project_command = [gdal_warp, '-overwrite', '-ot', 'Float32', '-s_srs', aster_proj, '-t_srs', nztm2000_proj, '-dstnodata', '-9999', '-r', 'bilinear', aster_tif, aster_tif_NZTM2000]
project_result = subprocess.run(project_command, stdout=subprocess.PIPE)
if project_result.returncode != 0: print(project_result.stdout)

# Generate a slope raster (using the NZTM2000 version of the ASTER raster)
slope_NZTM2000 = '{}proc/ASTER_Slope_NZTM2000.tif'.format(folder_aster)
if os.path.exists(slope_NZTM2000): os.remove(slope_NZTM2000)
slope_command = [gdal_dem, 'slope', aster_tif_NZTM2000, slope_NZTM2000, '-compute_edges', '-alg', 'ZevenbergenThorne']
slope_result = subprocess.run(slope_command, stdout=subprocess.PIPE)
if slope_result.returncode != 0: print(slope_result.stdout)