]> granicus.if.org Git - postgis/commitdiff
- taking a suggestion from strk in #958, all regression tests for functions related...
authorBborie Park <bkpark at ucdavis.edu>
Wed, 18 May 2011 23:33:05 +0000 (23:33 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Wed, 18 May 2011 23:33:05 +0000 (23:33 +0000)
- added additional argument checks for pgraster to rt_pg.c
- changed floating point comparisons in rt_pg.c and rt_api.c

git-svn-id: http://svn.osgeo.org/postgis/trunk@7196 b70326c6-7e19-0410-871a-916f4a2858ee

14 files changed:
raster/rt_core/rt_api.c
raster/rt_pg/rt_pg.c
raster/test/regress/rt_histogram.sql
raster/test/regress/rt_histogram_expected
raster/test/regress/rt_mean.sql
raster/test/regress/rt_mean_expected
raster/test/regress/rt_minmax.sql
raster/test/regress/rt_minmax_expected
raster/test/regress/rt_quantile.sql
raster/test/regress/rt_quantile_expected
raster/test/regress/rt_stddev.sql
raster/test/regress/rt_stddev_expected
raster/test/regress/rt_summarystats.sql
raster/test/regress/rt_summarystats_expected

index 62be5de4045078f3dad7529b217bb631f0a6555b..b1fc8114f4254c0ecb4b215cbead353310f345b2 100644 (file)
@@ -1524,6 +1524,7 @@ rt_band_get_summary_stats(rt_band band, int hasnodata, double sample,
        double value;
        rt_bandstats stats = NULL;
 
+       uint32_t do_sample = 0;
        uint32_t sample_size = 0;
        int byY = 0;
        uint32_t outer = 0;
@@ -1607,11 +1608,19 @@ rt_band_get_summary_stats(rt_band band, int hasnodata, double sample,
        }
 
        /* clamp percentage */
-       if (sample <= 0 || sample > 1)
+       if (
+               (sample < 0 || fabs(sample - 0.0) < FLT_EPSILON) ||
+               (sample > 1 || fabs(sample - 1.0) < FLT_EPSILON)
+       ) {
+               do_sample = 0;
                sample = 1;
+       }
+       else
+               do_sample = 1;
+       RASTER_DEBUGF(3, "do_sample = %d", do_sample);
 
        /* sample all pixels */
-       if (sample == 1) {
+       if (do_sample != 1) {
                sample_size = band->width * band->height;
                sample_per = inner;
        }
@@ -1643,7 +1652,7 @@ rt_band_get_summary_stats(rt_band band, int hasnodata, double sample,
                diff = 0;
 
                for (i = 0, z = 0; i < sample_per; i++) {
-                       if (sample == 1)
+                       if (do_sample != 1)
                                y = i;
                        else {
                                offset = (rand() % sample_int) + 1;
@@ -1661,14 +1670,15 @@ rt_band_get_summary_stats(rt_band band, int hasnodata, double sample,
                        j++;
                        if (rtn != -1) {
                                if (
-                                       !hasnodata ||
-                                       (hasnodata && (hasnodata_flag != FALSE) && (value != nodata))
+                                       !hasnodata || (
+                                               hasnodata &&
+                                               (hasnodata_flag != FALSE) &&
+                                               (fabs(value - nodata) > FLT_EPSILON)
+                                       )
                                ) {
 
                                        /* inc_vals set, collect pixel values */
-                                       if (inc_vals) {
-                                               values[k] = value;
-                                       }
+                                       if (inc_vals) values[k] = value;
 
                                        /* average */
                                        k++;
@@ -1738,7 +1748,7 @@ rt_band_get_summary_stats(rt_band band, int hasnodata, double sample,
                stats->mean = sum / k;
 
                /* standard deviation */
-               if (sample == 1)
+               if (do_sample != 1)
                        stats->stddev = sqrt(Q / k);
                /* sample deviation */
                else {
@@ -1821,7 +1831,7 @@ rt_band_get_histogram(rt_bandstats stats,
        /* bin width must be positive numbers and not zero */
        if (NULL != bin_width && bin_width_count > 0) {
                for (i = 0; i < bin_width_count; i++) {
-                       if (bin_width[i] <= 0.) {
+                       if (bin_width[i] < 0 || fabs(bin_width[i] - 0.0) < FLT_EPSILON) {
                                rterror("rt_util_get_histogram: bin_width element is less than or equal to zero");
                                return NULL;
                        }
@@ -1863,7 +1873,7 @@ rt_band_get_histogram(rt_bandstats stats,
        }
 
        /* min and max the same */
-       if (stats->min == stats->max)
+       if (fabs(stats->max - stats->min) < FLT_EPSILON)
                bin_count = 1;
 
        RASTER_DEBUGF(3, "bin_count = %d", bin_count); 
@@ -1962,8 +1972,12 @@ rt_band_get_histogram(rt_bandstats stats,
                if (!right) {
                        for (j = 0; j < bin_count; j++) {
                                if (
-                                       (!bins[j].inc_max && value < bins[j].max) ||
-                                       (bins[j].inc_max && value <= bins[j].max)
+                                       (!bins[j].inc_max && value < bins[j].max) || (
+                                               bins[j].inc_max && (
+                                                       (value < bins[j].max) ||
+                                                       (fabs(value - bins[j].max) < FLT_EPSILON)
+                                               )
+                                       )
                                ) {
                                        bins[j].count++;
                                        sum++;
@@ -1974,8 +1988,12 @@ rt_band_get_histogram(rt_bandstats stats,
                else {
                        for (j = 0; j < bin_count; j++) {
                                if (
-                                       (!bins[j].inc_min && value > bins[j].min) ||
-                                       (bins[j].inc_min && value >= bins[j].min)
+                                       (!bins[j].inc_min && value > bins[j].min) || (
+                                               bins[j].inc_min && (
+                                                       (value > bins[j].min) ||
+                                                       (fabs(value - bins[j].min) < FLT_EPSILON)
+                                               )
+                                       )
                                ) {
                                        bins[j].count++;
                                        sum++;
@@ -2344,23 +2362,38 @@ rt_band_reclass(rt_band srcband, rt_pixtype pixtype,
                                        expr = exprset[i];
 
                                        /* ov matches min and max*/
-                                       if (expr->src.min == ov && ov == expr->src.max) {
+                                       if (
+                                               fabs(expr->src.min - ov) < FLT_EPSILON &&
+                                               fabs(expr->src.max - ov) < FLT_EPSILON
+                                       ) {
                                                do_nv = 1;
                                                break;
                                        }
 
                                        /* process min */
-                                       if (
-                                               (expr->src.exc_min && expr->src.min >= ov) ||
-                                               (expr->src.inc_min && expr->src.min <= ov) ||
-                                               (expr->src.min < ov)
-                                       ) {
+                                       if ((
+                                               expr->src.exc_min && (
+                                                       expr->src.min > ov ||
+                                                       fabs(expr->src.min - ov) < FLT_EPSILON
+                                               )) || (
+                                               expr->src.inc_min && (
+                                                       expr->src.min < ov ||
+                                                       fabs(expr->src.min - ov) < FLT_EPSILON
+                                               )) || (
+                                               expr->src.min < ov
+                                       )) {
                                                /* process max */
-                                               if (
-                                                       (expr->src.exc_max && ov >= expr->src.max) ||
-                                                       (expr->src.inc_max && ov <= expr->src.max) ||
-                                                       (ov < expr->src.max)
-                                               ) {
+                                               if ((
+                                                       expr->src.exc_max && (
+                                                               ov > expr->src.max ||
+                                                               fabs(expr->src.max - ov) < FLT_EPSILON
+                                                       )) || (
+                                                               expr->src.inc_max && (
+                                                               ov < expr->src.max ||
+                                                               fabs(expr->src.max - ov) < FLT_EPSILON
+                                                       )) || (
+                                                       ov < expr->src.max
+                                               )) {
                                                        do_nv = 1;
                                                        break;
                                                }
@@ -2379,14 +2412,18 @@ rt_band_reclass(rt_band srcband, rt_pixtype pixtype,
                        */
 
                        /* nodata */
-                       if (src_hasnodata && hasnodata && ov == src_nodataval) {
+                       if (
+                               src_hasnodata &&
+                               hasnodata &&
+                               fabs(ov - src_nodataval) < FLT_EPSILON
+                       ) {
                                nv = nodataval;
                        }
                        /*
                                "src" min and max is the same, prevent division by zero
                                set nv to "dst" min, which should be the same as "dst" max
                        */
-                       else if (expr->src.min == expr->src.max) {
+                       else if (fabs(expr->src.max - expr->src.min) < FLT_EPSILON) {
                                nv = expr->dst.min;
                        }
                        else {
@@ -2773,8 +2810,8 @@ rt_raster_generate_new_band(rt_raster raster, rt_pixtype pixtype,
     oldnumbands = rt_raster_get_num_bands(raster);
     if (index < 0)
         index = 0;
-    else if (index > rt_raster_get_num_bands(raster) + 1)
-        index = rt_raster_get_num_bands(raster) + 1;
+    else if (index > oldnumbands + 1)
+        index = oldnumbands + 1;
 
     /* Determine size of memory block to allocate and allocate it */
     width = rt_raster_get_width(raster);
@@ -5235,7 +5272,7 @@ rt_raster_to_gdal_mem(rt_raster raster, char *srs,
        numBands = rt_raster_get_num_bands(raster);
        for (i = 0; i < numBands; i++) {
                rtband = rt_raster_get_band(raster, i);
-               if (0 == rtband) {
+               if (NULL == rtband) {
                        rterror("rt_raster_to_gdal_mem: Unable to get requested band\n");
                        GDALClose(ds);
                        if (drv_gen) {
index d6d94238cc5205c0acdea37e683b0fb2314f8c92..cc40a1af4db5810d637a5e2e13f16fc5e693e860 100644 (file)
@@ -1984,11 +1984,7 @@ Datum RASTER_addband(PG_FUNCTION_ARGS)
     }
 
     pixeltypename = PG_GETARG_TEXT_P(2);
-    new_pixeltypename = (char *) palloc(VARSIZE(pixeltypename) + 1 - VARHDRSZ);
-    SET_VARSIZE(new_pixeltypename, VARSIZE(pixeltypename));
-    memcpy(new_pixeltypename, VARDATA(pixeltypename),
-        VARSIZE(pixeltypename) - VARHDRSZ);
-    new_pixeltypename[VARSIZE(pixeltypename) - VARHDRSZ] = 0; /* null terminate */
+               new_pixeltypename = text_to_cstring(pixeltypename);
 
     /* Get the pixel type index */
     pixtype = rt_pixtype_index_from_name(new_pixeltypename);
@@ -2936,7 +2932,7 @@ struct rt_bandstats_t {
 PG_FUNCTION_INFO_V1(RASTER_summaryStats);
 Datum RASTER_summaryStats(PG_FUNCTION_ARGS)
 {
-       rt_pgraster *pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+       rt_pgraster *pgraster = NULL;
        rt_raster raster = NULL;
        rt_band band = NULL;
        int32_t bandindex = 0;
@@ -2952,6 +2948,10 @@ Datum RASTER_summaryStats(PG_FUNCTION_ARGS)
        HeapTuple tuple;
        Datum result;
 
+       /* pgraster is null, return null */
+       if (PG_ARGISNULL(0)) PG_RETURN_NULL();
+       pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+
        raster = rt_raster_deserialize(pgraster);
        if (!raster) {
                elog(ERROR, "RASTER_summaryStats: Could not deserialize raster");
@@ -2980,7 +2980,7 @@ Datum RASTER_summaryStats(PG_FUNCTION_ARGS)
                        rt_raster_destroy(raster);
                        PG_RETURN_NULL();
                }
-               else if (sample == 0)
+               else if (fabs(sample - 0.0) < FLT_EPSILON)
                        sample = 1;
        }
        else
@@ -3122,7 +3122,7 @@ Datum RASTER_histogram(PG_FUNCTION_ARGS)
        if (SRF_IS_FIRSTCALL()) {
                MemoryContext oldcontext;
 
-               rt_pgraster *pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+               rt_pgraster *pgraster = NULL;
                rt_raster raster = NULL;
                rt_band band = NULL;
                int32_t bandindex = 0;
@@ -3157,6 +3157,10 @@ Datum RASTER_histogram(PG_FUNCTION_ARGS)
                /* switch to memory context appropriate for multiple function calls */
                oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
 
+               /* pgraster is null, return nothing */
+               if (PG_ARGISNULL(0)) SRF_RETURN_DONE(funcctx);
+               pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+
                raster = rt_raster_deserialize(pgraster);
                if (!raster) {
                        elog(ERROR, "RASTER_histogram: Could not deserialize raster");
@@ -3185,7 +3189,7 @@ Datum RASTER_histogram(PG_FUNCTION_ARGS)
                                rt_raster_destroy(raster);
                                SRF_RETURN_DONE(funcctx);
                        }
-                       else if (sample == 0)
+                       else if (fabs(sample - 0.0) < FLT_EPSILON)
                                sample = 1;
                }
                else
@@ -3234,7 +3238,7 @@ Datum RASTER_histogram(PG_FUNCTION_ARGS)
                                                break;
                                }
 
-                               if (width < 0) {
+                               if (width < 0 || fabs(width - 0.0) < FLT_EPSILON) {
                                        elog(NOTICE, "Invalid value for width (must be greater than 0). Returning NULL");
                                        pfree(bin_width);
                                        rt_raster_destroy(raster);
@@ -3412,7 +3416,7 @@ Datum RASTER_quantile(PG_FUNCTION_ARGS)
        if (SRF_IS_FIRSTCALL()) {
                MemoryContext oldcontext;
 
-               rt_pgraster *pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+               rt_pgraster *pgraster = NULL;
                rt_raster raster = NULL;
                rt_band band = NULL;
                int32_t bandindex = 0;
@@ -3445,6 +3449,10 @@ Datum RASTER_quantile(PG_FUNCTION_ARGS)
                /* switch to memory context appropriate for multiple function calls */
                oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
 
+               /* pgraster is null, return nothing */
+               if (PG_ARGISNULL(0)) SRF_RETURN_DONE(funcctx);
+               pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+
                raster = rt_raster_deserialize(pgraster);
                if (!raster) {
                        elog(ERROR, "RASTER_quantile: Could not deserialize raster");
@@ -3473,7 +3481,7 @@ Datum RASTER_quantile(PG_FUNCTION_ARGS)
                                rt_raster_destroy(raster);
                                SRF_RETURN_DONE(funcctx);
                        }
-                       else if (sample == 0)
+                       else if (fabs(sample - 0.0) < FLT_EPSILON)
                                sample = 1;
                }
                else
@@ -3664,7 +3672,7 @@ struct rt_reclassexpr_t {
  */
 PG_FUNCTION_INFO_V1(RASTER_reclass);
 Datum RASTER_reclass(PG_FUNCTION_ARGS) {
-       rt_pgraster *pgrast = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+       rt_pgraster *pgrast = NULL;
        rt_raster raster = NULL;
        rt_band band = NULL;
        rt_band newband = NULL;
@@ -3716,6 +3724,10 @@ Datum RASTER_reclass(PG_FUNCTION_ARGS) {
 
        POSTGIS_RT_DEBUG(3, "RASTER_reclass: Starting");
 
+       /* pgraster is null, return null */
+       if (PG_ARGISNULL(0)) PG_RETURN_NULL();
+       pgrast = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+
        /* raster */
        raster = rt_raster_deserialize(pgrast);
        if (!raster) {
@@ -4114,7 +4126,7 @@ Datum RASTER_reclass(PG_FUNCTION_ARGS) {
 PG_FUNCTION_INFO_V1(RASTER_asGDALRaster);
 Datum RASTER_asGDALRaster(PG_FUNCTION_ARGS)
 {
-       rt_pgraster *pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+       rt_pgraster *pgraster = NULL;
        rt_raster raster;
 
        text *formattext = NULL;
@@ -4146,6 +4158,10 @@ Datum RASTER_asGDALRaster(PG_FUNCTION_ARGS)
 
        POSTGIS_RT_DEBUG(3, "RASTER_asGDALRaster: Starting");
 
+       /* pgraster is null, return null */
+       if (PG_ARGISNULL(0)) PG_RETURN_NULL();
+       pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+
        raster = rt_raster_deserialize(pgraster);
        if (!raster) {
                elog(ERROR, "RASTER_asGDALRaster: Could not deserialize raster");
index 2dc91f6366bbeadf629ad542f431130476638935..41824c0f48b38d960b5b832fca13b3168de0e4a1 100644 (file)
@@ -1,4 +1,9 @@
-SELECT * FROM ST_Histogram(
+SELECT
+       round(min::numeric, 3),
+       round(max::numeric, 3),
+       count,
+       round(proportion::numeric, 3)
+FROM ST_Histogram(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -13,22 +18,12 @@ SELECT * FROM ST_Histogram(
                , 1, 5, 5, 3.14159
        )
 );
-SELECT ST_Histogram(
-       ST_SetValue(
-               ST_SetValue(
-                       ST_SetValue(
-                               ST_AddBand(
-                                       ST_MakeEmptyRaster(10, 10, 10, 10, 2, 2, 0, 0,-1)
-                                       , 1, '64BF', 0, 0
-                               )
-                               , 1, 1, 1, -10
-                       )
-                       , 1, 5, 4, 0
-               )
-               , 1, 5, 5, 3.14159
-       )
-);
-SELECT * FROM ST_Histogram(
+SELECT
+       round(min::numeric, 3),
+       round(max::numeric, 3),
+       count,
+       round(proportion::numeric, 3)
+FROM ST_Histogram(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -44,7 +39,12 @@ SELECT * FROM ST_Histogram(
        ),
        1, FALSE, 0, ARRAY[]::double precision[], FALSE
 );
-SELECT * FROM ST_Histogram(
+SELECT
+       round(min::numeric, 3),
+       round(max::numeric, 3),
+       count,
+       round(proportion::numeric, 3)
+FROM ST_Histogram(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -60,7 +60,12 @@ SELECT * FROM ST_Histogram(
        ),
        1, FALSE, 1, FALSE
 );
-SELECT * FROM ST_Histogram(
+SELECT
+       round(min::numeric, 3),
+       round(max::numeric, 3),
+       count,
+       round(proportion::numeric, 3)
+FROM ST_Histogram(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -76,7 +81,12 @@ SELECT * FROM ST_Histogram(
        ),
        1, FALSE, 5
 );
-SELECT * FROM ST_Histogram(
+SELECT
+       round(min::numeric, 3),
+       round(max::numeric, 3),
+       count,
+       round(proportion::numeric, 3)
+FROM ST_Histogram(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -92,7 +102,12 @@ SELECT * FROM ST_Histogram(
        ),
        1, FALSE
 );
-SELECT * FROM ST_Histogram(
+SELECT
+       round(min::numeric, 3),
+       round(max::numeric, 3),
+       count,
+       round(proportion::numeric, 3)
+FROM ST_Histogram(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -108,7 +123,12 @@ SELECT * FROM ST_Histogram(
        ),
        1
 );
-SELECT * FROM ST_Histogram(
+SELECT
+       round(min::numeric, 3),
+       round(max::numeric, 3),
+       count,
+       round(proportion::numeric, 3)
+FROM ST_Histogram(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -124,7 +144,12 @@ SELECT * FROM ST_Histogram(
        ),
        1, 0, ARRAY[5]::double precision[], FALSE
 );
-SELECT * FROM ST_Histogram(
+SELECT
+       round(min::numeric, 3),
+       round(max::numeric, 3),
+       count,
+       round(proportion::numeric, 3)
+FROM ST_Histogram(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -140,7 +165,12 @@ SELECT * FROM ST_Histogram(
        ),
        1, 3, FALSE
 );
-SELECT * FROM ST_Histogram(
+SELECT
+       round(min::numeric, 3),
+       round(max::numeric, 3),
+       count,
+       round(proportion::numeric, 3)
+FROM ST_Histogram(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
index 1d068b83564871f32ac12f81437a9ef4f7141128..725eae67de574c6f3bb4ac8d6de79eb4edea1492 100644 (file)
@@ -1,39 +1,37 @@
--10|-3.429205|1|0.5
--3.429205|3.14159|1|0.5
-(-10,-3.429205,1,0.5)
-(-3.429205,3.14159,1,0.5)
--10|-8.357301|1|0.01
--8.357301|-6.714602|0|0
--6.714602|-5.071904|0|0
--5.071904|-3.429205|0|0
--3.429205|-1.786506|0|0
--1.786506|-0.143807|0|0
--0.143807|1.498891|98|0.98
-1.498891|3.14159|1|0.01
--10|3.14159|100|-1
--10|-7.371682|1|0.01
--7.371682|-4.743364|0|0
--4.743364|-2.115046|0|0
--2.115046|0.513272|98|0.98
-0.513272|3.14159|1|0.01
--10|-8.357301|1|0.01
--8.357301|-6.714602|0|0
--6.714602|-5.071904|0|0
--5.071904|-3.429205|0|0
--3.429205|-1.786506|0|0
--1.786506|-0.143807|0|0
--0.143807|1.498891|98|0.98
-1.498891|3.14159|1|0.01
--10|-3.429205|1|0.5
--3.429205|3.14159|1|0.5
--10|-5|1|0.5
--5|0|0|0
-0|5|1|0.5
--10|-5.61947|1|0.5
--5.61947|-1.23894|0|0
--1.23894|3.14159|1|0.5
--10|-7.371682|1|0.5
--7.371682|-4.743364|0|0
--4.743364|-2.115046|0|0
--2.115046|0.513272|0|0
-0.513272|3.14159|1|0.5
+-10.000|-3.429|1|0.500
+-3.429|3.142|1|0.500
+-10.000|-8.357|1|0.010
+-8.357|-6.715|0|0.000
+-6.715|-5.072|0|0.000
+-5.072|-3.429|0|0.000
+-3.429|-1.787|0|0.000
+-1.787|-0.144|0|0.000
+-0.144|1.499|98|0.980
+1.499|3.142|1|0.010
+-10.000|3.142|100|-1.000
+-10.000|-7.372|1|0.010
+-7.372|-4.743|0|0.000
+-4.743|-2.115|0|0.000
+-2.115|0.513|98|0.980
+0.513|3.142|1|0.010
+-10.000|-8.357|1|0.010
+-8.357|-6.715|0|0.000
+-6.715|-5.072|0|0.000
+-5.072|-3.429|0|0.000
+-3.429|-1.787|0|0.000
+-1.787|-0.144|0|0.000
+-0.144|1.499|98|0.980
+1.499|3.142|1|0.010
+-10.000|-3.429|1|0.500
+-3.429|3.142|1|0.500
+-10.000|-5.000|1|0.500
+-5.000|0.000|0|0.000
+0.000|5.000|1|0.500
+-10.000|-5.619|1|0.500
+-5.619|-1.239|0|0.000
+-1.239|3.142|1|0.500
+-10.000|-7.372|1|0.500
+-7.372|-4.743|0|0.000
+-4.743|-2.115|0|0.000
+-2.115|0.513|0|0.000
+0.513|3.142|1|0.500
index 3a17f3c5c3fb261a3f5c22480eafb19797433622..6edd9a998b309a9dfd9ca411417368069d798689 100644 (file)
@@ -1,4 +1,4 @@
-SELECT * FROM ST_Mean(
+SELECT round(ST_Mean(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -13,24 +13,8 @@ SELECT * FROM ST_Mean(
                , 1, 5, 5, 3.14159
        )
        , TRUE
-);
-SELECT ST_Mean(
-       ST_SetValue(
-               ST_SetValue(
-                       ST_SetValue(
-                               ST_AddBand(
-                                       ST_MakeEmptyRaster(10, 10, 10, 10, 2, 2, 0, 0,-1)
-                                       , 1, '64BF', 0, 0
-                               )
-                               , 1, 1, 1, -10
-                       )
-                       , 1, 5, 4, 0
-               )
-               , 1, 5, 5, 3.14159
-       )
-       , TRUE
-);
-SELECT mean FROM ST_Mean(
+)::numeric, 3);
+SELECT round(mean::numeric, 3) FROM ST_Mean(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -46,7 +30,7 @@ SELECT mean FROM ST_Mean(
        )
        , TRUE
 );
-SELECT mean FROM ST_Mean(
+SELECT round(mean::numeric, 3) FROM ST_Mean(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -86,9 +70,9 @@ CREATE TEMP TABLE test
                SELECT generate_series(1, 10) AS id
        ) AS id
                ON 1 = 1;
-SELECT * FROM ST_Mean('test', 'rast', 1, TRUE);
-SELECT * FROM ST_Mean('test', 'rast', 1, FALSE);
-SELECT * FROM ST_Mean('test', 'rast', 1);
-SELECT * FROM ST_Mean('test', 'rast');
+SELECT round(mean::numeric, 3) FROM ST_Mean('test', 'rast', 1, TRUE);
+SELECT round(mean::numeric, 3) FROM ST_Mean('test', 'rast', 1, FALSE);
+SELECT round(mean::numeric, 3) FROM ST_Mean('test', 'rast', 1);
+SELECT round(mean::numeric, 3) FROM ST_Mean('test', 'rast');
 ROLLBACK;
 
index ef09e7e94ef34b43253c0791d3f2def0907c2ef3..1731829d43ac7b0e12f7b777da4d1631c2214c57 100644 (file)
@@ -1,10 +1,9 @@
--3.429205
--3.429205
--3.429205
--0.068584
+-3.429
+-3.429
+-0.069
 BEGIN
--3.429205
--0.068584
--3.429205
--3.429205
+-3.429
+-0.069
+-3.429
+-3.429
 COMMIT
index db91483393d845e73a8837f4fe2d3e8d09677c20..e5ddbcf6fa1e0e176007a5e2219436f95ac137e6 100644 (file)
@@ -1,4 +1,4 @@
-SELECT min, max FROM ST_MinMax(
+SELECT round(min::numeric, 3), round(max::numeric, 3) FROM ST_MinMax(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -14,7 +14,7 @@ SELECT min, max FROM ST_MinMax(
        )
        , TRUE
 );
-SELECT ST_MinMax(
+SELECT round(min::numeric, 3), round(max::numeric, 3) FROM ST_MinMax(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -28,9 +28,9 @@ SELECT ST_MinMax(
                )
                , 1, 5, 5, 3.14159
        )
-       , TRUE
+       , FALSE
 );
-SELECT min FROM ST_MinMax(
+SELECT round(min::numeric, 3), round(max::numeric, 3) FROM ST_MinMax(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -43,10 +43,10 @@ SELECT min FROM ST_MinMax(
                        , 1, 5, 4, 0
                )
                , 1, 5, 5, 3.14159
-       )
-       , TRUE
+       ),
+       1, TRUE
 );
-SELECT max,max FROM ST_MinMax(
+SELECT round(min::numeric, 3), round(max::numeric, 3) FROM ST_MinMax(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -59,6 +59,35 @@ SELECT max,max FROM ST_MinMax(
                        , 1, 5, 4, 0
                )
                , 1, 5, 5, 3.14159
-       )
-       , TRUE
+       ),
+       1
 );
+BEGIN;
+CREATE TEMP TABLE test
+       ON COMMIT DROP AS
+       SELECT
+               rast.rast
+       FROM (
+               SELECT ST_SetValue(
+                       ST_SetValue(
+                               ST_SetValue(
+                                       ST_AddBand(
+                                               ST_MakeEmptyRaster(10, 10, 10, 10, 2, 2, 0, 0,-1)
+                                               , 1, '64BF', 0, 0
+                                       )
+                                       , 1, 1, 1, -10
+                               )
+                               , 1, 5, 4, 0
+                       )
+                       , 1, 5, 5, 3.14159
+               ) AS rast
+       ) AS rast
+       FULL JOIN (
+               SELECT generate_series(1, 10) AS id
+       ) AS id
+               ON 1 = 1;
+SELECT round(min::numeric, 3), round(max::numeric, 3) FROM ST_MinMax('test', 'rast', 1, TRUE);
+SELECT round(min::numeric, 3), round(max::numeric, 3) FROM ST_MinMax('test', 'rast', 1, FALSE);
+SELECT round(min::numeric, 3), round(max::numeric, 3) FROM ST_MinMax('test', 'rast', 1);
+SELECT round(min::numeric, 3), round(max::numeric, 3) FROM ST_MinMax('test', 'rast');
+ROLLBACK;
index ef01ccd340cc41a67baf4626b434abb8844ce1f8..51bcc6b62d4cbc3ff93a288acb665f3ce982915f 100644 (file)
@@ -1,4 +1,10 @@
--10|3.14159
-(-10,3.14159)
--10
-3.14159|3.14159
+-10.000|3.142
+-10.000|3.142
+-10.000|3.142
+-10.000|3.142
+BEGIN
+-10.000|3.142
+-10.000|3.142
+-10.000|3.142
+-10.000|3.142
+COMMIT
index 3ee41af7a6e294bb5b08c05523234b99d28d59cd..4be5dc9b0853791d2fb45ca7082c2e6a00ed7485 100644 (file)
@@ -1,4 +1,7 @@
-SELECT * FROM ST_Quantile(
+SELECT
+       round(quantile::numeric, 3),
+       round(value::numeric, 3)
+FROM ST_Quantile(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -14,7 +17,10 @@ SELECT * FROM ST_Quantile(
        )
        , 1, FALSE, ARRAY[0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]::double precision[]
 );
-SELECT * FROM ST_Quantile(
+SELECT
+       round(quantile::numeric, 3),
+       round(value::numeric, 3)
+FROM ST_Quantile(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -30,7 +36,10 @@ SELECT * FROM ST_Quantile(
        )
        , 1, ARRAY[0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]::double precision[]
 );
-SELECT * FROM ST_Quantile(
+SELECT
+       round(quantile::numeric, 3),
+       round(value::numeric, 3)
+FROM ST_Quantile(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -46,7 +55,10 @@ SELECT * FROM ST_Quantile(
        ),
        1, FALSE
 );
-SELECT * FROM ST_Quantile(
+SELECT
+       round(quantile::numeric, 3),
+       round(value::numeric, 3)
+FROM ST_Quantile(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -62,7 +74,10 @@ SELECT * FROM ST_Quantile(
        ),
        1
 );
-SELECT * FROM ST_Quantile(
+SELECT
+       round(quantile::numeric, 3),
+       round(value::numeric, 3)
+FROM ST_Quantile(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -78,7 +93,10 @@ SELECT * FROM ST_Quantile(
        ),
        ARRAY[0.05, 0.95]::double precision[]
 );
-SELECT * FROM ST_Quantile(
+SELECT
+       round(quantile::numeric, 3),
+       round(value::numeric, 3)
+FROM ST_Quantile(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -93,7 +111,10 @@ SELECT * FROM ST_Quantile(
                , 1, 5, 5, 3.14159
        )
 );
-SELECT * FROM ST_Quantile(
+SELECT
+       round(quantile::numeric, 3),
+       round(value::numeric, 3)
+FROM ST_Quantile(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -109,7 +130,10 @@ SELECT * FROM ST_Quantile(
        ),
        1, FALSE, 0.05
 );
-SELECT * FROM ST_Quantile(
+SELECT
+       round(quantile::numeric, 3),
+       round(value::numeric, 3)
+FROM ST_Quantile(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -125,7 +149,10 @@ SELECT * FROM ST_Quantile(
        ),
        1, 0.95
 );
-SELECT * FROM ST_Quantile(
+SELECT
+       round(quantile::numeric, 3),
+       round(value::numeric, 3)
+FROM ST_Quantile(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -141,7 +168,10 @@ SELECT * FROM ST_Quantile(
        ),
        FALSE, 0.7
 );
-SELECT * FROM ST_Quantile(
+SELECT
+       round(quantile::numeric, 3),
+       round(value::numeric, 3)
+FROM ST_Quantile(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
index d612998b2846bdc8d26790dda94f2286737eb975..d6235076a5be27fed4497625f0fbc8d2403caf88 100644 (file)
@@ -1,43 +1,43 @@
-0|-10
-0.1|0
-0.2|0
-0.3|0
-0.4|0
-0.5|0
-0.6|0
-0.7|0
-0.8|0
-0.9|0
-1|3.14159
-0|-10
-0.1|-8.685841
-0.2|-7.371682
-0.3|-6.057523
-0.4|-4.743364
-0.5|-3.429205
-0.6|-2.115046
-0.7|-0.800887
-0.8|0.513272
-0.9|1.827431
-1|3.14159
-0|-10
-0.25|0
-0.5|0
-0.75|0
-1|3.14159
-0|-10
-0.25|-6.714602
-0.5|-3.429205
-0.75|-0.143807
-1|3.14159
-0.05|-9.34292
-0.95|2.484511
-0|-10
-0.25|-6.714602
-0.5|-3.429205
-0.75|-0.143807
-1|3.14159
-0.05|0
-0.95|2.484511
-0.7|0
-0.45|-4.086285
+0.000|-10.000
+0.100|0.000
+0.200|0.000
+0.300|0.000
+0.400|0.000
+0.500|0.000
+0.600|0.000
+0.700|0.000
+0.800|0.000
+0.900|0.000
+1.000|3.142
+0.000|-10.000
+0.100|-8.686
+0.200|-7.372
+0.300|-6.058
+0.400|-4.743
+0.500|-3.429
+0.600|-2.115
+0.700|-0.801
+0.800|0.513
+0.900|1.827
+1.000|3.142
+0.000|-10.000
+0.250|0.000
+0.500|0.000
+0.750|0.000
+1.000|3.142
+0.000|-10.000
+0.250|-6.715
+0.500|-3.429
+0.750|-0.144
+1.000|3.142
+0.050|-9.343
+0.950|2.485
+0.000|-10.000
+0.250|-6.715
+0.500|-3.429
+0.750|-0.144
+1.000|3.142
+0.050|0.000
+0.950|2.485
+0.700|0.000
+0.450|-4.086
index 84370ddf8e40e9d0b299c90a20c1862cddeea5eb..0bb408e6b0cfebeaa9d50177c85301f158898a9b 100644 (file)
@@ -1,4 +1,4 @@
-SELECT * FROM ST_StdDev(
+SELECT round(ST_StdDev(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -13,24 +13,8 @@ SELECT * FROM ST_StdDev(
                , 1, 5, 5, 3.14159
        )
        , TRUE
-);
-SELECT ST_StdDev(
-       ST_SetValue(
-               ST_SetValue(
-                       ST_SetValue(
-                               ST_AddBand(
-                                       ST_MakeEmptyRaster(10, 10, 10, 10, 2, 2, 0, 0,-1)
-                                       , 1, '64BF', 0, 0
-                               )
-                               , 1, 1, 1, -10
-                       )
-                       , 1, 5, 4, 0
-               )
-               , 1, 5, 5, 3.14159
-       )
-       , TRUE
-);
-SELECT stddev FROM ST_StdDev(
+)::numeric, 3);
+SELECT round(stddev::numeric, 3) FROM ST_StdDev(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -46,7 +30,7 @@ SELECT stddev FROM ST_StdDev(
        )
        , TRUE
 );
-SELECT stddev FROM ST_StdDev(
+SELECT round(stddev::numeric, 3) FROM ST_StdDev(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -86,8 +70,8 @@ CREATE TEMP TABLE test
                SELECT generate_series(1, 10) AS id
        ) AS id
                ON 1 = 1;
-SELECT * FROM ST_StdDev('test', 'rast', 1, TRUE);
-SELECT * FROM ST_StdDev('test', 'rast', 1, FALSE);
-SELECT * FROM ST_StdDev('test', 'rast', 1);
-SELECT * FROM ST_StdDev('test', 'rast');
+SELECT round(stddev::numeric, 3) FROM ST_StdDev('test', 'rast', 1, TRUE);
+SELECT round(stddev::numeric, 3) FROM ST_StdDev('test', 'rast', 1, FALSE);
+SELECT round(stddev::numeric, 3) FROM ST_StdDev('test', 'rast', 1);
+SELECT round(stddev::numeric, 3) FROM ST_StdDev('test', 'rast');
 ROLLBACK;
index 7315f53c8d9e46f18d70f736c95301261357aa02..ef302a8f40551ac7ccbf7d0cc1b7161d5b2abf99 100644 (file)
@@ -1,10 +1,9 @@
-6.570795
-6.570795
-6.570795
-1.045941
+6.571
+6.571
+1.046
 BEGIN
-6.570795
-1.045941
-6.570795
-6.570795
+6.571
+1.046
+6.571
+6.571
 COMMIT
index 97267631cd186fcb2feb97ff16989f4ff2edb3ad..4768c0907b13c89672f94e4271c946c211216b96 100644 (file)
@@ -1,20 +1,11 @@
-SELECT * FROM ST_SummaryStats(
-       ST_SetValue(
-               ST_SetValue(
-                       ST_SetValue(
-                               ST_AddBand(
-                                       ST_MakeEmptyRaster(10, 10, 10, 10, 2, 2, 0, 0,-1)
-                                       , 1, '64BF', 0, 0
-                               )
-                               , 1, 1, 1, -10
-                       )
-                       , 1, 5, 4, 0
-               )
-               , 1, 5, 5, 3.14159
-       )
-       , TRUE
-);
-SELECT ST_SummaryStats(
+SELECT
+       count,
+       round(sum::numeric, 3),
+       round(mean::numeric, 3),
+       round(stddev::numeric, 3),
+       round(min::numeric, 3),
+       round(max::numeric, 3)
+FROM ST_SummaryStats(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -62,7 +53,7 @@ SELECT count FROM ST_SummaryStats(
        )
        , FALSE
 );
-SELECT mean, stddev FROM ST_SummaryStats(
+SELECT round(mean::numeric, 3), round(stddev::numeric, 3) FROM ST_SummaryStats(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -78,7 +69,7 @@ SELECT mean, stddev FROM ST_SummaryStats(
        )
        , TRUE
 );
-SELECT mean, stddev FROM ST_SummaryStats(
+SELECT round(mean::numeric, 3), round(stddev::numeric, 3) FROM ST_SummaryStats(
        ST_SetValue(
                ST_SetValue(
                        ST_SetValue(
@@ -118,8 +109,36 @@ CREATE TEMP TABLE test
                SELECT generate_series(1, 10) AS id
        ) AS id
                ON 1 = 1;
-SELECT * FROM ST_SummaryStats('test', 'rast', 1, TRUE);
-SELECT * FROM ST_SummaryStats('test', 'rast', 1, FALSE);
-SELECT * FROM ST_SummaryStats('test', 'rast', 1);
-SELECT * FROM ST_SummaryStats('test', 'rast');
+SELECT
+       count,
+       round(sum::numeric, 3),
+       round(mean::numeric, 3),
+       round(stddev::numeric, 3),
+       round(min::numeric, 3),
+       round(max::numeric, 3)
+FROM ST_SummaryStats('test', 'rast', 1, TRUE);
+SELECT
+       count,
+       round(sum::numeric, 3),
+       round(mean::numeric, 3),
+       round(stddev::numeric, 3),
+       round(min::numeric, 3),
+       round(max::numeric, 3)
+FROM ST_SummaryStats('test', 'rast', 1, FALSE);
+SELECT
+       count,
+       round(sum::numeric, 3),
+       round(mean::numeric, 3),
+       round(stddev::numeric, 3),
+       round(min::numeric, 3),
+       round(max::numeric, 3)
+FROM ST_SummaryStats('test', 'rast', 1);
+SELECT
+       count,
+       round(sum::numeric, 3),
+       round(mean::numeric, 3),
+       round(stddev::numeric, 3),
+       round(min::numeric, 3),
+       round(max::numeric, 3)
+FROM ST_SummaryStats('test', 'rast');
 ROLLBACK;
index d366dc47d2bfe58ba4f2e96ddb04086d5d1c921e..4287810c40941e054f1ffa3bffeaf65974933c3c 100644 (file)
@@ -1,12 +1,11 @@
-2|-6.85841|-3.429205|6.570795|-10|3.14159
-(2,-6.85841,-3.429205,6.570795,-10,3.14159)
+2|-6.858|-3.429|6.571|-10.000|3.142
 2
 100
--3.429205|6.570795
--0.068584|1.045941
+-3.429|6.571
+-0.069|1.046
 BEGIN
-20|-6.85841|-3.429205|6.570795|-10|3.14159
-1000|-6.85841|-0.0685841|1.045941|-10|3.14159
-20|-6.85841|-3.429205|6.570795|-10|3.14159
-20|-6.85841|-3.429205|6.570795|-10|3.14159
+20|-6.858|-3.429|6.571|-10.000|3.142
+1000|-6.858|-0.069|1.046|-10.000|3.142
+20|-6.858|-3.429|6.571|-10.000|3.142
+20|-6.858|-3.429|6.571|-10.000|3.142
 COMMIT