<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi Louis-Philippe,</p>
<p>yes this is a matter of conventions. GRIB indeed uses a
center-of-pixel registration whereas GDAL uses a top-left corner
of pixel ones. So GDAL adds a half-pixel shift to expose GRIB
georeferencing using its convention, which is a feature. What is
annoying is that it leads to latitudes > 90 for such datasets,
but there isn't much that can be done in the driver itself.</p>
<p>Except doing post-processing to subset the file to crop the top
and bottom line (gdal_translate -srcwin 0 1 2400 1199), which will
result in longitudes in [-90 + 0.15, 90 - 0.15]. That said that
file is a bit inconsistent. It is quite expected that it uses an
odd number of rows (1201) to encode a clean (90 - -90) / (1201 -
1) = 0.15 vertical resolution. But for the horizontal dimension,
it uses an even number of columns (2400), which leads to a compute
resolution of (360 - 0) / (2400 - 1) = 0.15006252605252188
resolution. <br>
</p>
<p>Or if you're OK to deal with a slight alteration in the
georeferencing (maximum relative error should be 0.5 / 1200 = 0.04
% at the equator), gdal_translate -a_ullr 0 90 360 -90</p>
<p>Another approach would be to crop using non-integer coordinates
(to remove the top and bottom half-rows) + apply a non-nearest
resampling like</p>
<p>gdal_translate -srcwin 0 0.5 2400 1200 -r cubic in.grib2 out.tif</p>
<p>You should get an extent of latitudes in [-90,90].<br>
</p>
<p>Even<br>
</p>
<div class="moz-cite-prefix">Le 28/09/2023 à 21:31, Rousseau
Lambert, Louis-Philippe (ECCC) via gdal-dev a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:YT4PR01MB10407EEDA6B7BDB0729BC96DEFCC1A@YT4PR01MB10407.CANPRD01.PROD.OUTLOOK.COM">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style>@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-ligatures:standardcontextual;}a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-ligatures:standardcontextual;}span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}div.WordSection1
{page:WordSection1;}ol
{margin-bottom:0cm;}ul
{margin-bottom:0cm;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-CA">Hi, <o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">I am facing an issue
with GRIB2 data, and the extent reported by a gdal_info
command. Here is a sample data to test:
<a
href="https://drive.google.com/file/d/1URvQs2qHXgRkq3YfC7ZR8VGYK3SKXB59/view?usp=drive_link"
moz-do-not-send="true" class="moz-txt-link-freetext">
https://drive.google.com/file/d/1URvQs2qHXgRkq3YfC7ZR8VGYK3SKXB59/view?usp=drive_link</a><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">Here is what I am
testing with: <o:p></o:p></span></p>
<ul style="margin-top:0cm" type="disc">
<li class="MsoListParagraph"
style="margin-left:0cm;mso-list:l0 level1 lfo1"><span
lang="EN-CA">Ubuntu 20.04.6 LTS<o:p></o:p></span></li>
<li class="MsoListParagraph"
style="margin-left:0cm;mso-list:l0 level1 lfo1"><span
lang="EN-CA">GDAL 3.5.2, released 2022/09/02<o:p></o:p></span></li>
<li class="MsoListParagraph"
style="margin-left:0cm;mso-list:l0 level1 lfo1"><span
lang="EN-CA">PROJ Rel. 8.2.0, November 1st, 2021<o:p></o:p></span></li>
</ul>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">So, using grib_dump, I
see the longitude of the file should be from 0 to 360
degress:
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA">grib_dump out.grib2 | grep shapeOfTheEarth -A
12<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA"> shapeOfTheEarth = 6;<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA"> Ni = 2400;<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA"> Nj = 1201;<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA"> iScansNegatively = 0;<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA"> jScansPositively = 1;<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA"> jPointsAreConsecutive = 0;<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA"> alternativeRowScanning = 0;<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA"> latitudeOfFirstGridPointInDegrees = -90;<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA"> <b>longitudeOfFirstGridPointInDegrees = 0;<o:p></o:p></b></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA"> latitudeOfLastGridPointInDegrees = 90;<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA"> <b>longitudeOfLastGridPointInDegrees =
360;<o:p></o:p></b></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA"> iDirectionIncrementInDegrees = 0.15;<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA"> jDirectionIncrementInDegrees = 0.15;<o:p></o:p></span></i></p>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">But using gdal_info I
see the extent as:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA">gdal_info -proj4 out.grib2 | grep PROJ -A
9
<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA">PROJ.4 string is:<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA">'+proj=longlat +R=6371229 +no_defs'<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA">Origin =
(-0.075031263026261,90.075000000000003)<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA">Pixel Size =
(0.150062526052522,-0.150000000000000)<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA">Corner Coordinates:<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA">Upper Left ( -0.0750313, 90.0750000) ( 0d
4'30.11"W, 90d 4'30.00"N)<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA">Lower Left ( -0.0750313, -90.0750000) ( 0d
4'30.11"W, 90d 4'30.00"S)<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA">Upper Right ( 360.075, 90.075) (360d
4'30.11"E, 90d 4'30.00"N)<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="EN-CA">Lower Right ( 360.075, -90.075) (360d
4'30.11"E, 90d 4'30.00"S)<o:p></o:p></span></i></p>
<p class="MsoNormal"><i><span style="font-size:10.0pt"
lang="FR-CA">Center ( 180.0000000, 0.0000000) (180d
0' 0.00"E, 0d 0' 0.01"N)<o:p></o:p></span></i></p>
<p class="MsoNormal"><span lang="FR-CA"><o:p> </o:p></span></p>
<p class="MsoNormal">I would expect the gdal_info extent to be
also from 0 to 360 degrees (2400 pixels * 0.15 = 360). From
reading various source, I see the issue is potentially that
the GRIB2 files define the extent using the center of the
pixel while gdal assumes it is the top left corner. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">My question: Is there a way to change this
behavior in gdal, or this expected, or a bug ?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">LP<o:p></o:p></p>
</div>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
gdal-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/gdal-dev">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a>
</pre>
</blockquote>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.spatialys.com">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</body>
</html>