| 1 | When you have a set of raster that are a mosaic. If really useful a catalogue to use all ads un unique raster. |
| 2 | Qgis is capable to use the VirtualCatalog of gdal.[[BR]] |
| 3 | To create a catalogue (on windows) usable from qgis 1.9, you can create a file ascii with a list of all the raster with their paths. Like this:[[BR]] |
| 4 | |
| 5 | {{{ |
| 6 | D:\dati\folder1\folder2\folder_11\raster_1.tif |
| 7 | D:\dati\folder1\folder2\folder_12\raster_2.tif |
| 8 | D:\dati\folder1\folder2\folder_13\raster_3.tif |
| 9 | D:\dati\folder1\folder2\folder_13\raster_4.tif |
| 10 | D:\dati\folder1\folder2\folder_13\raster_5.tif |
| 11 | ... |
| 12 | }}} |
| 13 | (save the file as "my_list.txt for example) |
| 14 | [[BR]] |
| 15 | |
| 16 | Please, notice that every raster could be on distinct path.[[BR]] |
| 17 | To create the catalog use this call.[[BR]] |
| 18 | |
| 19 | gdalbuildvrt.exe -resolution average -allow_projection_difference -addalpha -hidenodata -input_file_list my_list.txt -overwrite my_catalog.vrt [[BR]] |
| 20 | |
| 21 | After the catalog is create it could be used from qgs. But the gdalbuildvrt don't compute the statistics of the rasters in the catalogue and unfortunately qgis, |
| 22 | if detect that the stats are not available in the catalog, try to compute they for each raster (ouch!). If the rasters are huge and on a shared remote folder. This step could be more time expensive.[[BR]] |
| 23 | So is really a good idea to add the stats to the catalogue before use it on qgis :)[[BR]] |
| 24 | Qgis really need only of min/max nothing else. Also to speed up this step you could use without any problem an approximated stats computing.[[BR]] |
| 25 | To add this approx-stats to the gdal you can use this simple and smart python code:[[BR]] |
| 26 | |
| 27 | [Thanks to Giuseppe Sucameli & Faunalia for this smart code] |
| 28 | |
| 29 | {{{ |
| 30 | #!/usr/bin/env python |
| 31 | |
| 32 | from osgeo import gdal |
| 33 | from gdalconst import * |
| 34 | |
| 35 | def main( path, approx ): |
| 36 | ds = gdal.Open( path, GA_ReadOnly ) |
| 37 | if ds is None: |
| 38 | return "Unable to open", path |
| 39 | |
| 40 | for i in range(ds.RasterCount): |
| 41 | band = ds.GetRasterBand(i+1) |
| 42 | band.ComputeStatistics( approx ) |
| 43 | |
| 44 | ds = None |
| 45 | |
| 46 | if __name__ == "__main__": |
| 47 | import sys |
| 48 | |
| 49 | approx = False |
| 50 | path = "" |
| 51 | |
| 52 | for i in range( len(sys.argv) ): |
| 53 | if i == 0: |
| 54 | continue |
| 55 | |
| 56 | if sys.argv[i].lower() == "-approx": |
| 57 | approx = True |
| 58 | else: |
| 59 | path = sys.argv[i] |
| 60 | break |
| 61 | |
| 62 | if path == "": |
| 63 | print "Usage:", sys.argv[0], "[-approx] <datasource>" |
| 64 | sys.exit(0) |
| 65 | |
| 66 | main( path, approx ) |
| 67 | }}} |
| 68 | |
| 69 | Save it as "computestat.py" and use it with this sintax:[[BR]] |
| 70 | computestats.py -approx my_catalog.vrt |
| 71 | |
| 72 | et voila! |
| 73 | Now QGis start fast and smart using the raster catalogue |
| 74 | [[BR]] |
| 75 | |
| 76 | Happy catalog-ing |
| 77 | [[BR]] |
| 78 | Andrea Peri |
| 79 | |
| 80 | ------ |
| 81 | |