Building GDAL to support wildcards
Building GDAL to support wildcards
Earlier today, I was attempting to use the gdalbuildvrt utility function to create a virtual spatial datasource that combined a set of GeoTIFFs in a directory. The GeoTIFF files formed a set of perfectly tessellating images, from which I wanted to create a single tile layer to overlay on Bing Maps. If I’d have attempted to cut tiles from each GeoTIFF separately, I’d have been left with lots of separate layers – each containing unwanted edges. Alternatively, if I’d have stitched all the GeoTIFFs together first, I’d have to deal with one enormous, unwieldy image, several Gb in size.
So, the VRT virtual datasource sounded like a good idea – it would provide the convenience of operating on the set of GeoTIFFS as if they’d have been one single contiguous image, but without the overhead of having to actually create that behemoth file. The benefits of my proposed approach are confirmed in the performance measurements given in this article.
Unfortunately, I fell at the first hurdle when I got this error with only the most basic of gdalbuildvrt usage:
The error stated ERROR 4: ‘*.tif’’ does not exist in the file system, and is not recognised as a supported dataset name. Followed by Warning 1: Can’t open *.tif. Skipping it.
There were most definitely TIFF files in this directory, saved with the .tif file extension. Removing the asterisk wildcard and pointing at a manual list of files worked ok, so what was wrong with the syntax of *.tif ?
The answer is that if, like me, you built your GDAL from source, it is not configured by default to support wildcard expansion. To fix this, you have to edit GDAL’s nmake.opt file and, at line 155, insert the path to the setargv.obj of your Visual C installation. On my computer, this is installed in the default location of C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\setargv.obj. However, to make it a little trickier, you have to use the 8.3 short filename reference to this file. So, I changed my nmake.opt file to include the following line:
SETARGV = “C:\PROGRA~2\MICROS~1.0\VC\lib\setargv.obj”
(Note that following the comments in the file about setting the VCDIR and then providing a relative path didn’t work for me – SETARGV needed to be a complete absolute path to setargv.obj).
Then, rebuilding the project and trying again, and I was good to go:
And, an extract from the created merged.vrt file: