Ticket #902 (closed task: fixed)

Opened 2 years ago

Last modified 2 years ago

[raster] ST_MinMax

Reported by: dustymugs Owned by: dustymugs
Priority: medium Milestone: PostGIS 2.0.0
Component: raster Version: trunk
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

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

Change History

Changed 2 years ago by dustymugs

  • status changed from new to assigned

Changed 2 years ago by dustymugs

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.

Changed 2 years ago by pracine

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

Perfect!

Changed 2 years ago by dustymugs

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

Changed 2 years ago by dustymugs

Adds ST_MinMax and ST_ApproxMinMax

Changed 2 years ago by dustymugs

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

Changed 2 years ago by dustymugs

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

Changed 2 years ago by dustymugs

New patch due to refactoring in preparation for computing additonal stats

Changed 2 years ago by dustymugs

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?

2. Mean

3. Standard Deviation

4. # 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.

Changed 2 years ago by dustymugs

Changes to ST_MinMax regarding the "sample" function parameter

Changed 2 years ago by dustymugs

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.

Changed 2 years ago by dustymugs

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

Changed 2 years ago by dustymugs

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)

2. ST_MinMax(rastertable text, rastercolumn text, nband int) -> record

hasnodata is set to FALSE

ST_MinMax('tmax_2010', 'rast', 1)

3. ST_MinMax(rastertable text, rastercolumn text, hasnodata boolean) -> record

nband is set to 1

ST_MinMax('precip_2011', 'rast', TRUE)

4. 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)

2. 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)

3. 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)

4. 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)

5. 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')

Changed 2 years ago by dustymugs

Refactored to depend upon ST_SummaryStats instead of the original function.

Changed 2 years ago by dustymugs

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

2. ST_SummaryStats

3. ST_Mean

4. ST_StdDev

Changed 2 years ago by dustymugs

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

Added in r7151

Changed 2 years ago by dustymugs

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