Reputation: 37
I am trying to process rain radar images of the UK MET weather service for a particular catchment area.
I am stitiching the image together from several png files before georeferencing it with gdal.translate
.
For reasons that I don't understand, the latitude axis (Northings in the screenshot) is reversed when I am using the correct order of coordinates for output.Bounds
. It is only the axis that is upside down, the image itself is in the correct orientation. Swapping the order of the coordinates for output.Bounds
the axis is the right way around. The orientation of the image itself does not change (and is therefore still correct).
The code in the code block below (with the 'wrong' order of input coordinates) produces the maps as shown in the screenshot (with the desired orientation of the y-axis).
# corresponds to 'boundary box for this image is 48° to 61° north and 12° west to 5° east'
full_cover_radar_coordinates = {"north": 1255449.1294913862,
"south": -162566.0277786366,
"west": -345474.8065004799,
"east": 778063.4254725212}
for file in files: #loop to produce images for every requested timestep
files = 'path'+file
ds = gdal.Open(files)
# Set the output file path
out = 'gif/'+file+'.tif'
output_path = out
# Perform translation using gdal.Translate --- coords should be west, south, east, north
gdal.Translate(output_path,
ds,
outputBounds=[full_cover_radar_coordinates.get('west'),
full_cover_radar_coordinates.get('north'),
full_cover_radar_coordinates.get('east'),
full_cover_radar_coordinates.get('south')],
outputSRS="EPSG:27700")
# Close the input dataset
ds = None
src = rasterio.open(out)
path = 'gif/new/'+file
gb = gpd.read_file("../shapefile_path/GBR_adm1.shp")
gb = gb.copy()
gb = gb.to_crs(epsg=27700)
ax = gb.plot(edgecolor='black', facecolor='None')
gb.plot(edgecolor='black', facecolor='None', ax=ax)
show(src.read(), transform=src.transform, ax=ax)
pyplot.xlabel("Eastings")
pyplot.ylabel("Northings")
Eliminated Errors:
ax.invert_yaxis()
command, but that also flips the image contentIn summary, everything is working how I want it, but the y-axis is upside down. What am I missing?
Upvotes: 0
Views: 45
Reputation: 26
The documented outputBounds parameter in https://gdal.org/en/latest/api/python/utilities.html#osgeo.gdal.TranslateOptions is: assigned output bounds: [ulx, uly, lrx, lry]
ul means upper left, and lr lower right. So it is expected that the second value is the maximum northing, and the fourth one the minimum northing.
Upvotes: 0