# QGIS and Raster Mapping in 'Seamless' layer

I would like to use Ordnance Survey base mapping in QGIS. I would like to set up something like a seamless table in MapInfo. I think that the equivalent in QGIS is a Virtual Raster Table. The files are in tif format as they were when I download them.

I have built a VRT but it seems slow to load when I open the layer. I have also tried building pyramids for the data and this doesn't seem to speed it up that much.

Is there a way to speed this up? Am I missing something? Are there any good resources about steps to take to prepare raster data for use in QGIS?

Would I be best to start to load this information into a PostGIS database with PostGIS Raster installed?

-
In the last couple of days I've created two Rasterlite databases using OS OpenData raster imagery. Each one covered one 100 x 100 km OS grid square, the first (Vector Map District Rasters) using one hundred tiles and the second (Streetview) using four hundred tiles. I could talk you through doing this if you are interested. Nick. –  nhopton Apr 16 '12 at 16:09
That would be really useful to get the instructions on how to do that. I am thinking about adding them to a PostGIS database when I update my PostGIS to 2.0. –  James S Apr 18 '12 at 8:37
Okay James, which OS raster dataset will you be using? Just so that I can tailor the command lines to suit. Nick. –  nhopton Apr 18 '12 at 9:33
I am using VectorMap District Raster and also the StreetView rasters as well. Mainly interested in VectorMap District to start with. –  James S Apr 18 '12 at 12:46

Are the TIFs tiled? The OS Vector District raster images I have aren't. To find out using QGIS, load one of the rasters and select Information in the Raster menu. Click OK, and somewhere after the projection and metadata you should see a line something like: Band 1 Block=4000x65 Type=Byte, ColorInterp=Palette

If, as in this case the block size is the width of the image x some number of lines, then converting it to a tiled TIF can give you a good speedup in most cases. This is because we tend to want to look at rectangular areas of an image, and it avoids QGIS having to load an entire row of pixels only to discard most of them because they fall outside the view.

To do that, use the Translate menu item in the Raster menu. You can convert an entire directory, or just one file at a time. The key setting is the Creation Options which you should enable, and enter TILED for the name, and YES as the value. This defaults to a tile size of 256x256 which should be fine for most purposes, but it is possible to specify other sizes by adding BLOCKXSIZE and BLOCKYSIZE to the creation options and specifying the size you want.

When you tile your images, you will notice an increase in file size because the width and height of you image is probably not a multiple of the tile size. So with the OS Vector District raster the effective size will be 4096x4096, an increase of just under 5% of the file size, but QGIS and other tools will transparently treat it as 4000x4000.

-
Would building pyramids as well as tiling the images be beneficial? –  James S Jul 6 '11 at 11:47
Yes, absolutely. You may need to try different algorithms depending on your data, some produce better results than others. "nearest" is generally worst, "cubic" usually provides good results in a reasonable time, but you may find "cubic spline" or "lanczos" gives better results. I suggest you try the different algorithms on the same image and do a simple visual check in QGIS for whichever one looks the best. This is a fairly subjective thing though. –  MerseyViking Jul 6 '11 at 12:31

There are pre-compiled Rasterlite/Spatialite binaries for Windows (32 and 64-bit) so I took this route.

Step 1, install the software. For 32-bit Windows go here: http://www.gaia-gis.it/gaia-sins/windows-bin-x86/ or for 64-bit Windows go here: http://www.gaia-gis.it/gaia-sins/windows-bin-amd64/

Download (as a minimum) the following files and unzip them to a directory (I used C:/spatialite).

rasterlite_pyramid-1.1c-win-xxx.zip

rasterlite_topmost-1.1c-win-xxx.zip

spatialite-3.0.1-DLL-win-xxx.zip

spatialite_gui-1.5.0-stable-win-xxx.zip

You will also need a recent version of sqlite3.dll (the one that comes with OSGEO4W is too old), get it here: http://www.sqlite.org/sqlite-dll-win32-x86-3071100.zip

Unzip this to the C:/spatialite folder.

Step 2, prepare the raster images. OpenData rasters are indexed TIFFs with world files. To be loaded into a Rasterlite database these need to be batch converted to geotiffs. Do this in QGIS, Raster -> Conversion -> Translate. Use batch mode and (most important) tick 'Expand' and set 'RGB'.

Step 3, load the directory of GeoTIFFs into a Rasterlite database. Go to your C:/spatialite directory, click on spatialite_gui and then create a new spatialite database in the directory containing the GeoTIFFs, you could call this 'vmd.sqlite' for example.

Next, open a command line window in the directory containing the GeoTIFFs and type this command:

rasterlite_load -d vmd.sqlite -T vmd -D . -i wavelet -q 25

This should load all of the GeoTIFFs in the directory into vmd.sqlite, in a table called 'vmd'. It will take a while, but the progress will be reported.

Next, build pyramids:

rasterlite_pyramid -d vmd.sqlite -T vmd -i wavelet -v

When this finishes, set topmost:

rasterlite_topmost -d vmd.sqlite -T vmd -v

That should be it, load the new Rasterlite database into QGIS via Layer -> Add Raster Layer.

See: www.gaia-gis.it/gaia-sins/rasterlite-docs/rasterlite-how-to.pdf for more on Rasterlite.

In closing. You can download one of my Rasterlite VectorMap District (VMD) databases from here (about 500 KB):

http://dl.dropbox.com/u/45121071/vmd.sqlite