Changes between Version 123 and Version 124 of WKTRaster/SpecificationWorking01


Ignore:
Timestamp:
Sep 17, 2010, 8:59:53 AM (14 years ago)
Author:
pracine
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • WKTRaster/SpecificationWorking01

    v123 v124  
    375375
    376376
    377 ----
    378 
    379 == '''Objective 0.1.6f - Being able to return a JPEG, a TIFF or a PNG.''' ==
    380  
    381 '''ST_bytea(raster, integer) -> raster''' -- the integer parameters is the band number of the raster.[[BR]]
    382 What is does?
    383 
    384 ----
    385 '''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.
    386 
    387 There is two options to select the band to convert from a multiband raster in all the ST_AsFormat functions. [[BR]]
    388 [[BR]]
    389  1. Precede each call with ST_Band() to return a selected band.[[BR]]
    390   Pros: This is a general function that can be called before any function that would otherwise require a band parameter.[[BR]]
    391   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?
    392 
    393  2. Add a band parameter to each ST_AsFormat function.[[BR]]
    394   Pros: Hypothetically less overhead.[[BR]]
    395   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.
    396 
    397 Pierre: More I think about it more I think that the first option is the best one...
    398 
    399 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.
    400 
    401 ----
    402 
    403 '''ST_Band(raster, integer) -> raster''' -- the integer parameters are the band number of the rasters.[[BR]]
    404 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))
    405 
    406 ----
    407 '''ST_AsJPEG(raster, quality) -> JPEG as "bytea"'''[[BR]]
    408 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)
    409 
    410 
    411 '''Open Question:''' Is JPEG export limited to raster having 8 bit unsigned integer pixeltype (8BUI)?
    412 
    413 [http://www.gdal.org/frmt_jpeg.html See how GDAL do it]. It converts only 8 bits rasters. Should we do the same?
    414 
    415 Otherwise, how do we convert other types to 8BUI? e.g. 16BUI or 8BSI?
    416 
    417 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.
    418 
    419 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).
    420 
    421 Proposition two: There could also be just one parameter (string) defining a mapping method:
    422 
    423  * Method "None": No mapping. This is possible only for 8BUI.
    424 
    425  * 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]]
    426 [[BR]]This is equivalent to ST_AsJPEG(raster, quality, ST_Minimum(rast), ST_Maximum(rast))
    427 
    428  * 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]]
    429 [[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.]
    430 
    431 
    432 mloskot: ATM, I have no thoughts on this issue.
    433 
    434 '''Open Question:''' Is JPEG export limited to raster having 1 or 3 bands?
    435 
    436 [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.
    437 
    438 Pierre: I think the answer should be yes. I don't see how we could have a 2 band raster fit into RGB.
    439 
    440 mloskot: I agree, the answer should be yes.
    441 
    442 '''Here is an attempt to define the different versions of the function:'''
    443 
    444 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:
    445 
    446 ST_AsJPEG(raster) -quality = 75
    447 
    448 A variant allow specifying the quality:
    449 
    450 ST_AsJPEG(raster, integer)
    451 
    452 Another variant should enable us to specify which band correspond to the r, the g and the b:
    453 
    454 ST_AsJPEG(raster, integer, integer, integer) - raster, rband, gband, bband, quality=75[[BR]]
    455 ST_AsJPEG(raster, integer, integer, integer, integer) - raster, rband, gband, bband, quality
    456 
    457 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:
    458 
    459 ST_AsJPEG(raster, raster, raster)[[BR]]
    460 ST_AsJPEG(raster, raster, raster, integer) -with the quality param
    461 
    462 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):
    463 
    464 ST_AsJPEG(raster, "GRAYSCALE") - convert only band 1 with quality = 75[[BR]]
    465 ST_AsJPEG(raster, "GRAYSCALE", integer) - convert only band 1 with specified quality[[BR]]
    466 ST_AsJPEG(raster, integer, "GRAYSCALE") - allow specifying the band number to convert[[BR]]
    467 ST_AsJPEG(raster, integer, "GRAYSCALE", integer) - allow specifying the band number to convert and the quality
    468 
    469 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".
    470 
    471 ST_AsJPEG(raster, "GRAYSCALE", min, max, text) - convert only band 1 with quality = 75[[BR]]
    472 ST_AsJPEG(raster, "GRAYSCALE", integer, min, max, text) - convert only band 1 with specified quality[[BR]]
    473 ST_AsJPEG(raster, integer, "GRAYSCALE", min, max, text) - allow specifying the band number to convert[[BR]]
    474 ST_AsJPEG(raster, integer, "GRAYSCALE", integer, min, max, text) - allow specifying the band number to convert and the quality
    475 
    476 
    477 ----
    478 
    479 '''ST_AsTIFF(raster, compression) -> TIFF as "bytea"'''[[BR]]
    480 Return 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.
    481 
    482 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)
    483 
    484 ----
    485 '''Open Question:''' What if we want to export only the first two band of a three band layer?
    486 
    487 Maybe we need a ST_RasterFromBands(band1,band2,etc...) to reconstitute a multiband raster from multiple sources (having the same width, height, pixelsize, etc...)
    488 
    489 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.
    490 
    491 ----
    492 '''ST_AsPNG(raster, band) -> PNG as "bytea"'''
    493377
    494378----