I swear this used to work. I don't get any errors which is the confusing part- it just regurgitates the same layer in its original projection (in this case epsg 32630).

Version of Q is 3.10 A corunya.

raster = "raster.tif" #replace with a tif of your own not in 27700
crs = 27700 #british national grid

#reproj raster layer
{'INPUT': path + raster,
'TARGET_CRS':QgsCoordinateReferenceSystem("'" + 'EPSG:' + "'" + str(crs) + "'"),
'OUTPUT':path + raster})
rasterMap = iface.addRasterLayer(path + raster, "raster")

Can you help me?

  • I don't think it can do a reprojection with the SOURCE_CRS set to None shouldn't it be EPSG:32630? – Ian Turton Mar 4 at 17:59

I can reproduce that. Hmmmm..

Let's see what the target CRS is...

>>> QgsCoordinateReferenceSystem("'" + 'EPSG:' + "'" + str(crs) + "'")
<QgsCoordinateReferenceSystem: invalid>

Invalid? Hmmm what's that string turning out to be?

>>> "'" + 'EPSG:' + "'" + str(crs) + "'"

There's a lot of odd quote marks in there. Let's simplify:

>>> QgsCoordinateReferenceSystem("EPSG:" + str(crs))
<QgsCoordinateReferenceSystem: EPSG:27700>

That works for me in the processing call!

Not sure if your format with all the quotes should ever have worked, or maybe something has cleaned up the processing of strings to QgsCoordinateReferenceSystem to be a bit more strict.

  • f"EPSG: {crs}" would be the nice modern Python variant with less surprises :) – bugmenot123 Mar 4 at 18:30
  • Neither of these worked for me. Feel like I'm going mad.... – Jesse Mar 5 at 10:59
  • Are you getting "invalid" for literally QgsCoordinateReferenceSystem("EPSG:27700")? It seems very fussy, and the extra space introduced by @bugmenot123 comment is enough to break it. – Spacedman Mar 5 at 11:04
  • Oops, sorry. f"EPSG:{code}". – bugmenot123 Mar 5 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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