]> granicus.if.org Git - postgis/commitdiff
More fixups for the quantile coverage function. Fixes segfault that seems to only...
authorBborie Park <bkpark at ucdavis.edu>
Sat, 20 Aug 2011 17:51:04 +0000 (17:51 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Sat, 20 Aug 2011 17:51:04 +0000 (17:51 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@7771 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_api.c
raster/rt_pg/rt_pg.c
raster/test/core/testapi.c
raster/test/regress/rt_quantile.sql
raster/test/regress/rt_quantile_expected

index d2ac7320e03f23c061f4de6a30c2dc67bfe5e2d4..c4cb470cd629a926eece1cbb7bcc91a8ac8d6ad7 100644 (file)
@@ -2362,6 +2362,7 @@ rt_band_get_quantiles_stream(rt_band band,
 
        assert(NULL != band);
        assert(cov_count > 1);
+       RASTER_DEBUGF(3, "cov_count = %d", cov_count);
 
        if (band->offline) {
                rterror("rt_band_get_summary_stats not implemented yet for OFFDB bands");
@@ -2433,6 +2434,7 @@ rt_band_get_quantiles_stream(rt_band band,
                        if (!(i % 2)) {
                                qll->algeq = 1;
                                qll->tau = (uint64_t) ROUND(cov_count - (cov_count * qll->quantile), 0);
+                               if (qll->tau < 1) qll->tau = 1;
                        }
                        /* AL-GT */
                        else {
index 08c3af9afc5166127bce3d60c1c3bd34ac30e633..25738cec516501b6599e5b29a6e8098498ff49d1 100644 (file)
@@ -4952,6 +4952,14 @@ Datum RASTER_quantileCoverage(PG_FUNCTION_ARGS)
                quantile_llist_destroy(&qlls, qlls_count);
                if (quantiles_count) pfree(quantiles);
 
+               covquant2 = palloc(sizeof(struct rt_quantile_t) * count);
+               for (i = 0; i < count; i++) {
+                       covquant2[i].quantile = covquant[i].quantile;
+                       covquant2[i].value = covquant[i].value;
+               }
+               pfree(covquant);
+               covquant = covquant2;
+
                POSTGIS_RT_DEBUGF(3, "%d quantiles returned", count);
 
                /* Store needed information */
index 00968c5724b5b3c8409ad36c49839b55d7316f1b..8b98f023fe8b043cde6abc7160cab94dfb797f2c 100644 (file)
@@ -1131,10 +1131,58 @@ static void testBandStats() {
        CHECK(quantile);
        CHECK(count);
        CHECK((qlls_count > 0));
-       quantile_llist_destroy(&qlls, qlls_count);
        CHECK(FLT_EQ(quantile[0].value, 78));
+       rtdealloc(quantile);
+       quantile_llist_destroy(&qlls, qlls_count);
+       qlls = NULL;
+       qlls_count = 0;
+
+       quantile = (rt_quantile) rt_band_get_quantiles_stream(
+               band, 1, 1, 60,
+               &qlls, &qlls_count,
+               NULL, 0,
+               &count);
+       CHECK(quantile);
+       CHECK(count);
+       CHECK((qlls_count > 0));
+
+       quantile = (rt_quantile) rt_band_get_quantiles_stream(
+               band, 1, 1, 60,
+               &qlls, &qlls_count,
+               NULL, 0,
+               &count);
+       CHECK(quantile);
+       CHECK(count);
+       CHECK((qlls_count > 0));
+
+       quantile = (rt_quantile) rt_band_get_quantiles_stream(
+               band, 1, 1, 60,
+               &qlls, &qlls_count,
+               NULL, 0,
+               &count);
+       CHECK(quantile);
+       CHECK(count);
+       CHECK((qlls_count > 0));
+
+       quantile = (rt_quantile) rt_band_get_quantiles_stream(
+               band, 1, 1, 60,
+               &qlls, &qlls_count,
+               NULL, 0,
+               &count);
+       CHECK(quantile);
+       CHECK(count);
+       CHECK((qlls_count > 0));
+
+       quantile_llist_destroy(&qlls, qlls_count);
+
+       /*
+       for (x = 0; x < count; x++) {
+               printf("%f = %f\n", quantile[x].quantile, quantile[x].value);
+       }
+       */
 
        rtdealloc(quantile);
+
        deepRelease(raster);
 }
 
index 0d6c56cd9455cfa6f8cdb106f4ac7f57565c4622..a7c4a25e77f7f576addc63016272449842f7dc17 100644 (file)
@@ -204,7 +204,7 @@ CREATE TEMP TABLE test
                ) AS rast
        ) AS rast
        FULL JOIN (
-               SELECT generate_series(1, 1000) AS id
+               SELECT generate_series(1, 2) AS id
        ) AS id
                ON 1 = 1;
 SELECT
index 81d4a3309a46f6b343d4cb9f70fa18ad728ced4c..023a34a557fe071839c641c718a88f5d58c0fe19 100644 (file)
@@ -46,7 +46,7 @@ BEGIN
 0.100|-10.000
 0.200|-10.000
 0.300|-10.000
-0.400|-10.000
+0.400|3.142
 0.500|3.142
 0.600|3.142
 0.700|3.142