| 70 | The GDAL WKT Raster driver isn't able to load raster data yet. For this proposal, you'll have to use '''gdal2wktraster''' script. This loader script is included with the WKT Raster extension installation, under the ''scripts'' subdirectory. To check the syntax of the script, execute this command from ''$WKT_RASTER/scripts'' subdirectory: |
| 71 | |
| 72 | {{{ |
| 73 | >$ python gdal2wktraster.py --help |
| 74 | }}} |
| 75 | |
| 76 | '''Important:''' If you want to load raster data with out-db storage system, you'll have to apply [http://trac.osgeo.org/postgis/ticket/227 this patch] to the gdal2wktraster script. Please, take into account that this patch has not been included to the gdal2wktraster version on official WKT Raster extension. It's only a beta version. |
| 77 | |
| 78 | Example 1: |
| 79 | |
| 80 | Load [http://www.gis4free.org/gdal_wktraster_autotest/autotest/gdrivers/data/utm.tif this one-band grayscale image] (utm.tif) to PostGIS using loader script: |
| 81 | |
| 82 | {{{ |
| 83 | >$ python gdal2wktraster.py -r utm.tif -t utm -l 1 -k 100x100 -o utm.sql -s 26711 -I -M |
| 84 | }}} |
| 85 | |
| 86 | In this example, the script generates a SQL output (redirected to the file ''utm.sql''). This SQL code adds the image ''utm.tif'' to PostGIS, using a regular blocking arrangement with blocks of 100x100px. To execute the code, you must run this command as '''postgres''' user: |
| 87 | |
| 88 | {{{ |
| 89 | >$ psql -d <wktraster_database> -f utm.sql |
| 90 | }}} |
| 91 | |
| 92 | The ''wktraster_database'' must be a PostgreSQL database with PostGIS and WKT Raster extensions enabled. |
| 93 | |
| 94 | Example 2: |
| 95 | |
| 96 | Load [http://www.gis4free.org/gdal_wktraster_autotest/autotest/gdrivers/data/small_world.tif this RGB image] (small_world.tif) to PostGIS using loader script: |
| 97 | |
| 98 | {{{ |
| 99 | >$ python gdal2wktraster.py -r small_world.tif -t utm -l 1 -k 40x20 -o small_world.sql -s 4326 -I -M |
| 100 | }}} |
| 101 | |
| 102 | As in ''Example 1'', this code generates a SQL file, called ''small_world.sql'' with the SQL code to add the image ''small_world.tif'' to PostGIS using a regular blocking arrangement with blocks of 40x20px. To execute the code, as '''postgres''' user, run: |
| 103 | |
| 104 | {{{ |
| 105 | >$ psql -d <wktraster_database> -f small_world.sql |
| 106 | }}} |
| 107 | |
| 108 | |
| 109 | Example 3: |
| 110 | |
| 111 | Using the first image (utm.tif), let's create an overview of the image of half size in PostGIS. |
| 112 | |
| 113 | {{{ |
| 114 | >$ python gdal2wktraster.py -r utm.tif -t utm -l 2 -V -k 100x100 -o utm.sql -s 26711 -I -M |
| 115 | }}} |
| 116 | |
| 117 | The key concept here is the '''-V''' flag. This flag allows loader script to create a new table to store the overviews' metadata. If you want to load several images with overviews, you'll have to use this flag '''only the first time''' the loader script is called, to create the overviews' metadata table only once. |
| 118 | |
| 119 | The '''-l 2''' flag represents the overview level. 2 means an overview of the 50% of the original image size. |
| 120 | |
| 122 | |
| 123 | If you want to use the GDAL WKT Raster driver, you must provide a '''connection string''' as Dataset's name. The syntax of this connection string is (respect the quotes): |
| 124 | |
| 125 | |
| 126 | {{{ |
| 127 | PG":host='<host>' dbname='<dbname>' user='<user>' password='<password>' table='<raster_table>' [where='<sql_where>' mode='<working_mode>']" |
| 128 | }}} |
| 129 | |
| 130 | Note that the string, until the part that starts with "table='" is a libpq-style connection string. That means that you can change the order of these fields (dbname, user, password, host), or leave out unnecessary ones (like password, in some cases). But the rest of the connection string must have the syntax and order shown above. |
| 131 | |
| 132 | The "table" option requires the name of a WKT Raster table. This table only can be created by using the script gdal2tiles, from [http://trac.osgeo.org/postgis/wiki/WKTRaster WKTRaster code] |
| 133 | |
| 134 | The "where" option is used to filter the results of the raster table. Any SQL-WHERE expression is valid. The "mode" option is used to know the expected arrangement of the raster table. As the driver is currently working with only one table arrangement (regularly blocked tables), you can omit this option, or use it with value "REGULARLY_TILED_MODE". Otherwise, the driver won't work. |
| 135 | |
| 136 | You must use this dataset's format in all the gdal tools, like gdalinfo, gdal_translate, gdalwarp, etc. |
| 137 | |