Skip to main content
replaced http://gis.stackexchange.com/ with https://gis.stackexchange.com/
Source Link

There is a workaround using the processing.runalg() method, described in this post: Using in-memory vector layer with QGIS processing / SEXTANTEUsing in-memory vector layer with QGIS processing / SEXTANTE.

EDIT: the script I copied was for vector clipping (not raster). I replaced it by GDAL's Clip raster by extent algorithm which does precisely what you want. You need to use the path to your raster as an input (and not the raster itself), though:

out_raster = processing.runalg("gdalogr:cliprasterbyextent", "path/to/raster.tif", "", "0,0,2,2", "", None)

There is a workaround using the processing.runalg() method, described in this post: Using in-memory vector layer with QGIS processing / SEXTANTE.

EDIT: the script I copied was for vector clipping (not raster). I replaced it by GDAL's Clip raster by extent algorithm which does precisely what you want. You need to use the path to your raster as an input (and not the raster itself), though:

out_raster = processing.runalg("gdalogr:cliprasterbyextent", "path/to/raster.tif", "", "0,0,2,2", "", None)

There is a workaround using the processing.runalg() method, described in this post: Using in-memory vector layer with QGIS processing / SEXTANTE.

EDIT: the script I copied was for vector clipping (not raster). I replaced it by GDAL's Clip raster by extent algorithm which does precisely what you want. You need to use the path to your raster as an input (and not the raster itself), though:

out_raster = processing.runalg("gdalogr:cliprasterbyextent", "path/to/raster.tif", "", "0,0,2,2", "", None)
corrected answer
Source Link
ArMoraer
  • 5.7k
  • 2
  • 26
  • 49

There is a workaround using the processing.runalg() method, described in this post: Using in-memory vector layer with QGIS processing / SEXTANTE.

It seemsEDIT: the script I copied was for vector clipping (not raster). I replaced it by GDAL's Clip raster by extent algorithm which does precisely what you can do something like thiswant. You need to use the path to your raster as an input (it generates a temporary vector layer and calls QGIS' clipping functionand not the raster itself), though:

mem_layerout_raster = QgsVectorLayer("Polygon?crs=epsg:4326", "temp_layer", "memory")
if not mem_layerprocessing.isValidrunalg()"gdalogr: raise Exception("Failedcliprasterbyextent", "path/to create memory layer")            
mem_layer_provider = mem_layer/raster.dataProvider()

clip_polygon =tif", QgsFeature()
clip_polygon.setGeometry(QgsGeometry.fromRect("", QgsRectangle(0"0,0,2,2) ))
mem_layer_provider.addFeatures([clip_polygon])
mem_layer.updateExtents()

output = "output/path"
QgsMapLayerRegistry.instance().addMapLayer(mem_layer)
processing.runalg("qgis:clip", layers[0]2", mem_layer"", outputNone)

There is a workaround using the processing.runalg() method, described in this post: Using in-memory vector layer with QGIS processing / SEXTANTE.

It seems you can do something like this (it generates a temporary vector layer and calls QGIS' clipping function):

mem_layer = QgsVectorLayer("Polygon?crs=epsg:4326", "temp_layer", "memory")
if not mem_layer.isValid(): raise Exception("Failed to create memory layer")            
mem_layer_provider = mem_layer.dataProvider()

clip_polygon = QgsFeature()
clip_polygon.setGeometry(QgsGeometry.fromRect( QgsRectangle(0,0,2,2) ))
mem_layer_provider.addFeatures([clip_polygon])
mem_layer.updateExtents()

output = "output/path"
QgsMapLayerRegistry.instance().addMapLayer(mem_layer)
processing.runalg("qgis:clip", layers[0], mem_layer, output)

There is a workaround using the processing.runalg() method, described in this post: Using in-memory vector layer with QGIS processing / SEXTANTE.

EDIT: the script I copied was for vector clipping (not raster). I replaced it by GDAL's Clip raster by extent algorithm which does precisely what you want. You need to use the path to your raster as an input (and not the raster itself), though:

out_raster = processing.runalg("gdalogr:cliprasterbyextent", "path/to/raster.tif", "", "0,0,2,2", "", None)
Source Link
ArMoraer
  • 5.7k
  • 2
  • 26
  • 49

There is a workaround using the processing.runalg() method, described in this post: Using in-memory vector layer with QGIS processing / SEXTANTE.

It seems you can do something like this (it generates a temporary vector layer and calls QGIS' clipping function):

mem_layer = QgsVectorLayer("Polygon?crs=epsg:4326", "temp_layer", "memory")
if not mem_layer.isValid(): raise Exception("Failed to create memory layer")            
mem_layer_provider = mem_layer.dataProvider()

clip_polygon = QgsFeature()
clip_polygon.setGeometry(QgsGeometry.fromRect( QgsRectangle(0,0,2,2) ))
mem_layer_provider.addFeatures([clip_polygon])
mem_layer.updateExtents()

output = "output/path"
QgsMapLayerRegistry.instance().addMapLayer(mem_layer)
processing.runalg("qgis:clip", layers[0], mem_layer, output)