I want to determine the lat/long coordinates of my raster layer. I calculated them using the geotransform of the dataset.
When I run the script on my file, it produces longitudes that are out of range:
(0.0, 0.0, '->', 179.88, 90.12)
(0, 751, '->', 179.88, -90.11999999999998)
(1500, 751, '->', 539.88, -90.11999999999998)
(1500, 0, '->', 539.88, 90.12)
The longitude ranges from 180 to 540 (it's off by 360)
Here's the code I used:
import gdal, osr
gribdata = gdal.Open('CMC_glb_ABSV_ISBL_250_latlon.24x.24_2018041800_P000.grib2')
gribdata_gtrn = gribdata.GetGeoTransform()
gribdata_bbox_cells = (
(0., 0.),
(0, gribdata.RasterYSize),
(gribdata.RasterXSize, gribdata.RasterYSize),
(gribdata.RasterXSize, 0),
)
geo_pts = []
for x, y in gribdata_bbox_cells:
x2 = gribdata_gtrn[0] + gribdata_gtrn[1] * x + gribdata_gtrn[2] * y
y2 = gribdata_gtrn[3] + gribdata_gtrn[4] * x + gribdata_gtrn[5] * y
print (x, y, '->', x2, y2)
The file I'm using is this one, taken from the CMC global forecast.
The latitudes are correct (90 to -90), but howcome the longitude is 180 to 540?
gribdata_srs.IsProjected()), so of course the coordinate transformation won't work – obchardon Apr 18 '18 at 14:15