def GeoreferenceFrame(task, image, output, p): """ Save Current Image """ ext = ".tiff" t = "out_" + p + ext name = "g_" + p src_file = os.path.join(output, t) image.save(src_file) # Opens source dataset src_ds = gdal.OpenEx( src_file, gdal.OF_RASTER | gdal.OF_READONLY, open_options=["NUM_THREADS=ALL_CPUS"], ) # Open destination dataset dst_filename = os.path.join(output, name + ext) dst_ds = gdal.GetDriverByName("GTiff").CreateCopy( dst_filename, src_ds, 0, options=[ "TILED=NO", "BIGTIFF=NO", "COMPRESS_OVERVIEW=DEFLATE", "COMPRESS=LZW", "NUM_THREADS=ALL_CPUS", "predictor=2", ], ) src_ds = None # Get raster projection srs = osr.SpatialReference() srs.ImportFromEPSG(4326) # Set projection dst_ds.SetProjection(srs.ExportToWkt()) geotransform_affine = gv.getAffineTransform() # Set location dst_ds.SetGeoTransform(geotransform_affine) dst_ds.GetRasterBand(1).SetNoDataValue(0) dst_ds.FlushCache() # Close files dst_ds = None # Add Layer to canvas layer = QgsRasterLayer(dst_filename, name) addLayerNoCrsDialog(layer, False, frames_g, isSubGroup=True) ExpandLayer(layer, False) if task.isCanceled(): return None return {"task": task.description()}
def GeoreferenceFrame(image, output, parent): ''' Save Current Image ''' # TODO : Create memory raster? p = str(parent.player.position()) if p == "0": return ext = ".tiff" t = "out_" + p + ext name = "g_" + p f_g = name + ext src_file = os.path.join(output, t) image.save(src_file) dst_filename = os.path.join(os.path.dirname(src_file), f_g) # Opens source dataset src_ds = gdal.Open(src_file) driver = gdal.GetDriverByName("GTiff") # Open destination dataset dst_ds = driver.CreateCopy(dst_filename, src_ds, 0) # Get raster projection epsg = 4326 srs = osr.SpatialReference() srs.ImportFromEPSG(epsg) # Set projection dst_ds.SetProjection(srs.ExportToWkt()) # Set location dst_ds.SetGeoTransform(geotransform) dst_ds.GetRasterBand(1).SetNoDataValue(0) # Close files dst_ds = None src_ds = None try: os.remove(src_file) except OSError: pass # Add Layer to canvas layer = QgsRasterLayer(dst_filename, name) addLayerNoCrsDialog(layer, False, frames_g) ExpandLayer(layer, False) iface.mapCanvas().refresh() return
def GeoreferenceFrame(task, image, output, p): ''' Save Current Image ''' # TODO : Create memory raster? ext = ".tiff" t = "out_" + p + ext name = "g_" + p src_file = os.path.join(output, t) image.save(src_file) # Opens source dataset src_ds = gdal.OpenEx(src_file, gdal.OF_RASTER | gdal.OF_READONLY, open_options=['NUM_THREADS=ALL_CPUS']) # Open destination dataset dst_filename = os.path.join(output, name + ext) dst_ds = gdal.GetDriverByName("GTiff").CreateCopy(dst_filename, src_ds, 0, options=['TILED=NO', 'BIGTIFF=NO', 'COMPRESS_OVERVIEW=DEFLATE', 'COMPRESS=LZW', 'NUM_THREADS=ALL_CPUS', 'predictor=2']) src_ds = None # Get raster projection srs = osr.SpatialReference() srs.ImportFromEPSG(4326) # Set projection dst_ds.SetProjection(srs.ExportToWkt()) # Set location dst_ds.SetGeoTransform(geotransform_affine) dst_ds.GetRasterBand(1).SetNoDataValue(0) dst_ds.FlushCache() # Close files dst_ds = None # Add Layer to canvas layer = QgsRasterLayer(dst_filename, name) addLayerNoCrsDialog(layer, False, frames_g) ExpandLayer(layer, False) return