Changes between Version 99 and Version 100 of WKTRaster/SpecificationWorking03


Ignore:
Timestamp:
Jun 13, 2011, 1:52:09 PM (13 years ago)
Author:
pracine
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • WKTRaster/SpecificationWorking03

    v99 v100  
    1515----
    1616
    17 == '''Objective FV.01 - Being able to return a JPEG, a TIFF, a PNG or any image format supported by GDAL - ''DONE''''' ==
    18  
    19 '''ST_bytea(raster, integer) -> raster''' -- the integer parameters is the band number of the raster.[[BR]]
    20 What is does?
    21 
    22 ----
    23 ~~'''Open Question:''' When exporting a multiband raster to JPEG, TIFF, PNG, SVG or KML, how should we specify the band number in the exporting function.~~
    24 
    25 ~~There is two options to select the band to convert from a multiband raster in all the ST_AsFormat functions. [[BR]]~~
    26 [[BR]]
    27 ~~ 1. Precede each call with ST_Band() to return a selected band.[[BR]]~~
    28 ~~  Pros: This is a general function that can be called before any function that would otherwise require a band parameter.[[BR]]~~
    29 ~~  Cons: This implies creating a temporary raster. This might be more elegant and general but is this too much overhead comparing with having a band parameter?~~
    30 
    31 ~~ 2. Add a band parameter to each ST_AsFormat function.[[BR]]~~
    32 ~~  Pros: Hypothetically less overhead.[[BR]]~~
    33 ~~  Cons: Every functions implying access to a band should then have this parameter when in most case it would be equal to 1. In many cases it makes no sence to have to specify a band parameter since it is the whole raster that we want to export, including all the bands.~~
    34 
    35 ~~Pierre: More I think about it more I think that the first option is the best one...~~
    36 
    37 ~~mloskot: Perhaps there is a compromise in form of two sets of functions: 1) ST_As* which always burn the whole raster (all bands) 2) ST_BandAs* which takes number of band as a parameter and return only this requested band.~~
    38 
    39 ----
    40 
    41 '''ST_Band(raster, integer) -> raster''' -- the integer parameters are the band number of the rasters.[[BR]]
    42 Return a single band from a multiband raster. If "band" is greater than the value returned by ST_GetNumBands(), the function returns the last band. This function should be used to select a band before converting it to JPEG, TIFF, PNG, SVG or KML with the corresponding function. e.g. '''ST_AsTIFF(ST_Band(raster, band))
    43 
    44 A complete implementation of ST_Band should include the following:
    45 
    46 1. ST_Band(rast raster, nbands int[]) -> raster
    47 
    48     nbands is an array of 1-based band indices of the bands to copy into the output raster
    49 
    50     For a raster rast with 3 bands:
    51 {{{
    52 ST_Band(rast, ARRAY[1,3,2])
    53 
    54 ST_Band(rast, ARRAY[3,2,1])
    55 }}}
    56     You can rearrange the bands as above. You can also duplicate the bands:
    57 {{{
    58 ST_Band(rast, ARRAY[1,2,3,2,1])
    59 }}}
    60 
    61 2. ST_Band(rast raster, nband int) -> raster
    62 
    63     nband is a single integer of the 1-based band index of the band to copy into the output raster
    64 
    65 {{{
    66 ST_Band(rast, 1)
    67 
    68 ST_Band(rast, 3)
    69 }}}
    70 
    71 3. ST_Band(rast raster, nbands text) -> raster
    72 
    73     nbands is a comma separated string of 1-based band indices indicating the bands to copy into the output raster
    74 
    75 {{{
    76 ST_Band(rast, '1,2')
    77 
    78 ST_Band(rast, '1,2,3, 1, 1 , 2')
    79 }}}
    80 
    81 4. ST_Band(rast raster, nbands text, delimiter char) -> raster
    82 
    83     nbands is a user-specified delimiter separated string of 1-based band indices indicating the bands to copy into the output raster
    84 
    85 {{{
    86 ST_Band(rast, '1,2', ',')
    87 
    88 ST_Band(rast, '1,2,3, 1, 1 , 2', ',')
    89 }}}
    90 
    91 5. ST_Band(rast raster) -> raster
    92 
    93     the band to extract is automatically assumed to be one.
    94 
    95 {{{
    96 ST_Band(rast)
    97 }}}
    98 
    99 If an index is outside the valid range of band indices for a raster (less than 1 or greater than the value returned by ST_NumBands), the function will fail and return.
    100 
    101 ~~''' Open Question: ''' Should the function fail if an index is invalid?  How should this work when providing more than one indices to the function?~~
    102 
    103 ----
    104 
    105 '''ST_AsJPEG(raster, quality) -> JPEG as "bytea"'''[[BR]]
    106 
    107 The JPEG format has several limitations:
    108 
    109   1. JPEG only allows 1 (greyscale) or 3 (RGB) bands of data
    110 
    111   2. JPEG only supports 8BUI pixeltype
    112 
    113   3. JPEG cannot embed spatial reference information within the file but can have an associated world file
    114 
    115 To address the limitations:
    116 
    117   1. Use ST_Band to specify which band(s) should be passed to the ST_AsJPEG function. Variations of ST_AsJPEG are made available that allows specifying a band index. If a raster whose number of specified bands does not equal 1 or 3 is provided, a warning is raised and the first or the first three bands are used.
    118 
    119   2. Throw an exception if any of the specified bands is not 8BUI. The user should use ST_Reclass to convert any non-8BUI bands to 8BUI.
    120 
    121   3. Nothing can be done.
    122 
    123 A proposed set of variations of the ST_AsJPEG function:
    124 
    125 1. ST_AsJPEG(rast raster, options text[])
    126 
    127     rast: the raster with one or three bands in 8BUI pixel type to generate a JPEG image from
    128 
    129     options: array of creation options to pass to the GDAL JPEG driver
    130 
    131 {{{
    132 ST_AsJPEG(rast, ARRAY['QUALITY=90', 'PROGRESSIVE=ON'])
    133 }}}
    134 
    135 2. ST_AsJPEG(rast raster)
    136 
    137     Like !#1 above but use the driver's default creation options
    138 
    139 3. ST_AsJPEG(rast raster, nbands int[], options text[])
    140 
    141     nbands: an integer array specifying the band indices of the raster to include in the JPEG file
    142 
    143 {{{
    144 ST_AsJPEG(rast, ARRAY[1,3,6], ARRAY['QUALITY=50'])
    145 }}}
    146 
    147 4. ST_AsJPEG(rast raster, nbands int[])
    148 
    149     Like !#3, but use the default creation options
    150 
    151 {{{
    152 ST_AsJPEG(rast, ARRAY[1,3,6])
    153 }}}
    154 
    155 5. ST_AsJPEG(rast raster, nbands int[], quality int)
    156 
    157     quality: number between 10 and 100 indicating image quality
    158 
    159 {{{
    160 ST_AsJPEG(rast, ARRAY[1,2,3], 90)
    161 }}}
    162 
    163 6. ST_AsJPEG(rast raster, nband int, options text[])
    164 
    165     nband: index of the band to include
    166 
    167 {{{
    168 ST_AsJPEG(rast, 2, ARRAY['QUALITY=25'])
    169 }}}
    170 
    171 7. ST_AsJPEG(rast raster, nband int, quality int)
    172 
    173 {{{
    174 ST_AsJPEG(rast, 5, 75)
    175 }}}
    176 
    177 8. ST_AsJPEG(rast raster, nband int)
    178 
    179 {{{
    180 ST_AsJPEG(rast, 4)
    181 }}}
    182 
    183 ''OLD NOTES''
    184 
    185 ~~Return the raster as a JPEG encoded as a PostgreSQL bytea. By default quality is set to 75, but this option can be used to select other values. Values must be in the range 10-100. Low values result in higher compression ratios, but poorer image quality. Values above 95 are not meaningfully better quality but can but substantially larger. (copied from http://www.gdal.org/frmt_jpeg.html)~~
    186 
    187 
    188 ~~'''Open Question:''' Is JPEG export limited to raster having 8 bit unsigned integer pixeltype (8BUI)?~~
    189 
    190 ~~[http://www.gdal.org/frmt_jpeg.html See how GDAL do it]. It converts only 8 bits rasters. Should we do the same?~~
    191 
    192 ~~Otherwise, how do we convert other types to 8BUI? e.g. 16BUI or 8BSI?~~
    193 
    194 ~~Pierre: It might be more simple to ignore pixeltypes other than 8BUI but it would be very convenient to have a way to quickly export elevation data for example as a JPEG. It would be nice to have an elegant solution to this. Maybe something inspired from !MapServer.~~
    195 
    196 ~~Proposition one (Pierre): ST_AsJPEG could simply (optionally when the pixeltype is not 8BUI) map the ST_Maximum() and ST_Minimum() value to 0-255. ST_Maximum() and ST_Minimum() are not in the spec yet but this could be on nice usage of it. They will imply caching the min and max when importing and editing. Both function should ignore the !NoDataValues. They could also be two parameters passed to ST_AsJPEG(raster, quality, min, max).~~
    197 
    198 ~~Proposition two: There could also be just one parameter (string) defining a mapping method:~~
    199 
    200 ~~ * Method "None": No mapping. This is possible only for 8BUI.~~
    201 
    202 ~~ * Method "!MaxMinValue": Use the Max and the Min cached in the raster. e.g. for 16BSI (min, max) -> (-2033, 2456) -> (round((-2033 - -2033)/(2456 - -2033)*255), round((2456 - -2033)/(2456 - -2033)*255)) -> (0, 255).[[BR]]~~
    203 ~~[[BR]]This is equivalent to ST_AsJPEG(raster, quality, ST_Minimum(rast), ST_Maximum(rast))~~
    204 
    205 ~~ * Method "!MaxMinType": Use the Max and the Min allowed by the type. e.g. for 16BSI (min, max) -> (-2033, 2456) -> (round((-2033 - -32768)/(32767 - -32768)*255), round((2456 - -32768)/(32767 - -32768)*255)) -> (120, 137)[[BR]]~~
    206 ~~[[BR]]This would be equivalent to ST_AsJPEG(raster, quality, ST_BandPixelTypeMin(rast), ST_BandPixelTypeMax(rast)). Both functions (ST_BandPixelTypeMin & ST_BandPixelTypeMax) are not yet planned and I could not find an SQL query that returns the equivalent range for a type. [http://groups.google.nl/group/microsoft.public.sqlserver.programming/browse_thread/thread/46512c2691da4607/6743f4aea485c6d1 One possible solution.]~~
    207 
    208 
    209 ~~mloskot: ATM, I have no thoughts on this issue.~~
    210 
    211 ~~'''Open Question:''' Is JPEG export limited to raster having 1 or 3 bands?~~
    212 
    213 ~~[http://www.gdal.org/frmt_jpeg.html See how GDAL do it]. It converts only 1 or 3 band rasters. Should we do the same? In this case 1 band rasters would be exported as a greyscale JPEG having R G and B identical and 3 band rasters would be interpreted as R, G and B.~~
    214 
    215 ~~Pierre: I think the answer should be yes. I don't see how we could have a 2 band raster fit into RGB.~~
    216 
    217 ~~mloskot: I agree, the answer should be yes.~~
    218 
    219 ~~'''Here is an attempt to define the different versions of the function:'''~~
    220 
    221 ~~The most minimalistic versions of the function should assume band 1, 2 and 3 as being r, g, b and the quality equal to 75:~~
    222 
    223 ~~ ST_AsJPEG(raster) -quality = 75~~
    224 
    225 ~~A variant allow specifying the quality:~~
    226 
    227 ~~ ST_AsJPEG(raster, integer)~~
    228 
    229 ~~Another variant should enable us to specify which band correspond to the r, the g and the b:~~
    230 
    231 ~~ ST_AsJPEG(raster, integer, integer, integer) - raster, rband, gband, bband, quality=75~~
    232 
    233 ~~ ST_AsJPEG(raster, integer, integer, integer, integer) - raster, rband, gband, bband, quality~~
    234 
    235 ~~Another version should be designed to be used with a future ST_Band(raster) function. In this case there is no attempt to extract r, g or b band from any passed raster:~~
    236 
    237 ~~ ST_AsJPEG(raster, raster, raster)~~
    238 
    239 ~~ ST_AsJPEG(raster, raster, raster, integer) -with the quality param~~
    240 
    241 ~~Another series should allow converting 1 band raster with pixel of type 8BUI to a grayscale JPEG (Carefull study of the GDAL behavior when converting a single band to JPEG should be done before confirming these functions):~~
    242 
    243 ~~ ST_AsJPEG(raster, "GRAYSCALE") - convert only band 1 with quality = 75~~
    244 
    245 ~~ ST_AsJPEG(raster, "GRAYSCALE", integer) - convert only band 1 with specified quality~~
    246 
    247 ~~ ST_AsJPEG(raster, integer, "GRAYSCALE") - allow specifying the band number to convert~~
    248 
    249 ~~ ST_AsJPEG(raster, integer, "GRAYSCALE", integer) - allow specifying the band number to convert and the quality~~
    250 
    251 ~~Another series should allow converting 1 band raster of ANY pixel type to a grayscale JPEG. Pixel types different than 8BUI should be mapped according to specified min, max values and a mapping mode: "!MaxMinValue" (default) or "!MaxMinType".~~
    252 
    253 ~~ ST_AsJPEG(raster, "GRAYSCALE", min, max, text) - convert only band 1 with quality = 75~~
    254 
    255 ~~ ST_AsJPEG(raster, "GRAYSCALE", integer, min, max, text) - convert only band 1 with specified quality~~
    256 
    257 ~~ ST_AsJPEG(raster, integer, "GRAYSCALE", min, max, text) - allow specifying the band number to convert~~
    258 
    259 ~~ ST_AsJPEG(raster, integer, "GRAYSCALE", integer, min, max, text) - allow specifying the band number to convert and the quality~~
    260 
    261 ----
    262 
    263 '''ST_AsTIFF(raster, compression) -> TIFF as "bytea"'''[[BR]]
    264 Return the raster as a TIFF encoded as a PostgreSQL bytea. If raster is a multiband raster and no band were selected with ST_Band() every band are written to the resulting TIFF.
    265 
    266 compression=[JPEG/LZW/PACKBITS/DEFLATE/CCITTRLE/CCITTFAX3/CCITTFAX4/NONE]: Set the type of compression to use. None is the default. The CCITT compression should only be used with 1bit (NBITS=1) data. JPEG should only be used with Byte data. When using JPEG add a number specifying the quality. 75 is the default. e.g. ST_AsTIFF(raster, "JPEG60") (copied from http://www.gdal.org/frmt_gtiff.html)
    267 
    268 A proposed implementation of the ST_AsTIFF functions.
    269 
    270 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.
    271 
    272 ''If the compression parameter/option is specified to JPEG, all bands must be of pixel type 8BUI.  If the compression parameter/option is specified to one of the CCITT options, all bands must be of pixel type 1BB.  If any band violates the restriction, an exception is raised.''
    273 
    274 The next three functions are the most basic of the ST_AsTIFF functions.
    275 
    276 1. ST_AsTIFF(rast raster, options text[], srs text) -> bytea
    277 
    278     The most generic version of this function. All other ST_AsTIFF functions call this function.
    279 
    280     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 first band with a NODATA value.
    281 
    282         options: the GDAL creation options found in the Creation Options section of the GDAL TIFF driver
    283 
    284         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.
    285 
    286 {{{
    287 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')
    288 
    289 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]]')
    290 }}}
    291 
    292 2. ST_AsTIFF(rast raster, options text[]) -> bytea
    293 
    294 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.
    295 
    296 {{{
    297 ST_AsTIFF(rast, ARRAY['COMPRESS=DEFLATE', 'ZLEVEL=9'])
    298 }}}
    299 
    300 3. ST_AsTIFF(rast raster) -> bytea
    301 
    302 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.
    303 
    304 {{{
    305 ST_AsTIFF(rast)
    306 }}}
    307 
    308 
    309 The next three functions add a band index argument to filter the raster's bands before generating the output TIFF.
    310 
    311 4. ST_AsTIFF(rast raster, nbands int[], options text[], srs text) -> bytea
    312 
    313 {{{
    314 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')
    315 }}}
    316 
    317 5. ST_AsTIFF(rast raster, nbands int[], options text[]) -> bytea
    318 
    319 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.
    320 
    321 {{{
    322 ST_AsTIFF(rast, ARRAY[3,1,2], ARRAY['COMPRESS=DEFLATE', 'ZLEVEL=9'])
    323 }}}
    324 
    325 6. ST_AsTIFF(rast raster, nbands int[]) -> bytea
    326 
    327 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.
    328 
    329 {{{
    330 ST_AsTIFF(rast, ARRAY[3,1,2])
    331 }}}
    332 
    333 
    334 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.
    335 
    336 Examples are:
    337 
    338 {{{
    339 JPEG90
    340 
    341 JPEG
    342 
    343 DEFLATE8
    344 
    345 DEFLATE
    346 }}}
    347 
    348 7. ST_AsTIFF(rast raster, compression text, srs text) -> bytea
    349 
    350 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.
    351 
    352 {{{
    353 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')
    354 
    355 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')
    356 
    357 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')
    358 }}}
    359 
    360 8. ST_AsTIFF(rast raster, compression text) -> bytea
    361 
    362 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.
    363 
    364 {{{
    365 ST_AsTIFF(rast, 'LZMA')
    366 }}}
    367 
    368 
    369 The next two functions include band index and compression arguments
    370 
    371 9. ST_AsTIFF(rast raster, nbands int[], compression text, srs text) -> bytea
    372 
    373 {{{
    374 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')
    375 
    376 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')
    377 
    378 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')
    379 }}}
    380 
    381 10. ST_AsTIFF(rast raster, nbands int[], compression text) -> bytea
    382 
    383 {{{
    384 ST_AsTIFF(rast, ARRAY[3,2], 'DEFLATE9')
    385 }}}
    386 
    387 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.
    388 
    389 ----
    390 ~~'''Open Question:''' What if we want to export only the first two band of a three band layer?~~
    391 
    392 ~~Maybe we need a ST_RasterFromBands(band1, band2, etc...) to reconstitute a multiband raster from multiple sources (having the same width, height, pixelsize, etc...)~~
    393 
    394 ~~mloskot: or ST_RasterFromBands(bands) where bands is ARRAY[int]. For instance, ST_RasterFromBands(ARRAY[1,3]) will burn new raster from 1 and 3 bands of input raster.~~
    395 
    396 ----
    397 '''ST_AsPNG(raster, band) -> PNG as "bytea"'''
    398 
    399 Like the JPEG raster format, the PNG format has limitations:
    400 
    401   1. PNG only allows 1 (greyscale) or 3 (RGB) bands of data
    402 
    403   2. PNG only supports 8BUI and 16BUI pixeltypes. Any other pixeltype will be written as 8BUI, though the results are probably useless
    404 
    405   3. PNG cannot embed spatial reference information within the file but can have an associated world file
    406 
    407 Like JPEG, the limitations can be resolved:
    408 
    409   1. Use ST_Band to specify which band(s) should be passed to the ST_AsPNG function. If a raster whose number of specified bands does not equal 1 or 3 is provided, a warning is raised and the first or the first three bands are used.
    410 
    411   2. Throw an exception if any of the specified bands is not 8BUI or 16BUI. The user should use ST_Reclass to convert any non-8BUI or 16BUI bands to 8BUI or 16BUI.
    412 
    413   3. Nothing can be done within this function. ST_Georeference() can be used to the contents of the associated world file
    414 
    415 A proposed set of variations of the ST_AsPNG function:
    416 
    417 1. ST_AsPNG(rast raster, options text[])
    418 
    419     rast: the raster with one or three bands in 8BUI or 16BUI pixel type to generate a PNG image from
    420 
    421     options: array of creation options to pass to the GDAL PNG driver
    422 
    423 {{{
    424 ST_AsPNG(rast, ARRAY['ZLEVEL=9'])
    425 }}}
    426 
    427 2. ST_AsPNG(rast raster)
    428 
    429     Like !#1 above but use the driver's default creation options
    430 
    431 3. ST_AsPNG(rast raster, nbands int[], options text[])
    432 
    433     nbands: an integer array specifying the band indices of the raster to include in the PNG file
    434 
    435 {{{
    436 ST_AsPNG(rast, ARRAY[3,1,2], ARRAY['ZLEVEL=9'])
    437 }}}
    438 
    439 4. ST_AsPNG(rast raster, nbands int[])
    440 
    441     Like !#3, but use the default creation options
    442 
    443 {{{
    444 ST_AsPNG(rast, ARRAY[3])
    445 }}}
    446 
    447 5. ST_AsPNG(rast raster, nbands int[], compression int)
    448 
    449     compression: number between 1 and 9 indicating the amount of time to spend on compression. 1 is fastest with least compression. 9 is slowest with best compression
    450 
    451 {{{
    452 ST_AsPNG(rast, ARRAY[2,1,3], 3)
    453 }}}
    454 
    455 6. ST_AsPNG(rast raster, nband int, options text[])
    456 
    457     nband: index of the band to include
    458 
    459 {{{
    460 ST_AsPNG(rast, 2, ARRAY['ZLEVEL=5'])
    461 }}}
    462 
    463 7. ST_AsPNG(rast raster, nband int, compression int)
    464 
    465 {{{
    466 ST_AsPNG(rast, 1, 8)
    467 }}}
    468 
    469 8. ST_AsPNG(rast raster, nband int)
    470 
    471 {{{
    472 ST_AsPNG(rast, 1)
    473 }}}
    474 
    475 ----
    476 
    477 '''ST_AsGDALRaster(raster, band int, type text, options text) -> bytea'''
    478 
    479 Use GDAL to convert the raster into one of the format suported by GDAL.
    480 
    481 This is a generic interface to outputting a supported and installed GDAL raster:
    482 
    483 1. ST_AsGDALRaster(rast raster, format text, options text[], srs text) -> bytea
    484 
    485   This is the most generic and GDAL-specific method to convert a raster to a GDAL raster.  All other version of ST_AsGDALRaster and other format specific functions (ST_AsJPEG, ST_AsTIFF and ST_AsPNG) are all wrappers around this function.  Reference information for the format and options arguments of a particular format are specified at: http://gdal.org/formats_list.html.  The arguments specified are:
    486 
    487   format: the GDAL format code.  e.g. GTiff, JPEG, PNG
    488 
    489   options: the GDAL creation options found in the '''Creation Options''' section of a specified format.  e.g. COMPRESS=JPEG, JPEG_QUALITY=90
    490 
    491   srs: the user-specified OGC WKT or the proj4 text for a spatial reference to embed in the GDAL raster.  Not all formats support embedding this information.  e.g. the non-empty value for the srtext or proj4text column from the spatial_ref_sys table.
    492 
    493 {{{
    494 ST_AsGDALRaster(rast, 'GTiff', ARRAY['COMPRESS=JPEG', 'JPEG_QUALITY=90'], '+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')
    495 
    496 ST_AsGDALRaster(rast, 'GTiff', ARRAY['COMPRESS=JPEG', 'JPEG_QUALITY=90'], '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]]')
    497 }}}
    498 
    499 
    500 2. ST_AsGDALRaster(rast raster, format text, options text[]) -> bytea
    501 
    502   This one removes the user-specified srs argument.  The output GDAL raster's spatial reference will be set to the same as the input raster, if possible.
    503 
    504 {{{
    505 ST_AsGDALRaster(rast, 'JPEG', ARRAY['QUALITY=50'])
    506 
    507 ST_AsGDALRaster(rast, 'PNG', ARRAY['ZLEVEL=7'])
    508 }}}
    509 
    510 3. ST_AsGDALRaster(rast raster, format text) -> bytea
    511 
    512   The simplest implementation of this function.  Since the options argument has been removed, the output GDAL raster will be created with default options.  Like the prior function, the spatial reference of the GDAL raster will be set to the same as the input raster.
    513 
    514 {{{
    515 ST_AsGDALRaster(rast, 'JPEG')
    516 }}}
    517 
    518 ----
    519 
    520 '''ST_GDALDrivers() -> set of record'''
    521 
    522 As each GDAL installation may be different and ST_AsGDALRaster can be used to support formats other than GTiff, JPEG and PNG, a method is needed to expose to the end user the possible GDAL formats capable of being exported.  This function will output the following columns.
    523 
    524   idx: the internal GDAL index number
    525 
    526   short_name: the GDAL format code.  This is the value to pass to the format paramenter of ST_AsGDALRaster
    527 
    528   long_name: the full name of the GDAL format
    529 
    530   create_options: the creation options available for the format as an XML string.
    531 
    532 The formats outputted from ST_getGDALDrivers have been filtered to only those that the GDAL capabilities !CreateCopy and Virtual IO support.
    533 
    534 '''Open Question:''' Should the GDAL raster process be capable of supporting the GDAL capability Create?  As the GDAL raster process writes nothing to a file in the filesystem (via Virtual IO), should there be support for writing the output GDAL raster temporarily to the filesystem?  If so, how is it done in other PostgreSQL extensions in a secure manner?
    535 
    536 ----
    537 
    538 '''ST_srtext(rast raster) -> text'''
    539 
    540 A helper function to get the value of column srtext or proj4text for a raster with an SRID.  By default, the srtext is returned.  If srtext is not available but proj4text is, the proj4text is returned.
    541 
    542 This function may be removed based upon the capabilities of SPI.  It may not be possible to remove this function as the srs function argument of ST_AsGDALRaster can be NULL, thereby instructing the function to not embed any spatial reference information into the output GDAL raster.
    543 
    544 ----
    545 
    546 '''ST_Reclass(rast raster, VARIADIC argset reclassarg[]) -> raster'''
    547 
    548 Due to limitations in the JPEG (8BUI) and PNG (8BUI and 16BUI) raster formats regarding supported pixel/data types, a method must be provided that can convert a band of a larger data type to 8BUI, amongst other uses.  ST_Reclass allows raster's band pixel values to be remapped from one range of numbers to another as well as between pixel types, e.g. 32BF to 8BUI.
    549 
    550 ST_Reclass returns a duplicate of the submitted raster with the bands specified to be reclassed being processed.  This means that if a raster with 5 bands are submitted and band 1 is to be reclassed, the output raster will have 5 bands with band 1 reclassified.  The other four bands will not be touched.
    551 
    552 1. ST_Reclass(rast raster, VARIADIC argset reclassarg[]) -> raster
    553 
    554   rast: the raster whose specified bands are to be reclassified
    555 
    556   reclassarg: a new custom type defining the parameters required for reclassifying a band's pixel values.
    557 
    558 {{{
    559 CREATE TYPE reclassarg AS (
    560 
    561   nband int,
    562 
    563   reclassexpr text,
    564 
    565   pixeltype text,
    566 
    567   nodata double
    568 
    569 );
    570 }}}
    571 
    572     nband: index of the band to reclass (1-based)
    573 
    574     reclassexpr: reclassification expression indicating the ranges to convert from and to.  More than one expression can be provided by separating the expression with a comma (,).  The values provided can be of any valid numeric type.
    575 
    576       ''rangefrom:rangeto[, rangefrom:rangeto]''
    577 
    578 {{{
    579 0-100:0-10
    580 
    581 0-100:0-10, 101-1000:11-100
    582 
    583 0-100:0-10, 101-1000:11-100, 1001-10000:101-1000
    584 }}}
    585 
    586       In the last example above, the default evaluation of the ranges is
    587 
    588 {{{
    589         0 <= x < 100 reclassified to 0 <= y <= 10
    590 
    591         101 <= x < 1000 reclassified to 11 <= y <= 100
    592 
    593         1001 <= x < 10000 reclassified to 101 <= y <= 1000
    594 }}}
    595 
    596       To change the evaluation of rangefrom, use square brackets and parentheses.
    597 
    598 {{{
    599 1. [a-b] = a <= x <= b
    600 
    601 2. (a-b] = a < x <= b
    602 
    603 3. [a-b) = a <= x < b
    604 
    605 4. (a-b) = a < x < b
    606 }}}
    607 
    608       !#3 above is the default evaluation of x in the range a-b. The use of square brackets and parentheses are optional, so the examples below would be permitted. Missing notations substitute the appropriate notation from #3 above.
    609 
    610 {{{
    611 [a-b = a <= x < b
    612 
    613 (a-b = a < x < b
    614 
    615 a-b] = a <= x <= b
    616 
    617 a-b) = a <= x < b
    618 }}}
    619 
    620       Two special cases are also available for use when x may be outside the range of a-b.  This situation is possible if your range is based upon an approximation, such as from ST_ApproxMinMax.
    621 
    622 {{{
    623 ]a-b or )a-b = x < a, rule matches
    624 
    625 a-b[ or a-b( = x >= b, rule matches
    626 }}}
    627 
    628     pixeltype: the reclassified band's pixel type, e.g. 8BUI, 16BUI, 32BF
    629 
    630     nodata: the nodata value of the reclassified band.  If the source band has a nodata value, all source pixel value equal to the source nodata value will be converted to the reclassified band's nodata value.  If set to NULL, the reclassified band will NOT have a nodata value specified.
    631 
    632 {{{
    633 ST_Reclass(rast, ROW(1, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', NULL));
    634 
    635 ST_Reclass(rast, ROW(1, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001));
    636 
    637 ST_Reclass(rast,
    638   ROW(1, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001),
    639   ROW(2, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001),
    640   ROW(3, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001),
    641   ROW(5, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001)
    642 )
    643 }}}
    644 
    645   An expanded example
    646 
    647 {{{
    648 SELECT ST_Reclass(
    649   ST_Band(rast, ARRAY[1,1,1]),
    650   ROW(1, LEAST(covmin, 0)::text || '-0:0,0-' || GREATEST(covmax, 0)::text || ':0-255', '8BUI'),
    651   ROW(2, LEAST(covmin, 0)::text || '-0:200,0-' || GREATEST(covmax, 0)::text' || ':0-255','8BUI'),
    652   ROW(3, LEAST(covmin, 0)::text || '-0:255,0-' || (GREATEST(covmax, 0)/2)::text' || ':0,' || (GREATEST(covmax, 0)/2)::text' || ':' || GREATEST(covmax, 0)::text || ':0-255', '8BUI')
    653 )
    654 FROM mycoverage
    655 }}}
    656 
    657 2. ST_Reclass(rast raster, nband int, reclassexpr text, pixeltype text, nodata double) -> raster
    658 
    659   provides a method to process just one band of a raster
    660 
    661 {{{
    662 ST_Reclass(rast, 1, '0-100:0-10', '8BUI', 11)
    663 }}}
    664 
    665 3. ST_Reclass(rast raster, nband int, reclassexpr text, pixeltype text) -> raster
    666 
    667   nodata parameter removed so reclassified band will NOT have a nodata value set
    668 
    669 {{{
    670 ST_Reclass(rast, 1, '0-100:0-10', '8BUI')
    671 }}}
    672 
    673 4. ST_Reclass(rast raster, reclassexpr text, pixeltype text) -> raster
    674 
    675   nband parameter removed so reclassified band is assumed to be 1.  nodata parameter removed so reclassified band has NO nodata value.
    676 
    677 {{{
    678 ST_Reclass(rast, '0-100:0-10', '8BUI')
    679 }}}
    680 
    681 5. ST_Reclass(rast raster, reclassexpr text, pixeltype text, nodata double) -> raster
    682 
    683   nband parameter removed so reclassified band is assumed to be 1
    684 
    685 {{{
    686 ST_Reclass(rast, '0-100:0-10', '8BUI', 11)
    687 }}}
     17
    68818
    68919----
     
    29072237'''ST_RasterFromText(string, [<srid>])'''[[BR]]
    29082238'''ST_AsText(raster)'''
     2239
     2240== '''Objective FV.01 - Being able to return a JPEG, a TIFF, a PNG or any image format supported by GDAL - ''DONE''''' ==
     2241 
     2242'''ST_bytea(raster, integer) -> raster''' -- the integer parameters is the band number of the raster.[[BR]]
     2243What is does?
     2244
     2245----
     2246~~'''Open Question:''' When exporting a multiband raster to JPEG, TIFF, PNG, SVG or KML, how should we specify the band number in the exporting function.~~
     2247
     2248~~There is two options to select the band to convert from a multiband raster in all the ST_AsFormat functions. [[BR]]~~
     2249[[BR]]
     2250~~ 1. Precede each call with ST_Band() to return a selected band.[[BR]]~~
     2251~~  Pros: This is a general function that can be called before any function that would otherwise require a band parameter.[[BR]]~~
     2252~~  Cons: This implies creating a temporary raster. This might be more elegant and general but is this too much overhead comparing with having a band parameter?~~
     2253
     2254~~ 2. Add a band parameter to each ST_AsFormat function.[[BR]]~~
     2255~~  Pros: Hypothetically less overhead.[[BR]]~~
     2256~~  Cons: Every functions implying access to a band should then have this parameter when in most case it would be equal to 1. In many cases it makes no sence to have to specify a band parameter since it is the whole raster that we want to export, including all the bands.~~
     2257
     2258~~Pierre: More I think about it more I think that the first option is the best one...~~
     2259
     2260~~mloskot: Perhaps there is a compromise in form of two sets of functions: 1) ST_As* which always burn the whole raster (all bands) 2) ST_BandAs* which takes number of band as a parameter and return only this requested band.~~
     2261
     2262----
     2263
     2264'''ST_Band(raster, integer) -> raster''' -- the integer parameters are the band number of the rasters.[[BR]]
     2265Return a single band from a multiband raster. If "band" is greater than the value returned by ST_GetNumBands(), the function returns the last band. This function should be used to select a band before converting it to JPEG, TIFF, PNG, SVG or KML with the corresponding function. e.g. '''ST_AsTIFF(ST_Band(raster, band))
     2266
     2267A complete implementation of ST_Band should include the following:
     2268
     22691. ST_Band(rast raster, nbands int[]) -> raster
     2270
     2271    nbands is an array of 1-based band indices of the bands to copy into the output raster
     2272
     2273    For a raster rast with 3 bands:
     2274{{{
     2275ST_Band(rast, ARRAY[1,3,2])
     2276
     2277ST_Band(rast, ARRAY[3,2,1])
     2278}}}
     2279    You can rearrange the bands as above. You can also duplicate the bands:
     2280{{{
     2281ST_Band(rast, ARRAY[1,2,3,2,1])
     2282}}}
     2283
     22842. ST_Band(rast raster, nband int) -> raster
     2285
     2286    nband is a single integer of the 1-based band index of the band to copy into the output raster
     2287
     2288{{{
     2289ST_Band(rast, 1)
     2290
     2291ST_Band(rast, 3)
     2292}}}
     2293
     22943. ST_Band(rast raster, nbands text) -> raster
     2295
     2296    nbands is a comma separated string of 1-based band indices indicating the bands to copy into the output raster
     2297
     2298{{{
     2299ST_Band(rast, '1,2')
     2300
     2301ST_Band(rast, '1,2,3, 1, 1 , 2')
     2302}}}
     2303
     23044. ST_Band(rast raster, nbands text, delimiter char) -> raster
     2305
     2306    nbands is a user-specified delimiter separated string of 1-based band indices indicating the bands to copy into the output raster
     2307
     2308{{{
     2309ST_Band(rast, '1,2', ',')
     2310
     2311ST_Band(rast, '1,2,3, 1, 1 , 2', ',')
     2312}}}
     2313
     23145. ST_Band(rast raster) -> raster
     2315
     2316    the band to extract is automatically assumed to be one.
     2317
     2318{{{
     2319ST_Band(rast)
     2320}}}
     2321
     2322If an index is outside the valid range of band indices for a raster (less than 1 or greater than the value returned by ST_NumBands), the function will fail and return.
     2323
     2324~~''' Open Question: ''' Should the function fail if an index is invalid?  How should this work when providing more than one indices to the function?~~
     2325
     2326----
     2327
     2328'''ST_AsJPEG(raster, quality) -> JPEG as "bytea"'''[[BR]]
     2329
     2330The JPEG format has several limitations:
     2331
     2332  1. JPEG only allows 1 (greyscale) or 3 (RGB) bands of data
     2333
     2334  2. JPEG only supports 8BUI pixeltype
     2335
     2336  3. JPEG cannot embed spatial reference information within the file but can have an associated world file
     2337
     2338To address the limitations:
     2339
     2340  1. Use ST_Band to specify which band(s) should be passed to the ST_AsJPEG function. Variations of ST_AsJPEG are made available that allows specifying a band index. If a raster whose number of specified bands does not equal 1 or 3 is provided, a warning is raised and the first or the first three bands are used.
     2341
     2342  2. Throw an exception if any of the specified bands is not 8BUI. The user should use ST_Reclass to convert any non-8BUI bands to 8BUI.
     2343
     2344  3. Nothing can be done.
     2345
     2346A proposed set of variations of the ST_AsJPEG function:
     2347
     23481. ST_AsJPEG(rast raster, options text[])
     2349
     2350    rast: the raster with one or three bands in 8BUI pixel type to generate a JPEG image from
     2351
     2352    options: array of creation options to pass to the GDAL JPEG driver
     2353
     2354{{{
     2355ST_AsJPEG(rast, ARRAY['QUALITY=90', 'PROGRESSIVE=ON'])
     2356}}}
     2357
     23582. ST_AsJPEG(rast raster)
     2359
     2360    Like !#1 above but use the driver's default creation options
     2361
     23623. ST_AsJPEG(rast raster, nbands int[], options text[])
     2363
     2364    nbands: an integer array specifying the band indices of the raster to include in the JPEG file
     2365
     2366{{{
     2367ST_AsJPEG(rast, ARRAY[1,3,6], ARRAY['QUALITY=50'])
     2368}}}
     2369
     23704. ST_AsJPEG(rast raster, nbands int[])
     2371
     2372    Like !#3, but use the default creation options
     2373
     2374{{{
     2375ST_AsJPEG(rast, ARRAY[1,3,6])
     2376}}}
     2377
     23785. ST_AsJPEG(rast raster, nbands int[], quality int)
     2379
     2380    quality: number between 10 and 100 indicating image quality
     2381
     2382{{{
     2383ST_AsJPEG(rast, ARRAY[1,2,3], 90)
     2384}}}
     2385
     23866. ST_AsJPEG(rast raster, nband int, options text[])
     2387
     2388    nband: index of the band to include
     2389
     2390{{{
     2391ST_AsJPEG(rast, 2, ARRAY['QUALITY=25'])
     2392}}}
     2393
     23947. ST_AsJPEG(rast raster, nband int, quality int)
     2395
     2396{{{
     2397ST_AsJPEG(rast, 5, 75)
     2398}}}
     2399
     24008. ST_AsJPEG(rast raster, nband int)
     2401
     2402{{{
     2403ST_AsJPEG(rast, 4)
     2404}}}
     2405
     2406''OLD NOTES''
     2407
     2408~~Return the raster as a JPEG encoded as a PostgreSQL bytea. By default quality is set to 75, but this option can be used to select other values. Values must be in the range 10-100. Low values result in higher compression ratios, but poorer image quality. Values above 95 are not meaningfully better quality but can but substantially larger. (copied from http://www.gdal.org/frmt_jpeg.html)~~
     2409
     2410
     2411~~'''Open Question:''' Is JPEG export limited to raster having 8 bit unsigned integer pixeltype (8BUI)?~~
     2412
     2413~~[http://www.gdal.org/frmt_jpeg.html See how GDAL do it]. It converts only 8 bits rasters. Should we do the same?~~
     2414
     2415~~Otherwise, how do we convert other types to 8BUI? e.g. 16BUI or 8BSI?~~
     2416
     2417~~Pierre: It might be more simple to ignore pixeltypes other than 8BUI but it would be very convenient to have a way to quickly export elevation data for example as a JPEG. It would be nice to have an elegant solution to this. Maybe something inspired from !MapServer.~~
     2418
     2419~~Proposition one (Pierre): ST_AsJPEG could simply (optionally when the pixeltype is not 8BUI) map the ST_Maximum() and ST_Minimum() value to 0-255. ST_Maximum() and ST_Minimum() are not in the spec yet but this could be on nice usage of it. They will imply caching the min and max when importing and editing. Both function should ignore the !NoDataValues. They could also be two parameters passed to ST_AsJPEG(raster, quality, min, max).~~
     2420
     2421~~Proposition two: There could also be just one parameter (string) defining a mapping method:~~
     2422
     2423~~ * Method "None": No mapping. This is possible only for 8BUI.~~
     2424
     2425~~ * Method "!MaxMinValue": Use the Max and the Min cached in the raster. e.g. for 16BSI (min, max) -> (-2033, 2456) -> (round((-2033 - -2033)/(2456 - -2033)*255), round((2456 - -2033)/(2456 - -2033)*255)) -> (0, 255).[[BR]]~~
     2426~~[[BR]]This is equivalent to ST_AsJPEG(raster, quality, ST_Minimum(rast), ST_Maximum(rast))~~
     2427
     2428~~ * Method "!MaxMinType": Use the Max and the Min allowed by the type. e.g. for 16BSI (min, max) -> (-2033, 2456) -> (round((-2033 - -32768)/(32767 - -32768)*255), round((2456 - -32768)/(32767 - -32768)*255)) -> (120, 137)[[BR]]~~
     2429~~[[BR]]This would be equivalent to ST_AsJPEG(raster, quality, ST_BandPixelTypeMin(rast), ST_BandPixelTypeMax(rast)). Both functions (ST_BandPixelTypeMin & ST_BandPixelTypeMax) are not yet planned and I could not find an SQL query that returns the equivalent range for a type. [http://groups.google.nl/group/microsoft.public.sqlserver.programming/browse_thread/thread/46512c2691da4607/6743f4aea485c6d1 One possible solution.]~~
     2430
     2431
     2432~~mloskot: ATM, I have no thoughts on this issue.~~
     2433
     2434~~'''Open Question:''' Is JPEG export limited to raster having 1 or 3 bands?~~
     2435
     2436~~[http://www.gdal.org/frmt_jpeg.html See how GDAL do it]. It converts only 1 or 3 band rasters. Should we do the same? In this case 1 band rasters would be exported as a greyscale JPEG having R G and B identical and 3 band rasters would be interpreted as R, G and B.~~
     2437
     2438~~Pierre: I think the answer should be yes. I don't see how we could have a 2 band raster fit into RGB.~~
     2439
     2440~~mloskot: I agree, the answer should be yes.~~
     2441
     2442~~'''Here is an attempt to define the different versions of the function:'''~~
     2443
     2444~~The most minimalistic versions of the function should assume band 1, 2 and 3 as being r, g, b and the quality equal to 75:~~
     2445
     2446~~ ST_AsJPEG(raster) -quality = 75~~
     2447
     2448~~A variant allow specifying the quality:~~
     2449
     2450~~ ST_AsJPEG(raster, integer)~~
     2451
     2452~~Another variant should enable us to specify which band correspond to the r, the g and the b:~~
     2453
     2454~~ ST_AsJPEG(raster, integer, integer, integer) - raster, rband, gband, bband, quality=75~~
     2455
     2456~~ ST_AsJPEG(raster, integer, integer, integer, integer) - raster, rband, gband, bband, quality~~
     2457
     2458~~Another version should be designed to be used with a future ST_Band(raster) function. In this case there is no attempt to extract r, g or b band from any passed raster:~~
     2459
     2460~~ ST_AsJPEG(raster, raster, raster)~~
     2461
     2462~~ ST_AsJPEG(raster, raster, raster, integer) -with the quality param~~
     2463
     2464~~Another series should allow converting 1 band raster with pixel of type 8BUI to a grayscale JPEG (Carefull study of the GDAL behavior when converting a single band to JPEG should be done before confirming these functions):~~
     2465
     2466~~ ST_AsJPEG(raster, "GRAYSCALE") - convert only band 1 with quality = 75~~
     2467
     2468~~ ST_AsJPEG(raster, "GRAYSCALE", integer) - convert only band 1 with specified quality~~
     2469
     2470~~ ST_AsJPEG(raster, integer, "GRAYSCALE") - allow specifying the band number to convert~~
     2471
     2472~~ ST_AsJPEG(raster, integer, "GRAYSCALE", integer) - allow specifying the band number to convert and the quality~~
     2473
     2474~~Another series should allow converting 1 band raster of ANY pixel type to a grayscale JPEG. Pixel types different than 8BUI should be mapped according to specified min, max values and a mapping mode: "!MaxMinValue" (default) or "!MaxMinType".~~
     2475
     2476~~ ST_AsJPEG(raster, "GRAYSCALE", min, max, text) - convert only band 1 with quality = 75~~
     2477
     2478~~ ST_AsJPEG(raster, "GRAYSCALE", integer, min, max, text) - convert only band 1 with specified quality~~
     2479
     2480~~ ST_AsJPEG(raster, integer, "GRAYSCALE", min, max, text) - allow specifying the band number to convert~~
     2481
     2482~~ ST_AsJPEG(raster, integer, "GRAYSCALE", integer, min, max, text) - allow specifying the band number to convert and the quality~~
     2483
     2484----
     2485
     2486'''ST_AsTIFF(raster, compression) -> TIFF as "bytea"'''[[BR]]
     2487Return the raster as a TIFF encoded as a PostgreSQL bytea. If raster is a multiband raster and no band were selected with ST_Band() every band are written to the resulting TIFF.
     2488
     2489compression=[JPEG/LZW/PACKBITS/DEFLATE/CCITTRLE/CCITTFAX3/CCITTFAX4/NONE]: Set the type of compression to use. None is the default. The CCITT compression should only be used with 1bit (NBITS=1) data. JPEG should only be used with Byte data. When using JPEG add a number specifying the quality. 75 is the default. e.g. ST_AsTIFF(raster, "JPEG60") (copied from http://www.gdal.org/frmt_gtiff.html)
     2490
     2491A proposed implementation of the ST_AsTIFF functions.
     2492
     2493The 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.
     2494
     2495''If the compression parameter/option is specified to JPEG, all bands must be of pixel type 8BUI.  If the compression parameter/option is specified to one of the CCITT options, all bands must be of pixel type 1BB.  If any band violates the restriction, an exception is raised.''
     2496
     2497The next three functions are the most basic of the ST_AsTIFF functions.
     2498
     24991. ST_AsTIFF(rast raster, options text[], srs text) -> bytea
     2500
     2501    The most generic version of this function. All other ST_AsTIFF functions call this function.
     2502
     2503    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 first band with a NODATA value.
     2504
     2505        options: the GDAL creation options found in the Creation Options section of the GDAL TIFF driver
     2506
     2507        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.
     2508
     2509{{{
     2510ST_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')
     2511
     2512ST_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]]')
     2513}}}
     2514
     25152. ST_AsTIFF(rast raster, options text[]) -> bytea
     2516
     2517This 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.
     2518
     2519{{{
     2520ST_AsTIFF(rast, ARRAY['COMPRESS=DEFLATE', 'ZLEVEL=9'])
     2521}}}
     2522
     25233. ST_AsTIFF(rast raster) -> bytea
     2524
     2525The 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.
     2526
     2527{{{
     2528ST_AsTIFF(rast)
     2529}}}
     2530
     2531
     2532The next three functions add a band index argument to filter the raster's bands before generating the output TIFF.
     2533
     25344. ST_AsTIFF(rast raster, nbands int[], options text[], srs text) -> bytea
     2535
     2536{{{
     2537ST_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')
     2538}}}
     2539
     25405. ST_AsTIFF(rast raster, nbands int[], options text[]) -> bytea
     2541
     2542This 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.
     2543
     2544{{{
     2545ST_AsTIFF(rast, ARRAY[3,1,2], ARRAY['COMPRESS=DEFLATE', 'ZLEVEL=9'])
     2546}}}
     2547
     25486. ST_AsTIFF(rast raster, nbands int[]) -> bytea
     2549
     2550Since 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.
     2551
     2552{{{
     2553ST_AsTIFF(rast, ARRAY[3,1,2])
     2554}}}
     2555
     2556
     2557The 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.
     2558
     2559Examples are:
     2560
     2561{{{
     2562JPEG90
     2563
     2564JPEG
     2565
     2566DEFLATE8
     2567
     2568DEFLATE
     2569}}}
     2570
     25717. ST_AsTIFF(rast raster, compression text, srs text) -> bytea
     2572
     2573This 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.
     2574
     2575{{{
     2576ST_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')
     2577
     2578ST_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')
     2579
     2580ST_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')
     2581}}}
     2582
     25838. ST_AsTIFF(rast raster, compression text) -> bytea
     2584
     2585The 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.
     2586
     2587{{{
     2588ST_AsTIFF(rast, 'LZMA')
     2589}}}
     2590
     2591
     2592The next two functions include band index and compression arguments
     2593
     25949. ST_AsTIFF(rast raster, nbands int[], compression text, srs text) -> bytea
     2595
     2596{{{
     2597ST_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')
     2598
     2599ST_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')
     2600
     2601ST_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')
     2602}}}
     2603
     260410. ST_AsTIFF(rast raster, nbands int[], compression text) -> bytea
     2605
     2606{{{
     2607ST_AsTIFF(rast, ARRAY[3,2], 'DEFLATE9')
     2608}}}
     2609
     2610The output TIFF will be created with default options. The spatial reference of the TIFF will be set to the same as the input raster.
     2611
     2612----
     2613~~'''Open Question:''' What if we want to export only the first two band of a three band layer?~~
     2614
     2615~~Maybe we need a ST_RasterFromBands(band1, band2, etc...) to reconstitute a multiband raster from multiple sources (having the same width, height, pixelsize, etc...)~~
     2616
     2617~~mloskot: or ST_RasterFromBands(bands) where bands is ARRAY[int]. For instance, ST_RasterFromBands(ARRAY[1,3]) will burn new raster from 1 and 3 bands of input raster.~~
     2618
     2619----
     2620'''ST_AsPNG(raster, band) -> PNG as "bytea"'''
     2621
     2622Like the JPEG raster format, the PNG format has limitations:
     2623
     2624  1. PNG only allows 1 (greyscale) or 3 (RGB) bands of data
     2625
     2626  2. PNG only supports 8BUI and 16BUI pixeltypes. Any other pixeltype will be written as 8BUI, though the results are probably useless
     2627
     2628  3. PNG cannot embed spatial reference information within the file but can have an associated world file
     2629
     2630Like JPEG, the limitations can be resolved:
     2631
     2632  1. Use ST_Band to specify which band(s) should be passed to the ST_AsPNG function. If a raster whose number of specified bands does not equal 1 or 3 is provided, a warning is raised and the first or the first three bands are used.
     2633
     2634  2. Throw an exception if any of the specified bands is not 8BUI or 16BUI. The user should use ST_Reclass to convert any non-8BUI or 16BUI bands to 8BUI or 16BUI.
     2635
     2636  3. Nothing can be done within this function. ST_Georeference() can be used to the contents of the associated world file
     2637
     2638A proposed set of variations of the ST_AsPNG function:
     2639
     26401. ST_AsPNG(rast raster, options text[])
     2641
     2642    rast: the raster with one or three bands in 8BUI or 16BUI pixel type to generate a PNG image from
     2643
     2644    options: array of creation options to pass to the GDAL PNG driver
     2645
     2646{{{
     2647ST_AsPNG(rast, ARRAY['ZLEVEL=9'])
     2648}}}
     2649
     26502. ST_AsPNG(rast raster)
     2651
     2652    Like !#1 above but use the driver's default creation options
     2653
     26543. ST_AsPNG(rast raster, nbands int[], options text[])
     2655
     2656    nbands: an integer array specifying the band indices of the raster to include in the PNG file
     2657
     2658{{{
     2659ST_AsPNG(rast, ARRAY[3,1,2], ARRAY['ZLEVEL=9'])
     2660}}}
     2661
     26624. ST_AsPNG(rast raster, nbands int[])
     2663
     2664    Like !#3, but use the default creation options
     2665
     2666{{{
     2667ST_AsPNG(rast, ARRAY[3])
     2668}}}
     2669
     26705. ST_AsPNG(rast raster, nbands int[], compression int)
     2671
     2672    compression: number between 1 and 9 indicating the amount of time to spend on compression. 1 is fastest with least compression. 9 is slowest with best compression
     2673
     2674{{{
     2675ST_AsPNG(rast, ARRAY[2,1,3], 3)
     2676}}}
     2677
     26786. ST_AsPNG(rast raster, nband int, options text[])
     2679
     2680    nband: index of the band to include
     2681
     2682{{{
     2683ST_AsPNG(rast, 2, ARRAY['ZLEVEL=5'])
     2684}}}
     2685
     26867. ST_AsPNG(rast raster, nband int, compression int)
     2687
     2688{{{
     2689ST_AsPNG(rast, 1, 8)
     2690}}}
     2691
     26928. ST_AsPNG(rast raster, nband int)
     2693
     2694{{{
     2695ST_AsPNG(rast, 1)
     2696}}}
     2697
     2698----
     2699
     2700'''ST_AsGDALRaster(raster, band int, type text, options text) -> bytea'''
     2701
     2702Use GDAL to convert the raster into one of the format suported by GDAL.
     2703
     2704This is a generic interface to outputting a supported and installed GDAL raster:
     2705
     27061. ST_AsGDALRaster(rast raster, format text, options text[], srs text) -> bytea
     2707
     2708  This is the most generic and GDAL-specific method to convert a raster to a GDAL raster.  All other version of ST_AsGDALRaster and other format specific functions (ST_AsJPEG, ST_AsTIFF and ST_AsPNG) are all wrappers around this function.  Reference information for the format and options arguments of a particular format are specified at: http://gdal.org/formats_list.html.  The arguments specified are:
     2709
     2710  format: the GDAL format code.  e.g. GTiff, JPEG, PNG
     2711
     2712  options: the GDAL creation options found in the '''Creation Options''' section of a specified format.  e.g. COMPRESS=JPEG, JPEG_QUALITY=90
     2713
     2714  srs: the user-specified OGC WKT or the proj4 text for a spatial reference to embed in the GDAL raster.  Not all formats support embedding this information.  e.g. the non-empty value for the srtext or proj4text column from the spatial_ref_sys table.
     2715
     2716{{{
     2717ST_AsGDALRaster(rast, 'GTiff', ARRAY['COMPRESS=JPEG', 'JPEG_QUALITY=90'], '+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')
     2718
     2719ST_AsGDALRaster(rast, 'GTiff', ARRAY['COMPRESS=JPEG', 'JPEG_QUALITY=90'], '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]]')
     2720}}}
     2721
     2722
     27232. ST_AsGDALRaster(rast raster, format text, options text[]) -> bytea
     2724
     2725  This one removes the user-specified srs argument.  The output GDAL raster's spatial reference will be set to the same as the input raster, if possible.
     2726
     2727{{{
     2728ST_AsGDALRaster(rast, 'JPEG', ARRAY['QUALITY=50'])
     2729
     2730ST_AsGDALRaster(rast, 'PNG', ARRAY['ZLEVEL=7'])
     2731}}}
     2732
     27333. ST_AsGDALRaster(rast raster, format text) -> bytea
     2734
     2735  The simplest implementation of this function.  Since the options argument has been removed, the output GDAL raster will be created with default options.  Like the prior function, the spatial reference of the GDAL raster will be set to the same as the input raster.
     2736
     2737{{{
     2738ST_AsGDALRaster(rast, 'JPEG')
     2739}}}
     2740
     2741----
     2742
     2743'''ST_GDALDrivers() -> set of record'''
     2744
     2745As each GDAL installation may be different and ST_AsGDALRaster can be used to support formats other than GTiff, JPEG and PNG, a method is needed to expose to the end user the possible GDAL formats capable of being exported.  This function will output the following columns.
     2746
     2747  idx: the internal GDAL index number
     2748
     2749  short_name: the GDAL format code.  This is the value to pass to the format paramenter of ST_AsGDALRaster
     2750
     2751  long_name: the full name of the GDAL format
     2752
     2753  create_options: the creation options available for the format as an XML string.
     2754
     2755The formats outputted from ST_getGDALDrivers have been filtered to only those that the GDAL capabilities !CreateCopy and Virtual IO support.
     2756
     2757'''Open Question:''' Should the GDAL raster process be capable of supporting the GDAL capability Create?  As the GDAL raster process writes nothing to a file in the filesystem (via Virtual IO), should there be support for writing the output GDAL raster temporarily to the filesystem?  If so, how is it done in other PostgreSQL extensions in a secure manner?
     2758
     2759----
     2760
     2761'''ST_srtext(rast raster) -> text'''
     2762
     2763A helper function to get the value of column srtext or proj4text for a raster with an SRID.  By default, the srtext is returned.  If srtext is not available but proj4text is, the proj4text is returned.
     2764
     2765This function may be removed based upon the capabilities of SPI.  It may not be possible to remove this function as the srs function argument of ST_AsGDALRaster can be NULL, thereby instructing the function to not embed any spatial reference information into the output GDAL raster.
     2766
     2767----
     2768
     2769'''ST_Reclass(rast raster, VARIADIC argset reclassarg[]) -> raster'''
     2770
     2771Due to limitations in the JPEG (8BUI) and PNG (8BUI and 16BUI) raster formats regarding supported pixel/data types, a method must be provided that can convert a band of a larger data type to 8BUI, amongst other uses.  ST_Reclass allows raster's band pixel values to be remapped from one range of numbers to another as well as between pixel types, e.g. 32BF to 8BUI.
     2772
     2773ST_Reclass returns a duplicate of the submitted raster with the bands specified to be reclassed being processed.  This means that if a raster with 5 bands are submitted and band 1 is to be reclassed, the output raster will have 5 bands with band 1 reclassified.  The other four bands will not be touched.
     2774
     27751. ST_Reclass(rast raster, VARIADIC argset reclassarg[]) -> raster
     2776
     2777  rast: the raster whose specified bands are to be reclassified
     2778
     2779  reclassarg: a new custom type defining the parameters required for reclassifying a band's pixel values.
     2780
     2781{{{
     2782CREATE TYPE reclassarg AS (
     2783
     2784  nband int,
     2785
     2786  reclassexpr text,
     2787
     2788  pixeltype text,
     2789
     2790  nodata double
     2791
     2792);
     2793}}}
     2794
     2795    nband: index of the band to reclass (1-based)
     2796
     2797    reclassexpr: reclassification expression indicating the ranges to convert from and to.  More than one expression can be provided by separating the expression with a comma (,).  The values provided can be of any valid numeric type.
     2798
     2799      ''rangefrom:rangeto[, rangefrom:rangeto]''
     2800
     2801{{{
     28020-100:0-10
     2803
     28040-100:0-10, 101-1000:11-100
     2805
     28060-100:0-10, 101-1000:11-100, 1001-10000:101-1000
     2807}}}
     2808
     2809      In the last example above, the default evaluation of the ranges is
     2810
     2811{{{
     2812        0 <= x < 100 reclassified to 0 <= y <= 10
     2813
     2814        101 <= x < 1000 reclassified to 11 <= y <= 100
     2815
     2816        1001 <= x < 10000 reclassified to 101 <= y <= 1000
     2817}}}
     2818
     2819      To change the evaluation of rangefrom, use square brackets and parentheses.
     2820
     2821{{{
     28221. [a-b] = a <= x <= b
     2823
     28242. (a-b] = a < x <= b
     2825
     28263. [a-b) = a <= x < b
     2827
     28284. (a-b) = a < x < b
     2829}}}
     2830
     2831      !#3 above is the default evaluation of x in the range a-b. The use of square brackets and parentheses are optional, so the examples below would be permitted. Missing notations substitute the appropriate notation from #3 above.
     2832
     2833{{{
     2834[a-b = a <= x < b
     2835
     2836(a-b = a < x < b
     2837
     2838a-b] = a <= x <= b
     2839
     2840a-b) = a <= x < b
     2841}}}
     2842
     2843      Two special cases are also available for use when x may be outside the range of a-b.  This situation is possible if your range is based upon an approximation, such as from ST_ApproxMinMax.
     2844
     2845{{{
     2846]a-b or )a-b = x < a, rule matches
     2847
     2848a-b[ or a-b( = x >= b, rule matches
     2849}}}
     2850
     2851    pixeltype: the reclassified band's pixel type, e.g. 8BUI, 16BUI, 32BF
     2852
     2853    nodata: the nodata value of the reclassified band.  If the source band has a nodata value, all source pixel value equal to the source nodata value will be converted to the reclassified band's nodata value.  If set to NULL, the reclassified band will NOT have a nodata value specified.
     2854
     2855{{{
     2856ST_Reclass(rast, ROW(1, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', NULL));
     2857
     2858ST_Reclass(rast, ROW(1, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001));
     2859
     2860ST_Reclass(rast,
     2861  ROW(1, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001),
     2862  ROW(2, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001),
     2863  ROW(3, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001),
     2864  ROW(5, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001)
     2865)
     2866}}}
     2867
     2868  An expanded example
     2869
     2870{{{
     2871SELECT ST_Reclass(
     2872  ST_Band(rast, ARRAY[1,1,1]),
     2873  ROW(1, LEAST(covmin, 0)::text || '-0:0,0-' || GREATEST(covmax, 0)::text || ':0-255', '8BUI'),
     2874  ROW(2, LEAST(covmin, 0)::text || '-0:200,0-' || GREATEST(covmax, 0)::text' || ':0-255','8BUI'),
     2875  ROW(3, LEAST(covmin, 0)::text || '-0:255,0-' || (GREATEST(covmax, 0)/2)::text' || ':0,' || (GREATEST(covmax, 0)/2)::text' || ':' || GREATEST(covmax, 0)::text || ':0-255', '8BUI')
     2876)
     2877FROM mycoverage
     2878}}}
     2879
     28802. ST_Reclass(rast raster, nband int, reclassexpr text, pixeltype text, nodata double) -> raster
     2881
     2882  provides a method to process just one band of a raster
     2883
     2884{{{
     2885ST_Reclass(rast, 1, '0-100:0-10', '8BUI', 11)
     2886}}}
     2887
     28883. ST_Reclass(rast raster, nband int, reclassexpr text, pixeltype text) -> raster
     2889
     2890  nodata parameter removed so reclassified band will NOT have a nodata value set
     2891
     2892{{{
     2893ST_Reclass(rast, 1, '0-100:0-10', '8BUI')
     2894}}}
     2895
     28964. ST_Reclass(rast raster, reclassexpr text, pixeltype text) -> raster
     2897
     2898  nband parameter removed so reclassified band is assumed to be 1.  nodata parameter removed so reclassified band has NO nodata value.
     2899
     2900{{{
     2901ST_Reclass(rast, '0-100:0-10', '8BUI')
     2902}}}
     2903
     29045. ST_Reclass(rast raster, reclassexpr text, pixeltype text, nodata double) -> raster
     2905
     2906  nband parameter removed so reclassified band is assumed to be 1
     2907
     2908{{{
     2909ST_Reclass(rast, '0-100:0-10', '8BUI', 11)
     2910}}}