| 188 | |
| 189 | Bborie: A proposed implementation of the ST_AsTIFF functions. |
| 190 | |
| 191 | The TIFF format is probably the most robust available for converting rasters to GDAL rasters. Not only does it support all PostGIS Raster pixel types, it also provides plenty of creation options and possibly no issues with the number of bands. The only limitation found is that there can only be one NODATA value for all bands. |
| 192 | |
| 193 | The next three functions are the most basic of the ST_AsTIFF functions. |
| 194 | |
| 195 | 1. ST_AsTIFF(rast raster, options text[], srs text) -> bytea |
| 196 | |
| 197 | The most generic version of this function. All other ST_AsTIFF functions call this function. |
| 198 | |
| 199 | This function will check that all bands of the raster to be converted has the same NODATA value. If there are more than one possible NODATA values, a WARNING will be raised and the output TIFF will use the NODATA value of the last band with a NODATA value. |
| 200 | |
| 201 | options: the GDAL creation options found in the Creation Options section of the GDAL TIFF driver |
| 202 | |
| 203 | srs: the user-specified OGC WKT or the proj4 text for a spatial reference to embed in the GDAL raster. TIFF is one of the formats that supports embedding the spatial reference within the image file. |
| 204 | |
| 205 | {{{ |
| 206 | ST_AsTIFF(rast, ARRAY['COMPRESS=DEFLATE', 'ZLEVEL=9'], '+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') |
| 207 | |
| 208 | ST_AsTIFF(rast, ARRAY['COMPRESS=DEFLATE', 'ZLEVEL=9'], 'PROJCS["NAD83 / California Albers",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Albers_Conic_Equal_Area"],PARAMETER["standard_parallel_1",34],PARAMETER["standard_parallel_2",40.5],PARAMETER["latitude_of_center",0],PARAMETER["longitude_of_center",-120],PARAMETER["false_easting",0],PARAMETER["false_northing",-4000000],AUTHORITY["EPSG","3310"],AXIS["X",EAST],AXIS["Y",NORTH]]') |
| 209 | }}} |
| 210 | |
| 211 | 2. ST_AsTIFF(rast raster, options text[]) -> bytea |
| 212 | |
| 213 | This one removes the user-specified srs argument. The output TIFF's spatial reference will be set to the same as the input raster, if possible. |
| 214 | |
| 215 | {{{ |
| 216 | ST_AsTIFF(rast, ARRAY['COMPRESS=DEFLATE', 'ZLEVEL=9']) |
| 217 | }}} |
| 218 | |
| 219 | 3. ST_AsTIFF(rast raster) -> bytea |
| 220 | |
| 221 | The simplest implementation of this function. Since the options argument has been removed, the output TIFF will be created with default options. Like the prior function, the spatial reference of the TIFF will be set to the same as the input raster. |
| 222 | |
| 223 | {{{ |
| 224 | ST_AsTIFF(rast) |
| 225 | }}} |
| 226 | |
| 227 | |
| 228 | The next three functions add a band index argument to filter the raster's bands before generating the output TIFF. |
| 229 | |
| 230 | 4. ST_AsTIFF(rast raster, nbands int[], options text[], srs text) -> bytea |
| 231 | |
| 232 | {{{ |
| 233 | ST_AsTIFF(rast, ARRAY[3,1,2], ARRAY['COMPRESS=DEFLATE', 'ZLEVEL=9'], '+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') |
| 234 | }}} |
| 235 | |
| 236 | 5. ST_AsTIFF(rast raster, nbands int[], options text[]) -> bytea |
| 237 | |
| 238 | This one removes the user-specified srs argument. The output TIFF's spatial reference will be set to the same as the input raster, if possible. |
| 239 | |
| 240 | {{{ |
| 241 | ST_AsTIFF(rast, ARRAY[3,1,2], ARRAY['COMPRESS=DEFLATE', 'ZLEVEL=9']) |
| 242 | }}} |
| 243 | |
| 244 | 6. ST_AsTIFF(rast raster, nbands int[]) -> bytea |
| 245 | |
| 246 | Since the options argument has been removed, the output TIFF will be created with default options. Like the prior function, the spatial reference of the TIFF will be set to the same as the input raster. |
| 247 | |
| 248 | {{{ |
| 249 | ST_AsTIFF(rast, ARRAY[3,1,2]) |
| 250 | }}} |
| 251 | |
| 252 | |
| 253 | The next two functions add a compression argument. If the compression desired is JPEG or DEFLATE, the user can specify a quality as part of the compression string. |
| 254 | |
| 255 | Examples are: |
| 256 | |
| 257 | {{{ |
| 258 | JPEG90 |
| 259 | |
| 260 | JPEG |
| 261 | |
| 262 | DEFLATE8 |
| 263 | |
| 264 | DEFLATE |
| 265 | }}} |
| 266 | |
| 267 | 7. ST_AsTIFF(rast raster, compression text, srs text) -> bytea |
| 268 | |
| 269 | This function will parse the compression string for the compression type and the compression quality. It will also inspect to make sure that the pixel types of the raster's bands are appropriate for the compression type. This is primarily for JPEG and CCITT compression types, which only support 8BUI and 1BB respectively. |
| 270 | |
| 271 | {{{ |
| 272 | ST_AsTIFF(rast, 'JPEG90', '+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') |
| 273 | |
| 274 | ST_AsTIFF(rast, 'JPEG', '+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') |
| 275 | |
| 276 | ST_AsTIFF(rast, 'LZMA', '+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') |
| 277 | }}} |
| 278 | |
| 279 | 8. ST_AsTIFF(rast raster, compression text) -> bytea |
| 280 | |
| 281 | The output TIFF will be created with default options. Like the prior function, the spatial reference of the TIFF will be set to the same as the input raster. |
| 282 | |
| 283 | {{{ |
| 284 | ST_AsTIFF(rast, 'LZMA') |
| 285 | }}} |
| 286 | |
| 287 | |
| 288 | The next two functions include band index and compression arguments |
| 289 | |
| 290 | 9. ST_AsTIFF(rast raster, nbands int[], compression text, srs text) -> bytea |
| 291 | |
| 292 | {{{ |
| 293 | ST_AsTIFF(rast, ARRAY[2], 'JPEG90', ARRAY['BIGTIFF=IF_NEEDED'], '+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') |
| 294 | |
| 295 | ST_AsTIFF(rast, ARRAY[1,3], 'JPEG', ARRAY['BIGTIFF=IF_NEEDED'], '+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') |
| 296 | |
| 297 | ST_AsTIFF(rast, ARRAY[3,1,2], 'LZMA', ARRAY['BIGTIFF=IF_NEEDED'], '+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') |
| 298 | }}} |
| 299 | |
| 300 | 10. ST_AsTIFF(rast raster, nbands int[], compression text) -> bytea |
| 301 | |
| 302 | {{{ |
| 303 | ST_AsTIFF(rast, ARRAY[3,2], 'DEFLATE9') |
| 304 | }}} |
| 305 | |
| 306 | The output TIFF will be created with default options. The spatial reference of the TIFF will be set to the same as the input raster. |