<div dir="ltr">Hi Even, <div><br></div><div>Thanks for such a quick fix! Really really appreciate what you've done for the GDAL community! </div><div><br></div><div>Zhan. </div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Aug 31, 2020 at 8:32 PM Even Rouault <<a href="mailto:even.rouault@spatialys.com">even.rouault@spatialys.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>
<div style="font-family:monospace;font-size:9pt;font-weight:400;font-style:normal">
<p style="margin:0px;text-indent:0px">Zhan,</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">adding back the list</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">There was an issue in the writing code of the netCDF driver. It was supposed supposed to copy the offset and scale settings from the source dataset, but there was a logic error. Fixed per </p>
<p style="margin:0px;text-indent:0px"><a href="https://github.com/OSGeo/gdal/pull/2906" target="_blank">https://github.com/OSGeo/gdal/pull/2906</a></p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">Even</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">> Hi Even,</p>
<p style="margin:0px;text-indent:0px">> </p>
<p style="margin:0px;text-indent:0px">> Thanks a lot for your reply! Yes here in this example, scale_factor and</p>
<p style="margin:0px;text-indent:0px">> add_offset do not matter. I put them here just for demo purposes. In my</p>
<p style="margin:0px;text-indent:0px">> actual data (quite large), I'd like to use 1e-3 as scale factor but could</p>
<p style="margin:0px;text-indent:0px">> not write scale_factor into the metadata of netCDF via gdal_translate. Even</p>
<p style="margin:0px;text-indent:0px">> if I use VRT as an intermediate file and manually add scale_factor into the</p>
<p style="margin:0px;text-indent:0px">> VRT per band through "<MDI key="scale_factor">1e-3</MDI>". It still does</p>
<p style="margin:0px;text-indent:0px">> not work :(</p>
<p style="margin:0px;text-indent:0px">> </p>
<p style="margin:0px;text-indent:0px">> But it sounds like the implementation of the netCDF driver in GDAL has some</p>
<p style="margin:0px;text-indent:0px">> explicit tweak of metadata items? Like you said, valid_range is explicitly</p>
<p style="margin:0px;text-indent:0px">> discarded. Maybe scale_factor and add_offset and such are also part of</p>
<p style="margin:0px;text-indent:0px">> metadata items that the driver explicitly discards? In that case, I'll</p>
<p style="margin:0px;text-indent:0px">> stick to scale_factor=1 and add_offset=0. Not ideal though. Otherwise, this</p>
<p style="margin:0px;text-indent:0px">> loss of metadata items for netCDF files should count as a bug to be</p>
<p style="margin:0px;text-indent:0px">> reported?</p>
<p style="margin:0px;text-indent:0px">> </p>
<p style="margin:0px;text-indent:0px">> Zhan.</p>
<p style="margin:0px;text-indent:0px">> </p>
<p style="margin:0px;text-indent:0px">> On Mon, Aug 31, 2020 at 11:06 AM Even Rouault <<a href="mailto:even.rouault@spatialys.com" target="_blank">even.rouault@spatialys.com</a>></p>
<p style="margin:0px;text-indent:0px">> </p>
<p style="margin:0px;text-indent:0px">> wrote:</p>
<p style="margin:0px;text-indent:0px">> > On lundi 31 août 2020 00:11:54 CEST Zhan Li wrote:</p>
<p style="margin:0px;text-indent:0px">> > > Hi, when I use gdal_translate to convert a raster file (e.g., either</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > GTiff</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > > or VRT) into netCDF format, it always loses some important metadata</p>
<p style="margin:0px;text-indent:0px">> > > items</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > such as scale_factor, add_offset and etc. What am I doing it wrong? Can</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > anyone help me to solve this problem?</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > As scale_factor=1 and add_offset=0 in that dataset, they have no effect,</p>
<p style="margin:0px;text-indent:0px">> > and are thus not stored when converted to GeoTIFF.</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > valid_range is explicitly discarded from source metadata when converting</p>
<p style="margin:0px;text-indent:0px">> > into netCDF. I'm not completely sure of the rationale for that.</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > Even</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > --</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > Spatialys - Geospatial professional services</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > <a href="http://www.spatialys.com" target="_blank">http://www.spatialys.com</a></p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">-- </p>
<p style="margin:0px;text-indent:0px">Spatialys - Geospatial professional services</p>
<p style="margin:0px;text-indent:0px"><a href="http://www.spatialys.com" target="_blank">http://www.spatialys.com</a></p></div></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><a href="https://zhanlilz.github.io/" target="_blank">Zhan Li</a>, 李展; </div><div><a href="https://scholar.google.com/citations?user=JGNL9BoAAAAJ&hl=en" target="_blank">Google Scholar</a>, </div><div><a href="https://orcid.org/0000-0001-6307-5200" target="_blank">ORCID</a>, <a href="https://github.com/zhanlilz" target="_blank">Github</a>, </div><div><a href="https://twitter.com/zhanlilz" target="_blank">Twitter</a>, <a href="https://www.linkedin.com/in/zhanli/" target="_blank">LinkedIn</a></div></div></div></div></div></div>