Skip to content

Commit

Permalink
Merge pull request #572 from UKEODHP/improve-netcdf-support
Browse files Browse the repository at this point in the history
Handling of NetCDF Data
  • Loading branch information
constantinius authored Jul 12, 2024
2 parents 7fbe3e1 + d5ea0ab commit f9c8a21
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions eoxserver/contrib/gdal.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,10 @@ def config_env(env, fail_on_override=False, reset_old=True):

def open_with_env(path, env, shared=True):
with config_env(env, False):
# if attempting to load NETCDF file with additional indexing, need to extract only base path
# this loads the variable dataset and allows information to be extracted from first band
if "NETCDF" in path:
if ("https://" in path and path.count(":") == 4) or (not "https://" in path and path.count(":") == 3):
splitpath = path.rsplit(":",1)
path = splitpath[0]
return OpenShared(path) if shared else Open(path)
13 changes: 13 additions & 0 deletions eoxserver/render/mapserver/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,19 @@ def _create_raster_layer_objs(map_obj, extent, sr, data, filename_generator, env
layer_obj.type = ms.MS_LAYER_RASTER
layer_obj.status = ms.MS_ON

# if attempting to load NETCDF file, need to use a temporary file to extract only
# the required band data
if "NETCDF" in data:
# determine if attempting to load a specific band index
if ("https://" in data and data.count(":") == 4) or (not "https://" in data and data.count(":") == 3):
splitpath = data.rsplit(":",1)
data = splitpath[0]
index = int(splitpath[1]) + 1
temp_path = filename_generator.generate()
# extract only desired index to new temporary file
gdal.Translate(temp_path, data, bandList=[index])
data = temp_path

layer_obj.data = data
# assumption that RGBA already has transparency in alpha band
if browse_mode != BROWSE_MODE_RGBA:
Expand Down

0 comments on commit f9c8a21

Please sign in to comment.