]> granicus.if.org Git - postgis/commitdiff
Fixed how the minimum possible value of a pixel type was being
authorBborie Park <bkpark at ucdavis.edu>
Wed, 4 Jul 2012 00:33:00 +0000 (00:33 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Wed, 4 Jul 2012 00:33:00 +0000 (00:33 +0000)
determined.  Added regression tests for band without NODATA.

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

15 files changed:
raster/rt_core/rt_api.c
raster/test/regress/rt_histogram.sql
raster/test/regress/rt_histogram_expected
raster/test/regress/rt_nearestvalue.sql
raster/test/regress/rt_nearestvalue_expected
raster/test/regress/rt_neighborhood.sql
raster/test/regress/rt_neighborhood_expected
raster/test/regress/rt_pixelaspolygons.sql
raster/test/regress/rt_pixelaspolygons_expected
raster/test/regress/rt_quantile.sql
raster/test/regress/rt_quantile_expected
raster/test/regress/rt_summarystats.sql
raster/test/regress/rt_summarystats_expected
raster/test/regress/rt_valuecount.sql
raster/test/regress/rt_valuecount_expected

index ebc39bbf81920543073f5d687432e3f98029dfbd..1999d20655fede8c158a8a34a9dd1e900a8f2f0f 100644 (file)
@@ -1029,22 +1029,32 @@ rt_pixtype_name(rt_pixtype pixtype) {
 double
 rt_pixtype_get_min_value(rt_pixtype pixtype) {
        switch (pixtype) {
-               case PT_1BB:
-               case PT_2BUI:
-               case PT_4BUI:
+               case PT_1BB: {
+                       return (double) rt_util_clamp_to_1BB((double) CHAR_MIN);
+               }
+               case PT_2BUI: {
+                       return (double) rt_util_clamp_to_2BUI((double) CHAR_MIN);
+               }
+               case PT_4BUI: {
+                       return (double) rt_util_clamp_to_4BUI((double) CHAR_MIN);
+               }
                case PT_8BUI: {
-                       return (double) CHAR_MIN;
+                       return (double) rt_util_clamp_to_8BUI((double) CHAR_MIN);
                }
                case PT_8BSI: {
-                       return (double) SCHAR_MIN;
+                       return (double) rt_util_clamp_to_8BSI((double) SCHAR_MIN);
+               }
+               case PT_16BSI: {
+                       return (double) rt_util_clamp_to_16BSI((double) SHRT_MIN);
                }
-               case PT_16BSI:
                case PT_16BUI: {
-                       return (double) SHRT_MIN;
+                       return (double) rt_util_clamp_to_16BUI((double) SHRT_MIN);
+               }
+               case PT_32BSI: {
+                       return (double) rt_util_clamp_to_32BSI((double) INT_MIN);
                }
-               case PT_32BSI:
                case PT_32BUI: {
-                       return (double) INT_MIN;
+                       return (double) rt_util_clamp_to_32BUI((double) INT_MIN);
                }
                case PT_32BF: {
                        return (double) -FLT_MAX;
@@ -2284,6 +2294,8 @@ int rt_band_get_nearest_pixel(
        RASTER_DEBUG(3, "Starting");
 
        minval = rt_pixtype_get_min_value(band->pixtype);
+       RASTER_DEBUGF(4, "pixtype: %s", rt_pixtype_name(band->pixtype));
+       RASTER_DEBUGF(4, "minval: %f", minval);
 
        if (!distance)
                d0 = 1;
index 1c2efdee5c54b85852bdf28710c71c088b7ce991..b318eca497d55639c6a5af9842e02e12272480dc 100644 (file)
@@ -18,6 +18,26 @@ FROM ST_Histogram(
                , 1, 5, 5, 3.14159
        )
 );
+SELECT
+       round(min::numeric, 3),
+       round(max::numeric, 3),
+       count,
+       round(percent::numeric, 3)
+FROM ST_Histogram(
+       ST_SetValue(
+               ST_SetValue(
+                       ST_SetValue(
+                               ST_AddBand(
+                                       ST_MakeEmptyRaster(10, 10, 10, 10, 2, 2, 0, 0,0)
+                                       , 1, '64BF', 0, NULL
+                               )
+                               , 1, 1, 1, -10
+                       )
+                       , 1, 5, 4, 0
+               )
+               , 1, 5, 5, 3.14159
+       )
+);
 SELECT
        round(min::numeric, 3),
        round(max::numeric, 3),
index 08e649024526f2211a652b5cd19697da03b2eb02..2a73a6394ed89939554fe85ba9dabdae6a14dec7 100644 (file)
@@ -8,6 +8,14 @@
 -1.787|-0.144|0|0.000
 -0.144|1.499|98|0.980
 1.499|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.142|100|-1.000
 -10.000|-7.372|1|0.010
 -7.372|-4.743|0|0.000
index 43236ac0f95cee6c61480c4bdeadf54364785526..e4d0b2112a9d8c5091874916af3d2f4132eec551 100644 (file)
@@ -50,6 +50,9 @@ DROP FUNCTION IF EXISTS make_test_raster();
 SELECT
        ST_NearestValue(rast, 1, 1, 1)
 FROM raster_nearestvalue;
+SELECT
+       ST_NearestValue(ST_SetBandNoDataValue(rast, NULL), 1, 1, 1)
+FROM raster_nearestvalue;
 SELECT
        ST_NearestValue(rast, 1, 2, 2)
 FROM raster_nearestvalue;
index 8ced9f4ee4240c4ab5f47e3728312fd6a2447cf7..a550555eb9ad6ee326eb6e0bc7a6d4591b03c915 100644 (file)
@@ -1,5 +1,6 @@
 NOTICE:  table "raster_nearestvalue" does not exist, skipping
 4
+0
 4
 10
 10
index 1232dc9a3f0790ad0dcd9e652937015169c95cb1..22a3adcada7e280f5366edabab2051f605065072 100644 (file)
@@ -40,6 +40,9 @@ DROP FUNCTION IF EXISTS make_test_raster();
 SELECT 
        ST_Neighborhood(rast, 1, 1, 1, 1)
 FROM raster_neighborhood;
+SELECT 
+       ST_Neighborhood(ST_SetBandNoDataValue(rast, NULL), 1, 1, 1, 1)
+FROM raster_neighborhood;
 SELECT 
        ST_Neighborhood(rast, 1, 2, 2, 1)
 FROM raster_neighborhood;
index 36b8ca1e2c719d9ea9be5520a79a1c3d86d9506e..7cfc3733731aa3091a037c675b0a06ed92dda404 100644 (file)
@@ -1,5 +1,6 @@
 NOTICE:  table "raster_neighborhood" does not exist, skipping
 {{NULL,NULL,NULL},{NULL,NULL,1},{NULL,1,1}}
+{{0,0,0},{0,0,1},{0,1,1}}
 {{NULL,1,1},{1,1,NULL},{1,1,1}}
 {{1,1,1},{1,1,1},{1,NULL,1}}
 {{1,1,NULL,1,1},{1,1,1,1,NULL},{NULL,1,1,1,1},{1,1,NULL,1,1},{1,1,1,1,NULL}}
index b9e9c723de311e0ef5612f65d2a204ee207c4228..80ffcebd72bddc58901a6799a13bd5098eb23cf4 100644 (file)
@@ -39,6 +39,14 @@ SELECT
 FROM (SELECT ST_PixelAsPolygons(rast) AS pix FROM raster_pixelaspolygons) foo
 ORDER BY 1, 2, 4;
 
+SELECT
+       (pix).x,
+       (pix).y,
+       (pix).val,
+       ST_AsText((pix).geom)
+FROM (SELECT ST_PixelAsPolygons(ST_SetBandNoDataValue(rast, NULL)) AS pix FROM raster_pixelaspolygons) foo
+ORDER BY 1, 2, 4;
+
 SELECT
        (pix).x,
        (pix).y,
index f80c4daa950426583213973b196b8e085a5b9d9c..888201c7570271d3ff5f53d240d2c70358def104 100644 (file)
@@ -199,6 +199,106 @@ NOTICE:  table "raster_pixelaspolygons" does not exist, skipping
 10|8|0|POLYGON((9 -7,10 -7,10 -8,9 -8,9 -7))
 10|9|19|POLYGON((9 -8,10 -8,10 -9,9 -9,9 -8))
 10|10|0|POLYGON((9 -9,10 -9,10 -10,9 -10,9 -9))
+1|1|0|POLYGON((0 0,1 0,1 -1,0 -1,0 0))
+1|2|3|POLYGON((0 -1,1 -1,1 -2,0 -2,0 -1))
+1|3|0|POLYGON((0 -2,1 -2,1 -3,0 -3,0 -2))
+1|4|5|POLYGON((0 -3,1 -3,1 -4,0 -4,0 -3))
+1|5|0|POLYGON((0 -4,1 -4,1 -5,0 -5,0 -4))
+1|6|7|POLYGON((0 -5,1 -5,1 -6,0 -6,0 -5))
+1|7|0|POLYGON((0 -6,1 -6,1 -7,0 -7,0 -6))
+1|8|9|POLYGON((0 -7,1 -7,1 -8,0 -8,0 -7))
+1|9|0|POLYGON((0 -8,1 -8,1 -9,0 -9,0 -8))
+1|10|11|POLYGON((0 -9,1 -9,1 -10,0 -10,0 -9))
+2|1|3|POLYGON((1 0,2 0,2 -1,1 -1,1 0))
+2|2|0|POLYGON((1 -1,2 -1,2 -2,1 -2,1 -1))
+2|3|5|POLYGON((1 -2,2 -2,2 -3,1 -3,1 -2))
+2|4|0|POLYGON((1 -3,2 -3,2 -4,1 -4,1 -3))
+2|5|7|POLYGON((1 -4,2 -4,2 -5,1 -5,1 -4))
+2|6|0|POLYGON((1 -5,2 -5,2 -6,1 -6,1 -5))
+2|7|9|POLYGON((1 -6,2 -6,2 -7,1 -7,1 -6))
+2|8|0|POLYGON((1 -7,2 -7,2 -8,1 -8,1 -7))
+2|9|11|POLYGON((1 -8,2 -8,2 -9,1 -9,1 -8))
+2|10|0|POLYGON((1 -9,2 -9,2 -10,1 -10,1 -9))
+3|1|0|POLYGON((2 0,3 0,3 -1,2 -1,2 0))
+3|2|5|POLYGON((2 -1,3 -1,3 -2,2 -2,2 -1))
+3|3|0|POLYGON((2 -2,3 -2,3 -3,2 -3,2 -2))
+3|4|7|POLYGON((2 -3,3 -3,3 -4,2 -4,2 -3))
+3|5|0|POLYGON((2 -4,3 -4,3 -5,2 -5,2 -4))
+3|6|9|POLYGON((2 -5,3 -5,3 -6,2 -6,2 -5))
+3|7|0|POLYGON((2 -6,3 -6,3 -7,2 -7,2 -6))
+3|8|11|POLYGON((2 -7,3 -7,3 -8,2 -8,2 -7))
+3|9|0|POLYGON((2 -8,3 -8,3 -9,2 -9,2 -8))
+3|10|13|POLYGON((2 -9,3 -9,3 -10,2 -10,2 -9))
+4|1|5|POLYGON((3 0,4 0,4 -1,3 -1,3 0))
+4|2|0|POLYGON((3 -1,4 -1,4 -2,3 -2,3 -1))
+4|3|7|POLYGON((3 -2,4 -2,4 -3,3 -3,3 -2))
+4|4|0|POLYGON((3 -3,4 -3,4 -4,3 -4,3 -3))
+4|5|9|POLYGON((3 -4,4 -4,4 -5,3 -5,3 -4))
+4|6|0|POLYGON((3 -5,4 -5,4 -6,3 -6,3 -5))
+4|7|11|POLYGON((3 -6,4 -6,4 -7,3 -7,3 -6))
+4|8|0|POLYGON((3 -7,4 -7,4 -8,3 -8,3 -7))
+4|9|13|POLYGON((3 -8,4 -8,4 -9,3 -9,3 -8))
+4|10|0|POLYGON((3 -9,4 -9,4 -10,3 -10,3 -9))
+5|1|0|POLYGON((4 0,5 0,5 -1,4 -1,4 0))
+5|2|7|POLYGON((4 -1,5 -1,5 -2,4 -2,4 -1))
+5|3|0|POLYGON((4 -2,5 -2,5 -3,4 -3,4 -2))
+5|4|9|POLYGON((4 -3,5 -3,5 -4,4 -4,4 -3))
+5|5|0|POLYGON((4 -4,5 -4,5 -5,4 -5,4 -4))
+5|6|11|POLYGON((4 -5,5 -5,5 -6,4 -6,4 -5))
+5|7|0|POLYGON((4 -6,5 -6,5 -7,4 -7,4 -6))
+5|8|13|POLYGON((4 -7,5 -7,5 -8,4 -8,4 -7))
+5|9|0|POLYGON((4 -8,5 -8,5 -9,4 -9,4 -8))
+5|10|15|POLYGON((4 -9,5 -9,5 -10,4 -10,4 -9))
+6|1|7|POLYGON((5 0,6 0,6 -1,5 -1,5 0))
+6|2|0|POLYGON((5 -1,6 -1,6 -2,5 -2,5 -1))
+6|3|9|POLYGON((5 -2,6 -2,6 -3,5 -3,5 -2))
+6|4|0|POLYGON((5 -3,6 -3,6 -4,5 -4,5 -3))
+6|5|11|POLYGON((5 -4,6 -4,6 -5,5 -5,5 -4))
+6|6|0|POLYGON((5 -5,6 -5,6 -6,5 -6,5 -5))
+6|7|13|POLYGON((5 -6,6 -6,6 -7,5 -7,5 -6))
+6|8|0|POLYGON((5 -7,6 -7,6 -8,5 -8,5 -7))
+6|9|15|POLYGON((5 -8,6 -8,6 -9,5 -9,5 -8))
+6|10|0|POLYGON((5 -9,6 -9,6 -10,5 -10,5 -9))
+7|1|0|POLYGON((6 0,7 0,7 -1,6 -1,6 0))
+7|2|9|POLYGON((6 -1,7 -1,7 -2,6 -2,6 -1))
+7|3|0|POLYGON((6 -2,7 -2,7 -3,6 -3,6 -2))
+7|4|11|POLYGON((6 -3,7 -3,7 -4,6 -4,6 -3))
+7|5|0|POLYGON((6 -4,7 -4,7 -5,6 -5,6 -4))
+7|6|13|POLYGON((6 -5,7 -5,7 -6,6 -6,6 -5))
+7|7|0|POLYGON((6 -6,7 -6,7 -7,6 -7,6 -6))
+7|8|15|POLYGON((6 -7,7 -7,7 -8,6 -8,6 -7))
+7|9|0|POLYGON((6 -8,7 -8,7 -9,6 -9,6 -8))
+7|10|17|POLYGON((6 -9,7 -9,7 -10,6 -10,6 -9))
+8|1|9|POLYGON((7 0,8 0,8 -1,7 -1,7 0))
+8|2|0|POLYGON((7 -1,8 -1,8 -2,7 -2,7 -1))
+8|3|11|POLYGON((7 -2,8 -2,8 -3,7 -3,7 -2))
+8|4|0|POLYGON((7 -3,8 -3,8 -4,7 -4,7 -3))
+8|5|13|POLYGON((7 -4,8 -4,8 -5,7 -5,7 -4))
+8|6|0|POLYGON((7 -5,8 -5,8 -6,7 -6,7 -5))
+8|7|15|POLYGON((7 -6,8 -6,8 -7,7 -7,7 -6))
+8|8|0|POLYGON((7 -7,8 -7,8 -8,7 -8,7 -7))
+8|9|17|POLYGON((7 -8,8 -8,8 -9,7 -9,7 -8))
+8|10|0|POLYGON((7 -9,8 -9,8 -10,7 -10,7 -9))
+9|1|0|POLYGON((8 0,9 0,9 -1,8 -1,8 0))
+9|2|11|POLYGON((8 -1,9 -1,9 -2,8 -2,8 -1))
+9|3|0|POLYGON((8 -2,9 -2,9 -3,8 -3,8 -2))
+9|4|13|POLYGON((8 -3,9 -3,9 -4,8 -4,8 -3))
+9|5|0|POLYGON((8 -4,9 -4,9 -5,8 -5,8 -4))
+9|6|15|POLYGON((8 -5,9 -5,9 -6,8 -6,8 -5))
+9|7|0|POLYGON((8 -6,9 -6,9 -7,8 -7,8 -6))
+9|8|17|POLYGON((8 -7,9 -7,9 -8,8 -8,8 -7))
+9|9|0|POLYGON((8 -8,9 -8,9 -9,8 -9,8 -8))
+9|10|19|POLYGON((8 -9,9 -9,9 -10,8 -10,8 -9))
+10|1|11|POLYGON((9 0,10 0,10 -1,9 -1,9 0))
+10|2|0|POLYGON((9 -1,10 -1,10 -2,9 -2,9 -1))
+10|3|13|POLYGON((9 -2,10 -2,10 -3,9 -3,9 -2))
+10|4|0|POLYGON((9 -3,10 -3,10 -4,9 -4,9 -3))
+10|5|15|POLYGON((9 -4,10 -4,10 -5,9 -5,9 -4))
+10|6|0|POLYGON((9 -5,10 -5,10 -6,9 -6,9 -5))
+10|7|17|POLYGON((9 -6,10 -6,10 -7,9 -7,9 -6))
+10|8|0|POLYGON((9 -7,10 -7,10 -8,9 -8,9 -7))
+10|9|19|POLYGON((9 -8,10 -8,10 -9,9 -9,9 -8))
+10|10|0|POLYGON((9 -9,10 -9,10 -10,9 -10,9 -9))
 POLYGON((0 0,1 0,1 -1,0 -1,0 0))
 POLYGON((0 -1,1 -1,1 -2,0 -2,0 -1))
 POLYGON((-2 2,-1 2,-1 1,-2 1,-2 2))
index dba738488455215f49cc77be5a119431cd7171c8..df320bda164f83b80cb48278234fdab0c3b3fa49 100644 (file)
@@ -34,6 +34,25 @@ FROM ST_Quantile(
                )
                , 1, 5, 5, 3.14159
        )
+       , 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
+       round(quantile::numeric, 3),
+       round(value::numeric, 3)
+FROM ST_Quantile(
+       ST_SetValue(
+               ST_SetValue(
+                       ST_SetValue(
+                               ST_AddBand(
+                                       ST_MakeEmptyRaster(10, 10, 10, 10, 2, 2, 0, 0,0)
+                                       , 1, '64BF', 0, NULL
+                               )
+                               , 1, 1, 1, -10
+                       )
+                       , 1, 5, 4, 0
+               )
+               , 1, 5, 5, 3.14159
+       )
        , 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
index 3db327582f6e931ac9442c4bf2473eced1e651d8..27117ac81cf7d397f268c87e4cb5789633e364fc 100644 (file)
 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
+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|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.250|0.000
index 8d75d5a369babf13e1fea4910efce61c7fa1052c..a51037565bdca20d5cf01b30dbfaf93849833679 100644 (file)
@@ -21,6 +21,29 @@ FROM ST_SummaryStats(
        )
        , 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(
+       ST_SetValue(
+               ST_SetValue(
+                       ST_SetValue(
+                               ST_AddBand(
+                                       ST_MakeEmptyRaster(10, 10, 10, 10, 2, 2, 0, 0,0)
+                                       , 1, '64BF', 0, NULL
+                               )
+                               , 1, 1, 1, -10
+                       )
+                       , 1, 5, 4, 0
+               )
+               , 1, 5, 5, 3.14159
+       )
+       , TRUE
+);
 SELECT count FROM ST_SummaryStats(
        ST_SetValue(
                ST_SetValue(
index ab36e5a99c8e042063f78ab7a00dbc2c4af66068..120a530bab7ce22aa0ca4858649772607b3196e4 100644 (file)
@@ -1,4 +1,5 @@
 2|-6.858|-3.429|6.571|-10.000|3.142
+100|-6.858|-0.069|1.046|-10.000|3.142
 2
 100
 -3.429|6.571
index ae8139f6022e24eaac2dd554a58088e43d82c443..4a9dec7395cbdd0b7c19f2a98624081cbd36def0 100644 (file)
@@ -13,6 +13,21 @@ SELECT round(value::numeric, 3), count FROM ST_ValueCount(
                , 1, 5, 5, 3.14159
        )
 , 1, TRUE, ARRAY[]::double precision[], 0);
+SELECT round(value::numeric, 3), count FROM ST_ValueCount(
+       ST_SetValue(
+               ST_SetValue(
+                       ST_SetValue(
+                               ST_AddBand(
+                                       ST_MakeEmptyRaster(10, 10, 10, 10, 2, 2, 0, 0,0)
+                                       , 1, '64BF', 0, NULL
+                               )
+                               , 1, 1, 1, -10
+                       )
+                       , 1, 5, 4, 0
+               )
+               , 1, 5, 5, 3.14159
+       )
+, 1, TRUE, ARRAY[]::double precision[], 0);
 SELECT round(value::numeric, 3), count FROM ST_ValueCount(
        ST_SetValue(
                ST_SetValue(
index 2e623f564d8987cbc170aede008a4905519a20a7..5b84f9babaef47c693d18246c39dea99e3123f43 100644 (file)
@@ -1,6 +1,9 @@
 -10.000|1
 3.142|1
 -10.000|1
+0.000|98
+3.142|1
+-10.000|1
 3.142|1
 -10.000|1
 0.000|98