Changes between Version 25 and Version 26 of WKTRaster/SpecificationWorking03


Ignore:
Timestamp:
Sep 17, 2010, 9:00:20 AM (14 years ago)
Author:
pracine
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • WKTRaster/SpecificationWorking03

    v25 v26  
    1212
    1313}}}
     14----
     15
     16== '''Objective 01 - Being able to return a JPEG, a TIFF or a PNG.''' ==
     17 
     18'''ST_bytea(raster, integer) -> raster''' -- the integer parameters is the band number of the raster.[[BR]]
     19What is does?
     20
     21----
     22'''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.
     23
     24There is two options to select the band to convert from a multiband raster in all the ST_AsFormat functions. [[BR]]
     25[[BR]]
     26 1. Precede each call with ST_Band() to return a selected band.[[BR]]
     27  Pros: This is a general function that can be called before any function that would otherwise require a band parameter.[[BR]]
     28  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?
     29
     30 2. Add a band parameter to each ST_AsFormat function.[[BR]]
     31  Pros: Hypothetically less overhead.[[BR]]
     32  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.
     33
     34Pierre: More I think about it more I think that the first option is the best one...
     35
     36mloskot: 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.
     37
     38----
     39
     40'''ST_Band(raster, integer) -> raster''' -- the integer parameters are the band number of the rasters.[[BR]]
     41Return 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))
     42
     43----
     44'''ST_AsJPEG(raster, quality) -> JPEG as "bytea"'''[[BR]]
     45Return 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)
     46
     47
     48'''Open Question:''' Is JPEG export limited to raster having 8 bit unsigned integer pixeltype (8BUI)?
     49
     50[http://www.gdal.org/frmt_jpeg.html See how GDAL do it]. It converts only 8 bits rasters. Should we do the same?
     51
     52Otherwise, how do we convert other types to 8BUI? e.g. 16BUI or 8BSI?
     53
     54Pierre: 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.
     55
     56Proposition 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).
     57
     58Proposition two: There could also be just one parameter (string) defining a mapping method:
     59
     60 * Method "None": No mapping. This is possible only for 8BUI.
     61
     62 * 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]]
     63[[BR]]This is equivalent to ST_AsJPEG(raster, quality, ST_Minimum(rast), ST_Maximum(rast))
     64
     65 * 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]]
     66[[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.]
     67
     68
     69mloskot: ATM, I have no thoughts on this issue.
     70
     71'''Open Question:''' Is JPEG export limited to raster having 1 or 3 bands?
     72
     73[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.
     74
     75Pierre: I think the answer should be yes. I don't see how we could have a 2 band raster fit into RGB.
     76
     77mloskot: I agree, the answer should be yes.
     78
     79'''Here is an attempt to define the different versions of the function:'''
     80
     81The most minimalistic versions of the function should assume band 1, 2 and 3 as being r, g, b and the quality equal to 75:
     82
     83ST_AsJPEG(raster) -quality = 75
     84
     85A variant allow specifying the quality:
     86
     87ST_AsJPEG(raster, integer)
     88
     89Another variant should enable us to specify which band correspond to the r, the g and the b:
     90
     91ST_AsJPEG(raster, integer, integer, integer) - raster, rband, gband, bband, quality=75[[BR]]
     92ST_AsJPEG(raster, integer, integer, integer, integer) - raster, rband, gband, bband, quality
     93
     94Another 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:
     95
     96ST_AsJPEG(raster, raster, raster)[[BR]]
     97ST_AsJPEG(raster, raster, raster, integer) -with the quality param
     98
     99Another 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):
     100
     101ST_AsJPEG(raster, "GRAYSCALE") - convert only band 1 with quality = 75[[BR]]
     102ST_AsJPEG(raster, "GRAYSCALE", integer) - convert only band 1 with specified quality[[BR]]
     103ST_AsJPEG(raster, integer, "GRAYSCALE") - allow specifying the band number to convert[[BR]]
     104ST_AsJPEG(raster, integer, "GRAYSCALE", integer) - allow specifying the band number to convert and the quality
     105
     106Another 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".
     107
     108ST_AsJPEG(raster, "GRAYSCALE", min, max, text) - convert only band 1 with quality = 75[[BR]]
     109ST_AsJPEG(raster, "GRAYSCALE", integer, min, max, text) - convert only band 1 with specified quality[[BR]]
     110ST_AsJPEG(raster, integer, "GRAYSCALE", min, max, text) - allow specifying the band number to convert[[BR]]
     111ST_AsJPEG(raster, integer, "GRAYSCALE", integer, min, max, text) - allow specifying the band number to convert and the quality
     112
     113
     114----
     115
     116'''ST_AsTIFF(raster, compression) -> TIFF as "bytea"'''[[BR]]
     117Return the raster as a JPEG 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.
     118
     119compression=[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)
     120
     121----
     122'''Open Question:''' What if we want to export only the first two band of a three band layer?
     123
     124Maybe we need a ST_RasterFromBands(band1,band2,etc...) to reconstitute a multiband raster from multiple sources (having the same width, height, pixelsize, etc...)
     125
     126mloskot: 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.
     127
     128----
     129'''ST_AsPNG(raster, band) -> PNG as "bytea"'''
     130
    14131----
    15132== '''Objective 02 - Being able to intersect vector and raster to produce raster.''' ==