我正在尝试处理英国 MET 气象服务针对特定流域的降雨雷达图像。 我将多个 png 文件中的图像拼接在一起,然后使用
gdal.translate
对其进行地理配准。
由于我不明白的原因,当我使用 output.Bounds
的正确坐标顺序时,纬度轴(屏幕截图中的北距)会反转。只是轴是颠倒的,图像本身的方向是正确的。交换 output.Bounds
轴的坐标顺序是正确的方法。图像本身的方向不会改变(因此仍然正确)。下面代码块中的代码(输入坐标的“错误”顺序)生成的地图如屏幕截图所示(具有所需的 y 轴方向)。
# 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")
消除错误:
ax.invert_yaxis()
命令,但这也会翻转图像内容