<html style="direction: ltr;">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style id="bidiui-paragraph-margins" type="text/css">body p { margin-bottom: 0cm; margin-top: 0pt; } </style>
</head>
<body bidimailui-charset-is-forced="true" style="direction: ltr;">
<p><font size="4"><font face="Helvetica, Arial, sans-serif">Thanks
to all who took the time to answer.</font></font></p>
<p><font size="4"><font face="Helvetica, Arial, sans-serif">Just to
close off this thread, here's the code that created a CF
compliant NetCDF that GDAL >3.4 could read:</font></font></p>
<p><br>
</p>
<p><font size="4" face="monospace">DS.rio.write_crs(f'EPSG:{projected_epsg}',
inplace=True</font></p>
<p><font size="4" face="monospace">
).rio.set_spatial_dims(x_dim="x", y_dim="y", inplace=True<br>
).rio.write_coordinate_system(inplace=True)</font></p>
<p><br>
</p>
<p>(DS is the xarray DataSet, and projected_epsg is the EPSG code
for the CRS used here)</p>
<p><br>
</p>
<p> <br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 07/10/2022 15:31, Even Rouault
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:226b35f8-55ff-4a66-19c0-f2c5efbf88bd@spatialys.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<p>Yes the netCDF driver in GDAL 3.4.2 is much stricter on what it
assumes to be axis compatible of a geotransform (there were
false positives now).</p>
<p>You can set the GDAL_NETCDF_IGNORE_XY_AXIS_NAME_CHECKS
configuration option or IGNORE_XY_AXIS_NAME_CHECKS open option
to YES to remove those new extra checks. See <a
class="moz-txt-link-freetext"
href="https://gdal.org/drivers/raster/netcdf.html"
moz-do-not-send="true">https://gdal.org/drivers/raster/netcdf.html</a></p>
<p>To have GDAL properly recognize the X/longitude &
Y/latitude axis as such, the
<a class="moz-txt-link-freetext"
href="https://cfconventions.org/Data/cf-conventions/cf-conventions-1.10/cf-conventions.html"
moz-do-not-send="true">https://cfconventions.org/Data/cf-conventions/cf-conventions-1.10/cf-conventions.html</a>
should be followed. So have long_name, standard_name and units
set on the variables associated with the dimensions such as<br>
</p>
<pre>float lat(lat) ;
lat:long_name = "latitude" ;
lat:units = "degrees_north" ;
lat:standard_name = "latitude" ;
float lon(lon) ;
lon:long_name = "longitude" ;
lon:units = "degrees_east" ;
lon:standard_name = "longitude" ;
or
</pre>
<pre> double y(y);
y:units = "km";
y:long_name = "y coordinate of projection";
y:standard_name = "projection_y_coordinate";
double x(x);
x:units = "km";
x:long_name = "x coordinate of projection";
x:standard_name = "projection_x_coordinate";
Even
</pre>
<div class="moz-cite-prefix">Le 07/10/2022 à 14:03, Micha Silver a
écrit :<br>
</div>
<blockquote type="cite"
cite="mid:4f7c73f2-4b41-aba5-594b-da549cbaa8be@gmail.com">
<p>Hello:</p>
<p>I'm using xarray and rioxarray in python to create a DataSet
then export to Netcdf. After saving, when I check the exported
files with gdalinfo using GDAL 3.2, I see the correct extent.
However, when using GDAL >=3.4 (i.e in a conda env) it
seems that the extents are lost, and the NetCDF dimensions
appear instead. This causes the resulting NetCDF to appear at
coords (0,0) - the wrong place - in QGIS (on a system with the
newer GDAL).<br>
</p>
<p><br>
</p>
<p>Here is the output with my system installed GDAL:</p>
<p><br>
</p>
<p><span><span>micha@RMS</span><span>:</span><span>Kinneret</span><span>$
gdalinfo --version </span><br>
GDAL 3.2.2, released 2021/03/05 <br>
<span>micha@RMS</span><span>:</span><span>Kinneret</span><span>$
gdalinfo NETCDF:"Kinneret_velocity.nc":v | grep -A 4
Corner </span><br>
Warning 1: dimension #2 (x) is not a Longitude/X dimension.
<br>
Warning 1: dimension #1 (y) is not a Latitude/Y dimension. <br>
Warning 1: dimension #0 (z) is not a Time or Vertical
dimension. <br>
Corner Coordinates: <br>
Upper Left ( 735758.000, 3644806.000) ( 35d31'15.70"E,
32d54'57.98"N) <br>
Lower Left ( 735758.000, 3621606.000) ( 35d30'54.46"E,
32d42'25.30"N) <br>
Upper Right ( 754558.000, 3644806.000) ( 35d43'18.74"E,
32d54'42.80"N) <br>
</span></p>
<p><span>Lower Right ( 754558.000, 3621606.000) (
35d42'55.82"E, 32d42'10.25"N) </span></p>
<p><span><span><br>
</span></span></p>
<p>However, in my conda environment, with a newer GDAL:<span><span><br>
</span></span></p>
<p><span><span><br>
</span></span></p>
<p><span><span>micha@RMS</span><span>:</span><span>Kinneret</span><span>$
conda activate geo </span><br>
(geo) <span>micha@RMS</span><span>:</span><span>Kinneret</span><span>$
gdalinfo --version </span><br>
GDAL 3.5.2, released 2022/09/02 <br>
(geo) <span>micha@RMS</span><span>:</span><span>Kinneret</span><span>$
gdalinfo NETCDF:"Kinneret_velocity.nc":v | grep -A 4
Corner </span><br>
Warning 1: dimension #2 (x) is not a Longitude/X dimension.
<br>
Warning 1: dimension #1 (y) is not a Latitude/Y dimension. <br>
Warning 1: dimension #0 (z) is not a Time or Vertical
dimension. <br>
Corner Coordinates: <br>
Upper Left ( 0.0, 0.0) <br>
Lower Left ( 0.0, 58.0) <br>
Upper Right ( 47.0, 0.0) <br>
Lower Right ( 47.0, 58.0)<br>
</span><br>
</p>
<p>What do I need to add to the xarray Dataset so that the newer
GDAL gets the correct extent?</p>
<p>In both cases all the "grid_mapping" metadata entries point
to "spatial_ref", and the full spatial_ref details are
available in the NetCDF file.</p>
<p><br>
</p>
<p>(Note: double posted to GIS.stackexchange at <a
class="moz-txt-link-freetext"
href="https://gis.stackexchange.com/questions/442323/changes-to-gdal-netcdf-driver-between-3-2-and-3-4"
moz-do-not-send="true">https://gis.stackexchange.com/questions/442323/changes-to-gdal-netcdf-driver-between-3-2-and-3-4</a>)<br>
</p>
<p><br>
</p>
<p>Thanks</p>
<pre class="moz-signature" cols="72">--
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918</pre>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
gdal-dev mailing list
<a class="moz-txt-link-abbreviated moz-txt-link-freetext" href="mailto:gdal-dev@lists.osgeo.org" moz-do-not-send="true">gdal-dev@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" moz-do-not-send="true">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" moz-do-not-send="true">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</blockquote>
<pre class="moz-signature" cols="72">--
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918</pre>
</body>
</html>