# Reproject raster, copying into project directory in the process processingNotes = "Resampling %s raster from %s to %s, spatial resolution (%.2f, %.2f) to (%.2f, %.2f)" % \ (args.type, rasterSrs, srs, rasterX, rasterX, demResolutionX, demResolutionY) sys.stdout.write(textwrap.fill("%s..." % (processingNotes, ))) resampleRaster(context.config, context.projectDir, inRasterPath, rasterFilepath, \ s_srs=None, t_srs=srs, \ trX=demResolutionX, trY=demResolutionY, \ resampleMethod=args.resampleMethod) else: # Copy the raster in to the project directory processingNotes = "Importing %s raster from %s without resampling" % ( args.type, inRasterPath) sys.stdout.write(textwrap.fill("%s..." % (processingNotes, ))) sys.stdout.flush() copyRasterToGeoTIFF(context.config, context.projectDir, inRasterPath, rasterFilename) sys.stdout.write('done\n') # Make sure extent of resampled raster is the same as the extent of the DEM newRasterMetadata = getDimensionsForRaster(rasterFilepath) if (newRasterMetadata[0] != demColumns) or (newRasterMetadata[1] != demRows): if args.type == GenericMetadata.RASTER_TYPE_STREAM_BURNED_DEM: # Extents to not match, roll back and bail out os.unlink(rasterFilepath) sys.exit( textwrap.fill( "ERROR: Raster type %s must be the same extent as DEM" % (GenericMetadata.RASTER_TYPE_STREAM_BURNED_DEM, ))) if not force: # Extents to not match, roll back and bail out os.unlink(rasterFilepath)
os.unlink(demFilepath) outfileTemp = None demFilenameTemp = None demFilepathTemp = None if args.scale: outfileTemp = "%s_temp" % (outfile,) demFilenameTemp = "%s%stif" % (outfileTemp, os.extsep) demFilepathTemp = os.path.join(context.projectDir, demFilenameTemp) # Copy the raster in to the project directory (reprojecting if need be) if not resample: sys.stdout.write("Importing DEM...") sys.stdout.flush() if args.scale: copyRasterToGeoTIFF(context.config, context.projectDir, inDEMPath, demFilenameTemp) else: copyRasterToGeoTIFF(context.config, context.projectDir, inDEMPath, demFilename) else: sys.stdout.write("Reprojecting DEM from %s to %s, spatial resolution (%.2f, %.2f) to (%.2f, %.2f)..." % \ (s_srs, t_srs, inSpatialMetadata[0], inSpatialMetadata[1], demResolutionX, demResolutionY) ) sys.stdout.flush() if args.scale: resampleRaster(context.config, context.projectDir, inDEMPath, demFilenameTemp, s_srs, t_srs, demResolutionX, demResolutionY, args.resampleMethod) else: resampleRaster(context.config, context.projectDir, inDEMPath, demFilename, s_srs, t_srs, demResolutionX, demResolutionY, args.resampleMethod) if args.scale:
os.unlink(demFilepath) outfileTemp = None demFilenameTemp = None demFilepathTemp = None if args.scale: outfileTemp = "%s_temp" % (outfile, ) demFilenameTemp = "%s%stif" % (outfileTemp, os.extsep) demFilepathTemp = os.path.join(context.projectDir, demFilenameTemp) # Copy the raster in to the project directory (reprojecting if need be) if not resample: sys.stdout.write("Importing DEM...") sys.stdout.flush() if args.scale: copyRasterToGeoTIFF(context.config, context.projectDir, inDEMPath, demFilenameTemp) else: copyRasterToGeoTIFF(context.config, context.projectDir, inDEMPath, demFilename) else: sys.stdout.write("Reprojecting DEM from %s to %s, spatial resolution (%.2f, %.2f) to (%.2f, %.2f)..." % \ (s_srs, t_srs, inSpatialMetadata[0], inSpatialMetadata[1], demResolutionX, demResolutionY) ) sys.stdout.flush() if args.scale: resampleRaster(context.config, context.projectDir, inDEMPath, demFilenameTemp, s_srs, t_srs, demResolutionX, demResolutionY, args.resampleMethod) else: resampleRaster(context.config, context.projectDir, inDEMPath, demFilename, s_srs, t_srs, demResolutionX,
if resample: # Reproject raster, copying into project directory in the process processingNotes = "Resampling %s raster from %s to %s, spatial resolution (%.2f, %.2f) to (%.2f, %.2f)" % \ (args.type, rasterSrs, srs, rasterX, rasterX, demResolutionX, demResolutionY) sys.stdout.write("%s..." % (processingNotes,) ) resampleRaster(context.config, context.projectDir, inRasterPath, rasterFilepath, \ s_srs=rasterSrs, t_srs=srs, \ trX=demResolutionX, trY=demResolutionY, \ resampleMethod=args.resampleMethod) else: # Copy the raster in to the project directory processingNotes = "Importing %s raster from %s without resampling" % (args.type, inRasterPath) sys.stdout.write("%s..." % (processingNotes,) ) sys.stdout.flush() copyRasterToGeoTIFF(context.config, context.projectDir, inRasterPath, rasterFilename) sys.stdout.write('done\n') # Make sure extent of resampled raster is the same as the extent of the DEM newRasterMetadata = getDimensionsForRaster(rasterFilepath) if (not force) and ( (newRasterMetadata[0] != demColumns) or (newRasterMetadata[1] != demRows) ): # Extents to not match, roll back and bail out os.unlink(rasterFilepath) sys.exit(textwrap.fill("ERROR: Extent of raster dataset %s does not match extent of DEM in project directory %s. Use --force to override.") % (rasterFilename, context.projectDir)) # Write metadata if GenericMetadata.RASTER_TYPE_LC == args.type: GenericMetadata.writeStudyAreaEntry(context, "landcover_type", "custom") # Write provenance