Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#902 closed task (fixed)

[raster] ST_MinMax

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

Description

As part of the process to provide complete implementations of ST_AsJPEG and ST_AsPNG, a method is required to reclassify larger numbers unable to be contained in 8BUI (JPEG and PNG) and 16BUI (PNG). For this reclassification function, we need to get the min and max values of a band, thus ST_MinMax.

ST_MinMax(rast raster, nband int) → set of record

returns one record of two columns (min, max)

ST_MinMax(rast, 2)

ST_MinMax(rast raster) → set of record

assumes that the band index = 1

ST_MinMax(rast)

Attachments (5)

st_minmax.patch (17.9 KB ) - added by Bborie Park 13 years ago.
Adds ST_MinMax and ST_ApproxMinMax
st_minmax.2.patch (20.7 KB ) - added by Bborie Park 13 years ago.
New patch due to refactoring in preparation for computing additonal stats
st_minmax.3.patch (21.1 KB ) - added by Bborie Park 13 years ago.
Changes to ST_MinMax regarding the "sample" function parameter
st_minmax.4.patch (27.0 KB ) - added by Bborie Park 13 years ago.
Function parameter "no_nodata" is now "hasnodata" and behaves like the identical parameter of ST_Intersects
st_minmax.5.patch (7.6 KB ) - added by Bborie Park 13 years ago.
Refactored to depend upon ST_SummaryStats instead of the original function.

Download all attachments as: .zip

Change History (17)

comment:1 by Bborie Park, 13 years ago

Status: newassigned

comment:2 by Bborie Park, 13 years ago

Additional variations of the ST_MinMax function

ST_MinMax(rast raster, nband int, ignore_nodata boolean) → set of record (min float8, max float8)

instruct the function to ignore NODATA values in the band

ST_MinMax(rast raster, ignore_nodata boolean) → set of record (min float8, max float8)

assume band index = 1

The prior two versions of the function

ST_MinMax(rast raster, nband int) → set of record

ST_MinMax(rast raster) → set of record

will also assume that ignore_nodata is TRUE.

comment:3 by pracine, 13 years ago

The return value is not a "set of record" but just "a record".

Perfect!

comment:4 by Bborie Park, 13 years ago

Due to time it takes for ST_MinMax to run on large rasters, I would like to add a function that randomly samples a percentage of the pixels of a specified band for an approximate min and max. So, something like:

  1. ST_ApproxMinMax(rast raster, nband int, sample int)

sample: a value of between 0 and 100 indicating the percentage of the raster to sample

by Bborie Park, 13 years ago

Attachment: st_minmax.patch added

Adds ST_MinMax and ST_ApproxMinMax

comment:5 by Bborie Park, 13 years ago

Attached patch for adding ST_MinMax and ST_ApproxMinMax support. Patch can be applied with the following in the base postgis source directory.

patch -p1 < st_minmax.patch

comment:6 by Bborie Park, 13 years ago

Forgot to mention that this is an incremental patch. The patch for ST_Band should be used first.

by Bborie Park, 13 years ago

Attachment: st_minmax.2.patch added

New patch due to refactoring in preparation for computing additonal stats

comment:7 by Bborie Park, 13 years ago

Added patch (the patch for ST_Band must be applied first) that refactors the function in rt_api.c in preparation for calculation of additional stats. As it stands, the rt_api.c function currently computes…

  1. Min/Max
  1. Mean
  1. Standard Deviation
  1. # of values used in the stats

The rt_api.c function will also return the actual values used in the stats for subsequent processing, e.g. ST_Histogram and ST_Quantile.

by Bborie Park, 13 years ago

Attachment: st_minmax.3.patch added

Changes to ST_MinMax regarding the "sample" function parameter

comment:8 by Bborie Park, 13 years ago

New patch renames the ST_MinMax parameter "sample" to "sample_percent". It also changes the format of "sample_percent" from a number between 0 and 100 to 0 and 1, which is inline with the percentage format used for ST_ConvexHull.

by Bborie Park, 13 years ago

Attachment: st_minmax.4.patch added

Function parameter "no_nodata" is now "hasnodata" and behaves like the identical parameter of ST_Intersects

comment:9 by Bborie Park, 13 years ago

A set of ST_MinMax and ST_ApproxMinMax variations for processing coverages:

  1. ST_MinMax(rastertable text, rastercolumn text, nband int, hasnodata boolean) → record
ST_MinMax('tmax_2010', 'rast', 1, FALSE)

ST_MinMax('precip_2011', 'rast', 1, TRUE)
  1. ST_MinMax(rastertable text, rastercolumn text, nband int) → record

hasnodata is set to FALSE

ST_MinMax('tmax_2010', 'rast', 1)
  1. ST_MinMax(rastertable text, rastercolumn text, hasnodata boolean) → record

nband is set to 1

ST_MinMax('precip_2011', 'rast', TRUE)
  1. ST_MinMax(rastertable text, rastercolumn text) → record

nband is set to 1 and hasnodata is set to FALSE

ST_MinMax('tmin_2009', 'rast')

Variations for ST_ApproxMinMax are:

  1. ST_ApproxMinMax(rastertable text, rastercolumn text, nband int, hasnodata boolean, sample_percent double precision) → record
ST_ApproxMinMax('tmax_2010', 'rast', 1, FALSE, 0.5)

ST_ApproxMinMax('precip_2011', 'rast', 1, TRUE, 0.2)
  1. ST_ApproxMinMax(rastertable text, rastercolumn text, nband int, sample_percent double precision) → record

hasnodata is set to FALSE

ST_ApproxMinMax('tmax_2010', 'rast', 1, 0.5)

ST_ApproxMinMax('precip_2011', 'rast', 1, 0.2)
  1. ST_ApproxMinMax(rastertable text, rastercolumn text, hasnodata boolean, sample_percent double precision) → record

nband is set to 1

ST_ApproxMinMax('tmax_2010', 'rast', FALSE, 0.5)

ST_ApproxMinMax('precip_2011', 'rast', TRUE, 0.2)
  1. ST_ApproxMinMax(rastertable text, rastercolumn text, sample_percent double precision) → record

nband is set to 1 and hasnodata is set to FALSE

ST_ApproxMinMax('tmax_2010', 'rast', 0.5)

ST_ApproxMinMax('precip_2011', 'rast', 0.2)
  1. ST_ApproxMinMax(rastertable text, rastercolumn text) → record

nband is set to 1, hasnodata is set to FALSE and sample_percent is set to 0.1

ST_ApproxMinMax('tmax_2010', 'rast')

ST_ApproxMinMax('precip_2011', 'rast')

by Bborie Park, 13 years ago

Attachment: st_minmax.5.patch added

Refactored to depend upon ST_SummaryStats instead of the original function.

comment:10 by Bborie Park, 13 years ago

Adds ST_MinMax function, which builds upon ST_SummaryStats. 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

comment:11 by Bborie Park, 13 years ago

Keywords: history added
Resolution: fixed
Status: assignedclosed

Added in r7151

comment:12 by Bborie Park, 13 years ago

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