From: Bborie Park Date: Wed, 4 Jul 2012 00:33:00 +0000 (+0000) Subject: Fixed how the minimum possible value of a pixel type was being X-Git-Tag: 2.1.0beta2~822 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c07caf55e6013f1d8ca873063c60ef7eb86b327c;p=postgis Fixed how the minimum possible value of a pixel type was being determined. Added regression tests for band without NODATA. git-svn-id: http://svn.osgeo.org/postgis/trunk@10029 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index ebc39bbf8..1999d2065 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -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; diff --git a/raster/test/regress/rt_histogram.sql b/raster/test/regress/rt_histogram.sql index 1c2efdee5..b318eca49 100644 --- a/raster/test/regress/rt_histogram.sql +++ b/raster/test/regress/rt_histogram.sql @@ -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), diff --git a/raster/test/regress/rt_histogram_expected b/raster/test/regress/rt_histogram_expected index 08e649024..2a73a6394 100644 --- a/raster/test/regress/rt_histogram_expected +++ b/raster/test/regress/rt_histogram_expected @@ -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 diff --git a/raster/test/regress/rt_nearestvalue.sql b/raster/test/regress/rt_nearestvalue.sql index 43236ac0f..e4d0b2112 100644 --- a/raster/test/regress/rt_nearestvalue.sql +++ b/raster/test/regress/rt_nearestvalue.sql @@ -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; diff --git a/raster/test/regress/rt_nearestvalue_expected b/raster/test/regress/rt_nearestvalue_expected index 8ced9f4ee..a550555eb 100644 --- a/raster/test/regress/rt_nearestvalue_expected +++ b/raster/test/regress/rt_nearestvalue_expected @@ -1,5 +1,6 @@ NOTICE: table "raster_nearestvalue" does not exist, skipping 4 +0 4 10 10 diff --git a/raster/test/regress/rt_neighborhood.sql b/raster/test/regress/rt_neighborhood.sql index 1232dc9a3..22a3adcad 100644 --- a/raster/test/regress/rt_neighborhood.sql +++ b/raster/test/regress/rt_neighborhood.sql @@ -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; diff --git a/raster/test/regress/rt_neighborhood_expected b/raster/test/regress/rt_neighborhood_expected index 36b8ca1e2..7cfc37337 100644 --- a/raster/test/regress/rt_neighborhood_expected +++ b/raster/test/regress/rt_neighborhood_expected @@ -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}} diff --git a/raster/test/regress/rt_pixelaspolygons.sql b/raster/test/regress/rt_pixelaspolygons.sql index b9e9c723d..80ffcebd7 100644 --- a/raster/test/regress/rt_pixelaspolygons.sql +++ b/raster/test/regress/rt_pixelaspolygons.sql @@ -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, diff --git a/raster/test/regress/rt_pixelaspolygons_expected b/raster/test/regress/rt_pixelaspolygons_expected index f80c4daa9..888201c75 100644 --- a/raster/test/regress/rt_pixelaspolygons_expected +++ b/raster/test/regress/rt_pixelaspolygons_expected @@ -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)) diff --git a/raster/test/regress/rt_quantile.sql b/raster/test/regress/rt_quantile.sql index dba738488..df320bda1 100644 --- a/raster/test/regress/rt_quantile.sql +++ b/raster/test/regress/rt_quantile.sql @@ -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 diff --git a/raster/test/regress/rt_quantile_expected b/raster/test/regress/rt_quantile_expected index 3db327582..27117ac81 100644 --- a/raster/test/regress/rt_quantile_expected +++ b/raster/test/regress/rt_quantile_expected @@ -10,15 +10,26 @@ 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 diff --git a/raster/test/regress/rt_summarystats.sql b/raster/test/regress/rt_summarystats.sql index 8d75d5a36..a51037565 100644 --- a/raster/test/regress/rt_summarystats.sql +++ b/raster/test/regress/rt_summarystats.sql @@ -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( diff --git a/raster/test/regress/rt_summarystats_expected b/raster/test/regress/rt_summarystats_expected index ab36e5a99..120a530ba 100644 --- a/raster/test/regress/rt_summarystats_expected +++ b/raster/test/regress/rt_summarystats_expected @@ -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 diff --git a/raster/test/regress/rt_valuecount.sql b/raster/test/regress/rt_valuecount.sql index ae8139f60..4a9dec739 100644 --- a/raster/test/regress/rt_valuecount.sql +++ b/raster/test/regress/rt_valuecount.sql @@ -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( diff --git a/raster/test/regress/rt_valuecount_expected b/raster/test/regress/rt_valuecount_expected index 2e623f564..5b84f9bab 100644 --- a/raster/test/regress/rt_valuecount_expected +++ b/raster/test/regress/rt_valuecount_expected @@ -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