|
1 | 1 | ############################################################################### |
2 | 2 | # tools for handling auxiliary data in software pyroSAR |
3 | 3 |
|
4 | | -# Copyright (c) 2019-2024, the pyroSAR Developers. |
| 4 | +# Copyright (c) 2019-2025, the pyroSAR Developers. |
5 | 5 |
|
6 | 6 | # This file is part of the pyroSAR Project. It is subject to the |
7 | 7 | # license terms in the LICENSE.txt file found in the top-level |
@@ -552,35 +552,33 @@ def __commonextent(self, buffer=None): |
552 | 552 | return ext_new |
553 | 553 |
|
554 | 554 | @staticmethod |
555 | | - def __create_dummy_dem(): |
| 555 | + def __create_dummy_dem(filename, extent): |
556 | 556 | """ |
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. |
558 | 559 | 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 |
564 | 560 | """ |
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 |
584 | 582 |
|
585 | 583 | @staticmethod |
586 | 584 | def intrange(extent, step): |
@@ -1104,19 +1102,21 @@ def load(self, dem_type, vrt=None, buffer=None, username=None, |
1104 | 1102 | extent['ymax'] += shift_y |
1105 | 1103 |
|
1106 | 1104 | # 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']) |
1120 | 1120 |
|
1121 | 1121 | # make sure all GETASSE30 tiles get an ENVI HDR file so that they are GDAL-readable |
1122 | 1122 | if dem_type == 'GETASSE30': |
@@ -1513,5 +1513,8 @@ def vrt_check_sources(fname): |
1513 | 1513 | tree = etree.parse(fname) |
1514 | 1514 | sources = [x.text for x in tree.findall('.//SourceFilename')] |
1515 | 1515 | for source in sources: |
| 1516 | + if not os.path.isabs(source): |
| 1517 | + base_dir = os.path.dirname(fname) |
| 1518 | + source = os.path.normpath(os.path.join(base_dir, source)) |
1516 | 1519 | if not os.path.isfile(source): |
1517 | 1520 | raise RuntimeError(f'missing VRT source file: {source}') |
0 commit comments