From 6a8b1b05c9179cf50b685665a8c02292ee0f1607 Mon Sep 17 00:00:00 2001 From: Trey Stafford Date: Tue, 8 Aug 2023 10:32:58 -0600 Subject: [PATCH 1/3] Fix geoid and gravity anomaly layers' nodata value in overviews The given nodata value is not set correctly in the overviews. Use -9999 instead, which does get set correctly. ``` In [2]: from osgeo import gdal In [3]: ds = gdal.Open('/share/appdata/qgreenland/working-storage/wip-layers/geoid/04-command-build_overviews/ggeoid16.tif') In [4]: band = ds.GetRasterBand(1); In [5]: band Out[5]: > In [8]: band.GetOverview(2) Out[8]: > In [9]: band.GetOverview(2).ReadAsArray() Out[9]: array([[1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ..., 1.70141001e+38, 1.70141001e+38, 1.70141001e+38], [1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ..., 1.70141001e+38, 1.70141001e+38, 1.70141001e+38], [1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ..., 1.70141001e+38, 1.70141001e+38, 1.70141001e+38], ..., [1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ..., 1.70141001e+38, 1.70141001e+38, 1.70141001e+38], [1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ..., 1.70141001e+38, 1.70141001e+38, 1.70141001e+38], [1.70141001e+38, 1.70141001e+38, 1.70141001e+38, ..., 1.70141001e+38, 1.70141001e+38, 1.70141001e+38]]) In [20]: band.GetOverview(2).ReadAsArray().dtype Out[20]: dtype('float64') In [21]: band.ReadAsArray().dtype Out[21]: dtype('float64') In [22]: band.GetOverview(2).ReadAsArray()[0, 0] Out[22]: 1.701410009187828e+38 In [23]: band.ReadAsArray()[0, 0] Out[23]: 1.70141e+38 In [24]: overview_nodata = band.GetOverview(2).ReadAsArray()[0, 0] In [25]: data_nodata = band.ReadAsArray()[0, 0] In [26]: overview_nodata == data_nodata Out[26]: False In [27]: overview_nodata < data_nodata Out[27]: False In [28]: overview_nodata > data_nodata Out[28]: True In [29]: overview_nodata Out[29]: 1.701410009187828e+38 In [30]: int(overview_nodata) Out[30]: 170141000918782798866653488190622531584 In [31]: int(data_nodata) Out[31]: 170141000000000007096036300471486382080 ``` --- qgreenland/config/cfg-lock.json | 6 ++++++ qgreenland/config/helpers/layers/gravity_anomalies_geoid.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/qgreenland/config/cfg-lock.json b/qgreenland/config/cfg-lock.json index 338030b3..a00a85a6 100644 --- a/qgreenland/config/cfg-lock.json +++ b/qgreenland/config/cfg-lock.json @@ -18394,6 +18394,8 @@ "EPSG:3413", "-r", "bilinear", + "-dstnodata", + "-9999", "-tr", "2000", "2000", @@ -18485,6 +18487,8 @@ "EPSG:3413", "-r", "bilinear", + "-dstnodata", + "-9999", "-tr", "2000", "2000", @@ -18576,6 +18580,8 @@ "EPSG:3413", "-r", "bilinear", + "-dstnodata", + "-9999", "-tr", "2000", "2000", diff --git a/qgreenland/config/helpers/layers/gravity_anomalies_geoid.py b/qgreenland/config/helpers/layers/gravity_anomalies_geoid.py index 5a1dcc04..6bbbe433 100644 --- a/qgreenland/config/helpers/layers/gravity_anomalies_geoid.py +++ b/qgreenland/config/helpers/layers/gravity_anomalies_geoid.py @@ -38,6 +38,11 @@ def _make_layer( input_file="{input_dir}/" + filename, output_file="{output_dir}/" + filename, reproject_args=[ + # The source nodata value is 1.70141e+38. This value is not + # correctly set in the overviews (added in the step below), + # so override it here as -9999. + "-dstnodata", + "-9999", # Source data is 0.02x-0.02 degrees resolution. Rene noted in # his email to QGreenland on 2021-01-22 that the geoid and # gravity anomaly grids are 2km resolution. From eb923b4e0a36891bde8f840aa1f7dc7e6e756f09 Mon Sep 17 00:00:00 2001 From: Trey Stafford Date: Tue, 8 Aug 2023 10:38:51 -0600 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea0cc582..c103e27a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -177,6 +177,11 @@ - Switch back to `.qgs` project file from `.qgz`; There is [an issue](https://github.com/qgis/QGIS/issues/42033) conveniently opening `.qgz` project files in OSX for some versions of QGIS `3.16.x`. +- Fix issue with "Geophysics/" layers displaying nodata values at some zoom + levels: + - "Bouguer gravity anomaly (2km)" + - "Faye (free-air) gravity anomaly (2km)" + - "Geoid model (2km)" # v2.0.0rc6 (2022-03-17) From 969a0f6c708490540f90d84836736f13dfcc35d1 Mon Sep 17 00:00:00 2001 From: Trey Stafford Date: Tue, 8 Aug 2023 11:10:07 -0600 Subject: [PATCH 3/3] Add reference to gdal issue --- qgreenland/config/helpers/layers/gravity_anomalies_geoid.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qgreenland/config/helpers/layers/gravity_anomalies_geoid.py b/qgreenland/config/helpers/layers/gravity_anomalies_geoid.py index 6bbbe433..321c1dcb 100644 --- a/qgreenland/config/helpers/layers/gravity_anomalies_geoid.py +++ b/qgreenland/config/helpers/layers/gravity_anomalies_geoid.py @@ -40,7 +40,8 @@ def _make_layer( reproject_args=[ # The source nodata value is 1.70141e+38. This value is not # correctly set in the overviews (added in the step below), - # so override it here as -9999. + # so override it here as -9999. See + # https://github.com/OSGeo/gdal/issues/8187. "-dstnodata", "-9999", # Source data is 0.02x-0.02 degrees resolution. Rene noted in