- #1839, handling of subdatasets in GeoTIFF in raster2pgsql.
- #1840, fix logic of when to compute # of tiles in raster2pgsql.
+ - #1872, fix ST_ApproxSummarystats to prevent division by zero.
PostGIS 2.0.1
2012/06/DD
* @return the summary statistics for a band
*/
rt_bandstats
-rt_band_get_summary_stats(rt_band band, int exclude_nodata_value, double sample,
- int inc_vals, uint64_t *cK, double *cM, double *cQ) {
+rt_band_get_summary_stats(
+ rt_band band,
+ int exclude_nodata_value, double sample, int inc_vals,
+ uint64_t *cK, double *cM, double *cQ
+) {
uint8_t *data = NULL;
uint32_t x = 0;
uint32_t y = 0;
assert(NULL != band);
+ /* band is empty (width < 1 || height < 1) */
+ if (band->width < 1 || band->height < 1) {
+ stats = (rt_bandstats) rtalloc(sizeof(struct rt_bandstats_t));
+ if (NULL == stats) {
+ rterror("rt_band_get_summary_stats: Unable to allocate memory for stats");
+ return NULL;
+ }
+
+ rtwarn("Band is empty as width and/or height is 0");
+
+ stats->sample = 1;
+ stats->sorted = 0;
+ stats->values = NULL;
+ stats->count = 0;
+ stats->min = stats->max = 0;
+ stats->sum = 0;
+ stats->mean = 0;
+ stats->stddev = -1;
+
+ return stats;
+ }
+
data = rt_band_get_data(band);
if (data == NULL) {
rterror("rt_band_get_summary_stats: Cannot get band data");
else {
sample_size = round((band->width * band->height) * sample);
sample_per = round(sample_size / band->width);
+ if (sample_per < 1)
+ sample_per = 1;
sample_int = round(band->height / sample_per);
srand(time(NULL));
}
)
, 2
);
+SELECT ST_ApproxSummaryStats(
+ ST_Clip(
+ ST_AddBand(
+ ST_MakeEmptyRaster(10, 10, 0, 0, 1, 1, 0, 0, 0)
+ , '16BSI'::text, 0, 0
+ )
+ , ST_MakeEnvelope(0, 0, 10, 5, 0)
+ )
+ , 1, true, 0.1
+);
+SELECT ST_SummaryStats(
+ ST_AddBand(
+ ST_MakeEmptyRaster(10, 0, 0, 0, 1, -1, 0, 0, 0)
+ , '8BUI'::text, 1, 0
+ )
+);
BEGIN;
CREATE TEMP TABLE test_summarystats
ON COMMIT DROP AS