Opened 15 years ago

Closed 14 years ago

Last modified 14 years ago

#342 closed task (fixed)

[raster] ST_AsPNG

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

Description (last modified by pracine)

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.

See the working specifications for more details/questions.

Attachments (3)

st_aspng.patch (7.1 KB ) - added by dustymugs 14 years ago.
Add ST_AsPNG capability
st_aspng.2.patch (7.1 KB ) - added by dustymugs 14 years ago.
No changes made. Update diff due to incremental changes in ST_MinMax.
st_aspng.3.patch (7.1 KB ) - added by dustymugs 14 years ago.
Updated error messages

Download all attachments as: .zip

Change History (16)

comment:1 by mloskot, 15 years ago

Owner: changed from pracine to mloskot
Status: newassigned

comment:2 by pracine, 15 years ago

Version: trunk

comment:3 by pracine, 15 years ago

Description: modified (diff)

comment:4 by pracine, 14 years ago

Milestone: WKTRaster 0.1.6WKTRaster Future

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

comment:5 by pracine, 14 years ago

Summary: [wktraster] Implement ST_AsPNG function for raster[raster] Implement ST_AsPNG function for raster

comment:6 by pracine, 14 years ago

Status: assignednew

comment:7 by dustymugs, 14 years ago

Like the JPEG raster format, the PNG format has limitations:

  1. PNG only allows 1 (greyscale) or 3 (RGB) bands of data
  1. PNG only supports 8BUI and 16BUI pixeltypes. Any other pixeltype will be written as 8BUI, though the results are probably useless
  1. PNG cannot embed spatial reference information within the file but can have an associated world file

Like JPEG, the limitations can be resolved:

  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.
  1. 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.
  1. Nothing can be done within this function. ST_Georeference() can be used to the contents of the associated world file

A proposed set of variations of the ST_AsPNG function:

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

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

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

ST_AsPNG(rast, ARRAY['ZLEVEL=9'])
  1. ST_AsPNG(rast raster)

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

  1. ST_AsPNG(rast raster, nbands int[], options text[])

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

ST_AsPNG(rast, ARRAY[3,1,2], ARRAY['ZLEVEL=9'])
  1. ST_AsPNG(rast raster, nbands int[])

Like #3, but use the default creation options

ST_AsPNG(rast, ARRAY[3])
  1. ST_AsPNG(rast raster, nbands int[], compression int)

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

ST_AsPNG(rast, ARRAY[2,1,3], 3)
  1. ST_AsPNG(rast raster, nband int, options text[])

nband: index of the band to include

ST_AsPNG(rast, 2, ARRAY['ZLEVEL=5'])
  1. ST_AsPNG(rast raster, nband int, compression int)
ST_AsPNG(rast, 1, 8)
  1. ST_AsPNG(rast raster, nband int)
ST_AsPNG(rast, 1)

comment:8 by dustymugs, 14 years ago

Owner: changed from mloskot to dustymugs

by dustymugs, 14 years ago

Attachment: st_aspng.patch added

Add ST_AsPNG capability

comment:9 by dustymugs, 14 years ago

Status: newassigned

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

patch -p1 < st_aspng.patch

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

comment:10 by dustymugs, 14 years ago

Summary: [raster] Implement ST_AsPNG function for raster[raster] ST_AsPNG

by dustymugs, 14 years ago

Attachment: st_aspng.2.patch added

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

by dustymugs, 14 years ago

Attachment: st_aspng.3.patch added

Updated error messages

comment:11 by dustymugs, 14 years ago

Add ST_AsPNG. Merges cleanly against r7145.

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

  1. ST_Band
  1. ST_SummaryStats
  1. ST_Mean
  1. ST_StdDev
  1. ST_MinMax
  1. ST_Histogram
  1. ST_Quantile
  1. ST_Reclass
  1. ST_AsGDALRaster
  1. ST_AsTIFF
  1. ST_AsJPEG

comment:12 by dustymugs, 14 years ago

Keywords: history added
Resolution: fixed
Status: assignedclosed

Added in r7158

comment:13 by robe, 14 years ago

Milestone: PostGIS Raster FuturePostGIS 2.0.0
Note: See TracTickets for help on using tickets.