Skip to main content
Tweeted twitter.com/StackGIS/status/878062413404401665
deleted 14 characters in body; edited title
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

how to compress Compressing raster using pyqgisPyQGIS?

I have the following code which batch saves rasters in qgis using the python terminal:

myDir = 'd:/output/'
layers = iface.legendInterface().layers()
pipe = QgsRasterPipe()
for layer in layers:
    extent = layer.extent()
    width, height = layer.width(), layer.height()
    renderer = layer.renderer()
    provider=layer.dataProvider()
    crs = layer.crs().toWkt() 
    pipe.set(provider.clone())
    pipe.set(renderer.clone())
    file_writer = QgsRasterFileWriter(myDir + layer.name() + ".tif")
    file_writer.writeRaster(pipe,
                            width,
                            height,
                            extent,
                            layer.crs())

The tifs that are saved are uncompressed, does anyone know how to turn on compression like LZW?

Thank you.

how to compress raster using pyqgis

I have the following code which batch saves rasters in qgis using the python terminal:

myDir = 'd:/output/'
layers = iface.legendInterface().layers()
pipe = QgsRasterPipe()
for layer in layers:
    extent = layer.extent()
    width, height = layer.width(), layer.height()
    renderer = layer.renderer()
    provider=layer.dataProvider()
    crs = layer.crs().toWkt() 
    pipe.set(provider.clone())
    pipe.set(renderer.clone())
    file_writer = QgsRasterFileWriter(myDir + layer.name() + ".tif")
    file_writer.writeRaster(pipe,
                            width,
                            height,
                            extent,
                            layer.crs())

The tifs that are saved are uncompressed, does anyone know how to turn on compression like LZW?

Thank you.

Compressing raster using PyQGIS?

I have the following code which batch saves rasters in qgis using the python terminal:

myDir = 'd:/output/'
layers = iface.legendInterface().layers()
pipe = QgsRasterPipe()
for layer in layers:
    extent = layer.extent()
    width, height = layer.width(), layer.height()
    renderer = layer.renderer()
    provider=layer.dataProvider()
    crs = layer.crs().toWkt() 
    pipe.set(provider.clone())
    pipe.set(renderer.clone())
    file_writer = QgsRasterFileWriter(myDir + layer.name() + ".tif")
    file_writer.writeRaster(pipe,
                            width,
                            height,
                            extent,
                            layer.crs())

The tifs that are saved are uncompressed, does anyone know how to turn on compression like LZW?

Source Link
Trashmonk
  • 1k
  • 12
  • 24

how to compress raster using pyqgis

I have the following code which batch saves rasters in qgis using the python terminal:

myDir = 'd:/output/'
layers = iface.legendInterface().layers()
pipe = QgsRasterPipe()
for layer in layers:
    extent = layer.extent()
    width, height = layer.width(), layer.height()
    renderer = layer.renderer()
    provider=layer.dataProvider()
    crs = layer.crs().toWkt() 
    pipe.set(provider.clone())
    pipe.set(renderer.clone())
    file_writer = QgsRasterFileWriter(myDir + layer.name() + ".tif")
    file_writer.writeRaster(pipe,
                            width,
                            height,
                            extent,
                            layer.crs())

The tifs that are saved are uncompressed, does anyone know how to turn on compression like LZW?

Thank you.