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:
<VRTDataset rasterXSize="7102" rasterYSize="7102"> <SRS>PROJCS["OSGB 1936 / British National Grid",GEOGCS["OSGB 1936",DATUM["OSGB_1936",SPHEROID["Airy 1830",6377563.396,299.3249612664953,AUTHORITY["EPSG","7001"]],AUTHORITY["EPSG","6277"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4277"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",49],PARAMETER["central_meridian",-2],PARAMETER["scale_factor",0.9996012717],PARAMETER["false_easting",400000],PARAMETER["false_northing",-100000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","27700"]]</SRS> <GeoTransform> 5.2499964798648271e+005, 7.0402703463812999e-001, 0.0000000000000000e+000, 2.0500035201351732e+005, 0.0000000000000000e+000,-7.0402703463812999e-001</GeoTransform> <VRTRasterBand dataType="Byte" band="1"> ... ... </VRTDataset>