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:

<VRTDataset rasterXSize="7102" rasterYSize="7102">

  <SRS>PROJCS[&quot;OSGB 1936 / British National Grid&quot;,GEOGCS[&quot;OSGB 1936&quot;,DATUM[&quot;OSGB_1936&quot;,SPHEROID[&quot;Airy 1830&quot;,6377563.396,299.3249612664953,AUTHORITY[&quot;EPSG&quot;,&quot;7001&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;6277&quot;]],PRIMEM[&quot;Greenwich&quot;,0],UNIT[&quot;degree&quot;,0.0174532925199433],AUTHORITY[&quot;EPSG&quot;,&quot;4277&quot;]],PROJECTION[&quot;Transverse_Mercator&quot;],PARAMETER[&quot;latitude_of_origin&quot;,49],PARAMETER[&quot;central_meridian&quot;,-2],PARAMETER[&quot;scale_factor&quot;,0.9996012717],PARAMETER[&quot;false_easting&quot;,400000],PARAMETER[&quot;false_northing&quot;,-100000],UNIT[&quot;metre&quot;,1,AUTHORITY[&quot;EPSG&quot;,&quot;9001&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;27700&quot;]]</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">

This entry was posted in Spatial and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s