Skip to content

Commit

Permalink
[DEMHandler] apply file lock to VRTs
Browse files Browse the repository at this point in the history
  • Loading branch information
johntruckenbrodt committed Sep 17, 2024
1 parent db1eae8 commit 6122ff9
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions pyroSAR/auxdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def __find_first(self, dem_type, product):
@staticmethod
def __buildvrt(tiles, vrtfile, pattern, vsi, extent, src_nodata=None,
dst_nodata=None, hide_nodata=False, resolution=None,
tap=True, dst_datatype=None):
tap=True, dst_datatype=None, lock_timeout=600):
"""
Build a VRT mosaic from DEM tiles. The VRT is cropped to the specified `extent` but the pixel grid
of the source files is preserved and no resampling/shifting is applied.
Expand Down Expand Up @@ -510,6 +510,8 @@ def __buildvrt(tiles, vrtfile, pattern, vsi, extent, src_nodata=None,
dst_datatype: int or str or None
the VRT data type as supported by :class:`spatialist.raster.Dtype`.
Default None: use the same data type as the source files.
lock_timeout: int
how long to wait to acquire a lock on `vrtfile`?
Returns
-------
Expand All @@ -534,14 +536,16 @@ def __buildvrt(tiles, vrtfile, pattern, vsi, extent, src_nodata=None,
opts['VRTNodata'] = dst_nodata
opts['outputBounds'] = (extent['xmin'], extent['ymin'],
extent['xmax'], extent['ymax'])
gdalbuildvrt(src=locals, dst=vrtfile, **opts)
if dst_datatype is not None:
datatype = Dtype(dst_datatype).gdalstr
tree = etree.parse(source=vrtfile)
band = tree.find(path='VRTRasterBand')
band.attrib['dataType'] = datatype
tree.write(file=vrtfile, pretty_print=True,
xml_declaration=False, encoding='utf-8')
with Lock(vrtfile, timeout=lock_timeout):
if not os.path.isfile(vrtfile):
gdalbuildvrt(src=locals, dst=vrtfile, **opts)
if dst_datatype is not None:
datatype = Dtype(dst_datatype).gdalstr
tree = etree.parse(source=vrtfile)
band = tree.find(path='VRTRasterBand')
band.attrib['dataType'] = datatype
tree.write(file=vrtfile, pretty_print=True,
xml_declaration=False, encoding='utf-8')

def __commonextent(self, buffer=None):
"""
Expand Down Expand Up @@ -1057,7 +1061,7 @@ def load(self, dem_type, vrt=None, buffer=None, username=None,
bounding box of the geometries is expanded so that the coordinates are
multiples of the tile size of the respective DEM option.
lock_timeout: int
how long to wait to acquire a lock on downloaded files?
how long to wait to acquire a lock on the downloaded files and `vrt`?
Returns
-------
Expand Down Expand Up @@ -1153,7 +1157,8 @@ def load(self, dem_type, vrt=None, buffer=None, username=None,
src_nodata=src_nodata, dst_nodata=dst_nodata,
hide_nodata=True,
resolution=resolution,
tap=tap, dst_datatype=datatype)
tap=tap, dst_datatype=datatype,
lock_timeout=lock_timeout)
else:
return locals

Expand Down

0 comments on commit 6122ff9

Please sign in to comment.