Monday 7 September 2009

Raster index datasets in SharpMap

In my previous post I eluded to the fact that it was possible to use SharpMap 'out of the box' to render raster index datasets (tiles). About a year ago I remember trying to get SharpMap to do just that and came to the conclusion that unless i wanted to use some kind of web based tile server, I would have to invest a lot of time creating a new type of layer, perhaps based loosely on the TiledWmsLayer, but specifically for loading large raster tile datasets from disk.

Turns out I didnt need to do any of that.

GdalRasterLayer supports many different raster formats. One that I was unfamiliar with until recently was its own virtual dataset format. This is basically an xml file that, among other things, can pull together several raster files and treat them as a single dataset. You can build one of these very easily by doing something like:
gdalbuildvrt rasterIndex.vrt *.tif
Now, because vrt files are just another format supported by gdal, you can load them straight in using the GdalRasterLayer like so:
GdalRasterLayer layer = new GdalRasterLayer("MyRasterIndex", "rasterIndex.vrt");
And because the GdalRasterLayer is pretty smart at what it does, it will only read the pixels that it needs, meaning it's pretty efficient in terms of its speed and memory usage.

No comments:

Post a Comment