2

I want to define no data values when working with gdal.BuildVRT(). According to the gdal.documentation http://gdal.org/python/osgeo.gdal-module.html, by creating a gdal.BuildVRTOptions (srcNodata=-99, VRTNodata=-99), I should be able force the gdal.BuiltVRT() to incorporate nodata values.

Yet, doing so as one can be seen below, does not work.

gdal.BuildVRT(file_open,None,srs_wkt,gdal.GRA_Bilinear,gdal.BuildVRTOptions (srcNodata=-99, VRTNodata=-99))

and I get an error message:

Traceback (most recent call last):
  File "/home/esaiet/Dropbox/Python_programing/Python_scripts/converting_porjection_vrt_II.py", line 45, in <module>
    vrt_ds=gdal.AutoCreateWarpedVRT(file_open,None,srs_wkt,gdal.GRA_Bilinear,gdal.BuildVRTOptions(srcNodata=None))
  File "/usr/local/lib/python3.6/dist-packages/GDAL-2.2.1-py3.6-linux-x86_64.egg/osgeo/gdal.py", line 2872, in AutoCreateWarpedVRT
    return _gdal.AutoCreateWarpedVRT(*args)
TypeError: in method 'AutoCreateWarpedVRT', argument 5 of type 'double'

What am I doing wrong?

2

Your arguments are incorrect, you have all positional args. There are only 2 positional args destName, srcDSOrSrcDSTab and the rest are keyword args, either ALL keyword=arg OR options=gdal.BuildVRTOptions() (possbly also a mix of keyword args and options="keyword=string" or ["a=list", "of=strings"] but not sure).

From the docs:

BuildVRT(destName, srcDSOrSrcDSTab, **kwargs)
source code 
Build a VRT from a list of datasets.
Arguments are :
  destName --- Output dataset name
  srcDSOrSrcDSTab --- an array of Dataset objects or filenames, or a Dataset object or a filename
Keyword arguments are :
  options --- return of gdal.InfoOptions(), string or array of strings
  other keywords arguments of gdal.BuildVRTOptions()
If options is provided as a gdal.BuildVRTOptions() object, other keywords are ignored. 

Try:

output_vrt = "" # empty string OR None OR /vsimem/in_memory.vrt OR /path/to/file.vrt
gdal.BuildVRT(output_vrt, file_open, options=gdal.BuildVRTOptions(outputSRS=srs_wkt, resampleAlg=gdal.GRA_Bilinear, srcNodata=-99, VRTNodata=-99))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.