[gdal-dev] ERROR 4 while using gdalwarp to mosaic and resample multiple ASTGTM zipped tiffs

Panagiotis Sismanidis panosis at noa.gr
Mon Jun 15 03:01:43 PDT 2020


Hi,

I have prepared a python script that uses gdalwarp to mosaic and resample
ASTER DEM tiles, using as arguments the bounding box lat/lon coordinates
and the width and height of the output Gtiff. It works fine, except when I
use a quite large bbox (e.g. whole of Europe) where I get the gdal errors I
include below. If I split my bbox in two and iteratively run the script
there are no errors, all the tiffs are recognized without any issues, and
the process completes successfully. Do you know what can cause this weird
problem? Is it because of gdal or the OS?

The bbox coords (latS, lonW, latN, LonE) and the width and height that
gives me these errors are (29.94, -10.55, 61.18, 31.38), 4194 and 3125,
respectively.

I use python 3.6.7, gdal 2.2.3 and Ubuntu 18.04.4.

Thank you in advance for your help!

Errors:
=====
    ERROR 4:
`/vsizip//DATA/ASTER_GDEM_v3/ASTGTMV003_N45E009.zip/ASTGTMV003_N45E009_dem.tif'
not recognized as a supported file format.
    ERROR 4:
`/vsizip//DATA/ASTER_GDEM_v3/ASTGTMV003_N54E011.zip/ASTGTMV003_N54E011_dem.tif'
not recognized as a supported file format.
    ERROR 4:
`/vsizip//DATA/ASTER_GDEM_v3/ASTGTMV003_N34E033.zip/ASTGTMV003_N34E033_dem.tif'
not recognized as a supported file format.
    ERROR 4:
`/vsizip//DATA/ASTER_GDEM_v3/ASTGTMV003_N48E019.zip/ASTGTMV003_N48E019_dem.tif'
not recognized as a supported file format.
    ERROR 4:
`/vsizip//DATA/ASTER_GDEM_v3/ASTGTMV003_N51E006.zip/ASTGTMV003_N51E006_dem.tif'
not recognized as a supported file format.
    Traceback (most recent call last):
      File "/home/USER/gdalwarp_ASTGTM_tiles_inside_bbox.py", line 127, in
<module>
        warp_ASTGTM_tiles(args.savename, args.bbox, args.width,
args.height, args.method)
      File "/home/USER/gdalwarp_ASTGTM_tiles_inside_bbox.py", line 107, in
warp_ASTGTM_tiles
        gdal.Warp(savename, DEM_tiles_bbox, options=warp_options)
      File "/usr/lib/python3/dist-packages/osgeo/gdal.py", line 580, in Warp
        return wrapper_GDALWarpDestName(destNameOrDestDS, srcDSTab, opts,
callback, callback_data)
      File "/usr/lib/python3/dist-packages/osgeo/gdal.py", line 3112, in
wrapper_GDALWarpDestName
        return _gdal.wrapper_GDALWarpDestName(*args)
    SystemError: <built-in function wrapper_GDALWarpDestName> returned NULL
without setting an error


My function is the following:
===================

def warp_ASTGTM_tiles(savename, bbox, width, height, resampling_method):

    bound_S = math.trunc(bbox[0])
    bound_W = math.trunc(bbox[1])
    bound_N = math.ceil(bbox[2])
    bound_E = math.ceil(bbox[3])

    ASTGTM_zips = Path(ASTGTM_DATADIR).glob("*.zip")

    ASTGTM_zips_bbox = []

    for zipf in ASTGTM_zips:
        if re.match(ASTGTM_REGX, zipf.name):
            tile_lat, tile_lon = get_tile_loc(zipf.name)
            if (tile_lat >= bound_S and tile_lat <= bound_N and
                tile_lon >= bound_W and tile_lon <= bound_E):
                ASTGTM_zips_bbox.append(zipf)

    if len(ASTGTM_zips_bbox) == 0:
        raise SystemExit("No tiles are available for given bbox")

    DEM_tiles_bbox = []

    for zipf in ASTGTM_zips_bbox:
        with zipfile.ZipFile(zipf, "r") as zp:
            dem = zipf.stem + "_dem.tif"
            DEM_tiles_bbox.append(gdal.Open(f"/vsizip/{str(zipf)}/{dem}"))

    warp_options = gdal.WarpOptions(
        format="GTiff",
        outputBounds=(bbox[1], bbox[0], bbox[3], bbox[2]),
        outputBoundsSRS=WGS84_PROJ,
        srcSRS=DEM_tiles_bbox[0].GetProjection(),
        dstSRS=WGS84_PROJ,
        width=width,
        height=height,
        srcNodata=0,
        dstNodata=0,
        resampleAlg=METHODS[resampling_method],
    )

    gdal.Warp(savename, DEM_tiles_bbox, options=warp_options)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20200615/38e0c954/attachment.html>


More information about the gdal-dev mailing list