[GIS] QGIS 3.10 not recognising projection information from raster created using GDAL

coordinate systemgdalosgeoqgis-3raster

Problem

QGIS 3.10 only partly reads projection information from raster file however QGIS 3.4 correctly reads information from same raster file.

I thought I had an issue creating the raster – I may still have but thought I should check my project was correctly set up in QGIS and discovered different behaviours between 3.4, 3.10.6 and 3.12.

Is my raster file set up correctly or have I missed something in QGIS?

Have set up QGIS by loading OSTN15 NTV2 but QGIS 3.10 fails to load the raster file as documented below. 3.4 loads same file successfully. Neither versions had the grid files installed. Information on OSTN15 installation below.

Running Raster Layer Unique Values

QGIS 3.4 – Projection: OSGB 1936 / British National Grid (EPSG:27700)

QGIS 3.10 & 3.12 – Raster Layer Unique Values – Projection: Unknown CRS: BOUNDCRS[SOURCECRS[PROJCRS["OSGB 1936 / British Na�

QGIS project steps

  1. Create new project
  2. Set project CRS to epsg:27700 – British National Grid
  3. Load map layer (OS Master map section)
  4. Load raster file
  5. QGIS 3.4 loads immediately but in QGIS 3.10.6.0 I am faced with the window below. Note it states the source CS is unknown 3.4 recognises the source CS.
  6. Multiple operations are possible for converting co-ordinates between these two coordinate reference systems. / Source CRS Unknown CRS
  7. I can select cancel and my image is still drawn in the correct location and correct size. The transformation is not processed as the same error exists when I check the raster layer properties.

QGIS |Error

Raster Creation Code

src_filename = "000249.png"
dst_filename = "raster249.tif"
fileformat = "GTiff"
driver = gdal.GetDriverByName(fileformat)
dst_ds = driver.Create(dst_filename, xsize=1152, ysize=1152,
                    bands=1, eType=gdal.GDT_Byte)
raster = cv2.imread('000249.png',0)
dst_ds.SetGeoTransform([324643.6636, .017, 0, 673776.9037, 0, -.017])
srs = osr.SpatialReference()
srs.ImportFromEPSG(27700)
dest_wkt = srs.ExportToWkt()
dst_ds.SetProjection(dest_wkt)
dst_ds.GetRasterBand(1).WriteArray(raster)
dst_ds = None

Raster Format

Driver: GTiff/GeoTIFF

Size is 1152 x 1152 x 1

Projection is PROJCS["OSGB 1936 / British National Grid",GEOGCS["OSGB 1936",DATUM["OSGB_1936",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]],TOWGS84[446.448,-125.157,542.06,0.15,0.247,0.842,-20.489],AUTHORITY["EPSG","6277"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4277"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",49],PARAMETER["central_meridian",-2],PARAMETER["scale_factor",0.9996012717],PARAMETER["false_easting",400000],PARAMETER["false_northing",-100000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","27700"]]

Origin = (324643.6636, 673776.9037)

Pixel Size = (0.017, -0.017)

Band Type=Byte

Min=0.000, Max=155.000

The raster code was initially obtained from the gdal tutorial but updated from the following stackoverflow questions.

https://gdal.org/tutorials/raster_api_tut.html

Georeferencing raster using GDAL and Python?

ogr: how to use epsg database for RD New projection?

how to set the geotransform using GDAL in python

Loading OSTN15 NTv2 in QGIS

@Ian Turton suggested checking that I have the grid files for epsg:27700 BNG installed which I had not. Here are the steps I followed.

Download zip file from Ordnance Survey
https://www.ordnancesurvey.co.uk/business-government/tools-support/os-net/for-developers

I unzipped and copied the files to C:\Program Files\QGIS 3.10\share\proj, there are other .gsb files there. Reading the posts the srs.db file that is released with QGIS should be set up correctly and only the OS files were required.
http://blog.sourcepole.ch/2014/02/18/ntv2-transformations-with-qgis/

https://www.xyht.com/gnsslocation-tech/using-ostn15-qgis

CRS project settings

CRS project settings

Best Answer

If I'm not mistaken, it's an issue with the way QGIS (since 3.10) report CRS info taken from GDAL 3.0.4. This issue on GitHub explains everything. What you can do is use this python script written by rouault to update the metadata of your GeoTIFF (it removes the TOWGS84 string that cause the problem). The bug has been patched in GDAL 3.1.0 and when QGIS will start using this version instead of GDAL 3.0.4, your original file should be recognized correctly.

I had the same problem with other CRS (EPSG 2945 to 2952) and using the script did the trick.

Related Question