I have a script that loops through input raster's creates new raster files and converts these to vector performing a number of additional processes. Ultimately a vector is created that is a modified version of the input raster.

My question is how can I ensure that each new raster and vector created, whether they are a temp file or the final output, maintain the same projection (ESPG 27700)? Is there a command I can add in at the start of each loop or can I set the output projection in each individual process e.g. raster calculator or polygonize. An example line of the script is provide:

out1=processing.runalg('gdalogr:rastercalculator', raster,'1',None,'1',None,'1',None,'1',None,'1',None,'1','A>0',None,5,None,result_shp + "/" + result_name)

Additionally, is it possible to set a snap raster in a similar way and is this something I should consider doing?

  • Are your input layers always in EPSG:27700?
    – Joseph
    Feb 22, 2017 at 12:02
  • They should be, but I've had examples where they have an undefined / user defined projection that differs. Perhaps the solution could be as simple as using one of the tools to define the projection on the initial input?
    – AJ Walsh
    Feb 22, 2017 at 12:10

1 Answer 1


I would probably use an if statement to check if the raster CRS is EPSG:27700. If it is then run your gdalogr:rastercalculator, otherwise reproject it first using gdalogr:warpreproject and then run gdalogr:rastercalculator.

For example, something like:

if raster.crs().authid() == 'EPSG:27700':
    out2=processing.runalg('gdalogr:rastercalculator', out1['OUTPUT'],'1',...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.