Changes between Initial Version and Version 1 of CatalogueForQIS


Ignore:
Timestamp:
Feb 28, 2012, 12:38:44 PM (12 years ago)
Author:
aperi2007
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CatalogueForQIS

    v1 v1  
     1When you have a set of raster that are a mosaic. If really useful a catalogue to use all ads un unique raster.
     2Qgis is capable to use the VirtualCatalog of gdal.[[BR]]
     3To 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{{{
     6D:\dati\folder1\folder2\folder_11\raster_1.tif
     7D:\dati\folder1\folder2\folder_12\raster_2.tif
     8D:\dati\folder1\folder2\folder_13\raster_3.tif
     9D:\dati\folder1\folder2\folder_13\raster_4.tif
     10D:\dati\folder1\folder2\folder_13\raster_5.tif
     11...
     12}}}
     13(save the file as "my_list.txt for example)
     14[[BR]]
     15
     16Please, notice that every raster could be on distinct path.[[BR]]
     17To create the catalog use this call.[[BR]]
     18
     19gdalbuildvrt.exe -resolution average -allow_projection_difference -addalpha -hidenodata -input_file_list my_list.txt -overwrite my_catalog.vrt [[BR]]
     20
     21After 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,
     22if 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]]
     23So is really a good idea to add the stats to the catalogue before use it on qgis :)[[BR]]
     24Qgis 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]]
     25To 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
     32from osgeo import gdal
     33from gdalconst import *
     34
     35def 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
     46if __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
     69Save it as "computestat.py" and use it with this sintax:[[BR]]
     70computestats.py -approx my_catalog.vrt
     71
     72et voila!
     73Now QGis start fast and smart using the raster catalogue
     74[[BR]]
     75
     76Happy catalog-ing
     77[[BR]]
     78Andrea Peri
     79
     80------
     81