Skip to content

Commit 0296ee8

Browse files
[auxdata.DEMHandler.load] fixed ocean case where no DEM tiles are found. The previous approach with a dummy DEM spanning the whole globe seems to be no longer allowed with recent GDAL versions. A dumm DEM spanning the target extent is created instead.
1 parent cf33b48 commit 0296ee8

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

pyroSAR/auxdata.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -552,35 +552,33 @@ def __commonextent(self, buffer=None):
552552
return ext_new
553553

554554
@staticmethod
555-
def __create_dummy_dem():
555+
def __create_dummy_dem(filename, extent):
556556
"""
557-
Create a dummy file which spans the whole globe and is 1x1 pixels large to be as small as possible.
557+
Create a dummy file which spans the given extent and
558+
is 1x1 pixels large to be as small as possible.
558559
This file is used to create dummy DEMs over ocean.
559-
560-
Returns
561-
-------
562-
str
563-
the name of the file in the user's home directory: ~/.pyrosar/auxdata/dummy_dem.tif
564560
"""
565-
path = os.path.join(os.path.expanduser('~'), '.pyrosar', 'auxdata')
566-
os.makedirs(name=path, exist_ok=True)
567-
filename = os.path.join(path, 'dummy_dem.tif')
568-
if not os.path.isfile(filename):
569-
driver = gdal.GetDriverByName('GTiff')
570-
dataset = driver.Create(filename, 1, 1, 1, 1)
571-
geo = [-180, 360, 0, 90, 0, -180]
572-
dataset.SetGeoTransform(geo)
573-
dataset.SetProjection('EPSG:4326')
574-
band = dataset.GetRasterBand(1)
575-
band.SetNoDataValue(255)
576-
mat = numpy.zeros(shape=(1, 1))
577-
band.WriteArray(mat, 0, 0)
578-
band.FlushCache()
579-
del mat
580-
band = None
581-
dataset = None
582-
driver = None
583-
return filename
561+
driver = gdal.GetDriverByName('GTiff')
562+
dataset = driver.Create(filename, 1, 1, 1, 1)
563+
geo = [
564+
extent['xmin'],
565+
extent['xmax'] - extent['xmin'],
566+
0,
567+
extent['ymax'],
568+
0,
569+
extent['ymin'] - extent['ymax'] # negative
570+
]
571+
dataset.SetGeoTransform(geo)
572+
dataset.SetProjection('EPSG:4326')
573+
band = dataset.GetRasterBand(1)
574+
band.SetNoDataValue(255)
575+
mat = numpy.zeros(shape=(1, 1))
576+
band.WriteArray(mat, 0, 0)
577+
band.FlushCache()
578+
del mat
579+
band = None
580+
dataset = None
581+
driver = None
584582

585583
@staticmethod
586584
def intrange(extent, step):
@@ -1104,19 +1102,21 @@ def load(self, dem_type, vrt=None, buffer=None, username=None,
11041102
extent['ymax'] += shift_y
11051103

11061104
# special case where no DEM tiles were found because the AOI is completely over ocean
1107-
if len(locals) == 0:
1108-
if vrt is not None:
1109-
# define a dummy file as source file; this file contains one pixel spanning the whole globe
1110-
# this pixel has value 0, nodata value is 255
1111-
locals = [self.__create_dummy_dem()]
1112-
datatype = self.config[dem_type]['datatype'][product]
1113-
src_nodata = 0 # define the data value as nodata, so it can be overwritten in the VRT
1114-
if product == 'dem':
1115-
dst_nodata = 0
1116-
else:
1117-
dst_nodata = self.config[dem_type]['nodata'][product]
1118-
# determine the target resolution based on minimum latitude
1119-
resolution = self.__get_resolution(dem_type=dem_type, y=extent['ymin'])
1105+
if len(locals) == 0 and vrt is not None:
1106+
# define a dummy file as source file
1107+
# his file contains one pixel with a value of 0
1108+
# nodata value is 255
1109+
tif = vrt.replace('.vrt', '_tmp.tif')
1110+
self.__create_dummy_dem(filename=tif, extent=extent)
1111+
locals = [tif]
1112+
datatype = self.config[dem_type]['datatype'][product]
1113+
src_nodata = 0 # define the data value as nodata, so it can be overwritten in the VRT
1114+
if product == 'dem':
1115+
dst_nodata = 0
1116+
else:
1117+
dst_nodata = self.config[dem_type]['nodata'][product]
1118+
# determine the target resolution based on minimum latitude
1119+
resolution = self.__get_resolution(dem_type=dem_type, y=extent['ymin'])
11201120

11211121
# make sure all GETASSE30 tiles get an ENVI HDR file so that they are GDAL-readable
11221122
if dem_type == 'GETASSE30':

0 commit comments

Comments
 (0)