Ticket #340 (closed task: fixed)

Opened 2 years ago

Last modified 9 months ago

[raster] ST_AsJPEG

Reported by: mloskot Owned by: dustymugs
Priority: medium Milestone: PostGIS 2.0.0
Component: raster Version: trunk
Keywords: history Cc:

Description (last modified by pracine) (diff)

This tasks belongs to the Objective 0.1.6f specified in the WKT Raster roadmap

As stated at the end of the comment 5 of the "Specification Comments following the Code Sprint" section of the working specifications, this function should be a PL/pgSQL wrapper around a more general ST_AsImage(format, params) function using GDAL to convert any raster to an image.

The function should return a bytea.

This function is particularly sensible to the number of band present in the raster as it normally needs 3 band (r,g,b).

It is also very sensible to the pixel type of the raster since JPEG supports only values in the 0-255 range.

See the working specifications for more details/questions.

Priority should be given to these variants:

ST_AsJPEG(raster, integer)
ST_AsJPEG(raster, integer, integer, integer, integer)
ST_AsJPEG(raster, integer, "GRAYSCALE", integer, min, max, text)

Attachments

st_asjpeg.patch Download (6.4 KB) - added by dustymugs 10 months ago.
Adds ST_AsJPEG capability
st_asjpeg.2.patch Download (6.4 KB) - added by dustymugs 10 months ago.
No changes made. Update diff due to incremental changes in ST_MinMax.
st_asjpeg.3.patch Download (6.4 KB) - added by dustymugs 9 months ago.
Updated to follow error messaging guidelines

Change History

Changed 2 years ago by mloskot

  • owner changed from pracine to mloskot
  • status changed from new to assigned

Changed 2 years ago by pracine

  • version set to trunk

Changed 2 years ago by pracine

  • description modified (diff)

Changed 2 years ago by pracine

  • description modified (diff)

Changed 17 months ago by pracine

  • milestone changed from WKTRaster 0.1.6 to WKTRaster Future

A more general ST_AsImage invoking GDAL should be implemented first. ST_AsJPEG should be a wrapper around this more generic function.

Changed 17 months ago by pracine

  • summary changed from [wktraster] Implement ST_AsJPEG function for raster to [raster] Implement ST_AsJPEG function for raster

Changed 13 months ago by pracine

  • status changed from assigned to new

Changed 10 months ago by dustymugs

The JPEG format has several limitations:

1. JPEG only allows 1 (greyscale) or 3 (RGB) bands of data

2. JPEG only supports 8BUI pixeltype

3. JPEG cannot embed spatial reference information within the file

To address the limitations:

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.

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.

3. Nothing can be done.

A proposed set of variations of the ST_AsJPEG function:

1. ST_AsJPEG(rast raster, options text[])

rast: the raster with one or three bands in 8BUI pixel type to generate a JPEG image from

options: array of creation options to pass to the GDAL JPEG driver

ST_AsJPEG(rast, ARRAY['QUALITY=90', 'PROGRESSIVE=ON'])

2. ST_AsJPEG(rast raster)

Like #1 above but use the driver's default creation options

3. ST_AsJPEG(rast raster, nbands int[], options text[])

nbands: an integer array specifying the band indices of the raster to include in the JPEG file

ST_AsJPEG(rast, ARRAY[1,3,6], ARRAY['QUALITY=50'])

4. ST_AsJPEG(rast raster, nbands int[])

Like #3, but use the default creation options

ST_AsJPEG(rast, ARRAY[1,3,6])

5. ST_AsJPEG(rast raster, compression int)

compression: number between 10 and 100 indicating image quality

ST_AsJPEG(rast, 90)

6. ST_AsJPEG(rast raster, nbands int[] compression int)

ST_AsJPEG(rast, ARRAY[1,2,3], 90)

7. ST_AsJPEG(rast raster, nband int, options text[])

nband: index of the band to include

ST_AsJPEG(rast, 2, ARRAY['QUALITY=25'])

8. ST_AsJPEG(rast raster, nband int, compression int)

ST_AsJPEG(rast, 5, 75)

9. ST_AsJPEG(rast raster, nband int)

ST_AsJPEG(rast, 4)

In looking over the working spec's ST_AsJPEG, I don't believe the GREYSCALE variations are usable as the JPEG driver automatically creates a greyscale image if the raster passed to it has one band.

Changed 10 months ago by pracine

I would just rename the "compression" parameter to "quality".

Changed 10 months ago by pracine

Just for the record, JPEG cannot embed spatial reference information within the file but an application can get a sister wordfile with this query: SELECT ST_Georeference(rast) FROM mytable.

Changed 10 months ago by dustymugs

  • owner changed from mloskot to dustymugs
  • status changed from new to assigned

Changed 10 months ago by dustymugs

Adds ST_AsJPEG capability

Changed 10 months ago by dustymugs

Attached incremental patch for adding ST_AsJPEG. Patch can be applied with the following in the base postgis source directory.

patch -p1 < st_asjpeg.patch

Patches for ST_Band, ST_MinMax, ST_Reclass and ST_AsGDALRaster must be applied first in the order listed.

Changed 10 months ago by dustymugs

  • summary changed from [raster] Implement ST_AsJPEG function for raster to [raster] ST_AsJPEG

Changed 10 months ago by dustymugs

No changes made. Update diff due to incremental changes in ST_MinMax.

Changed 9 months ago by dustymugs

Updated to follow error messaging guidelines

Changed 9 months ago by dustymugs

Add ST_AsJPEG. Merges cleanly against r7145.

The following patches must be merged first for this patch to merge cleanly:

1. ST_Band

2. ST_SummaryStats

3. ST_Mean

4. ST_StdDev

5. ST_MinMax

6. ST_Histogram

7. ST_Quantile

8. ST_Reclass

9. ST_AsGDALRaster

10. ST_AsTIFF

Changed 9 months ago by dustymugs

  • keywords history added
  • status changed from assigned to closed
  • resolution set to fixed

Added in r7157

Changed 9 months ago by robe

  • milestone changed from PostGIS Raster Future to PostGIS 2.0.0
Note: See TracTickets for help on using tickets.