From: Bborie Park Date: Tue, 16 Oct 2012 19:55:34 +0000 (+0000) Subject: Corrected handling of NULL raster resulting from NO intersection of input rasters... X-Git-Tag: 2.1.0beta2~529 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0d253d3aab9b0f7a22a898d0373e9d63c9077356;p=postgis Corrected handling of NULL raster resulting from NO intersection of input rasters in map algebra. Fixed spelling mistakes. Additional tests for intersections of more than 3 rasters that don't actually intersect in ST_MapAlgebra git-svn-id: http://svn.osgeo.org/postgis/trunk@10439 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index 9ddb18c24..f65f20056 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -13464,6 +13464,7 @@ rt_raster_iterator( rast = rt_raster_from_two_rasters(rtnrast, _param->raster[i], extenttype, &status, NULL); rtdealloc(rtnrast); + if (rast == NULL || !status) { rterror("rt_raster_iterator: Unable to compute %s extent of rasters", extenttype == ET_UNION ? "union" : "intersection" @@ -13474,14 +13475,16 @@ rt_raster_iterator( return NULL; } else if (rt_raster_is_empty(rast)) { - rterror("rt_raster_iterator: Computed raster for %s extent is empty", + rtinfo("rt_raster_iterator: Computed raster for %s extent is empty", extenttype == ET_UNION ? "union" : "intersection" ); _rti_param_destroy(_param); + *noerr = 1; return NULL; } + rtnrast = rast; rast = NULL; } diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index d9789ea59..44670aefa 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -14238,9 +14238,11 @@ Datum RASTER_nMapAlgebra(PG_FUNCTION_ARGS) rtpg_nmapalgebra_arg_destroy(arg); if (!noerr) { - elog(ERROR, "RASTER_nMapAlgebra: Unable to run raster interator function"); + elog(ERROR, "RASTER_nMapAlgebra: Unable to run raster iterator function"); PG_RETURN_NULL(); } + else if (raster == NULL) + PG_RETURN_NULL(); pgraster = rt_raster_serialize(raster); rt_raster_destroy(raster); @@ -14937,7 +14939,7 @@ Datum RASTER_union_transfn(PG_FUNCTION_ARGS) ); if (!noerr) { - elog(ERROR, "RASTER_union_transfn: Unable to run raster interator function"); + elog(ERROR, "RASTER_union_transfn: Unable to run raster iterator function"); pfree(itrset); rtpg_union_arg_destroy(iwr); @@ -15041,7 +15043,7 @@ Datum RASTER_union_finalfn(PG_FUNCTION_ARGS) ); if (!noerr) { - elog(ERROR, "RASTER_union_finalfn: Unable to run raster interator function"); + elog(ERROR, "RASTER_union_finalfn: Unable to run raster iterator function"); pfree(itrset); rtpg_union_arg_destroy(iwr); if (_rtn != NULL) diff --git a/raster/test/regress/rt_mapalgebra.sql b/raster/test/regress/rt_mapalgebra.sql index 96167deed..d0a878057 100644 --- a/raster/test/regress/rt_mapalgebra.sql +++ b/raster/test/regress/rt_mapalgebra.sql @@ -519,6 +519,30 @@ SELECT (ST_BandMetadata(rast, 1)) FROM foo; +WITH foo AS ( + SELECT + t1.rid AS rid1, + t2.rid AS rid2, + t3.rid AS rid3, + ST_MapAlgebra( + ARRAY[ROW(t1.rast, 1), ROW(t2.rast, 1), ROW(t3.rast, 1)]::rastbandarg[], + 'raster_nmapalgebra_test(double precision[], int[], text[])'::regprocedure + ) AS rast + FROM raster_nmapalgebra_in t1 + CROSS JOIN raster_nmapalgebra_in t2 + CROSS JOIN raster_nmapalgebra_in t3 + WHERE t1.rid = 20 + AND t2.rid = 21 + AND t3.rid = 22 +) +SELECT + rid1, + rid2, + rid3, + (ST_Metadata(rast)), + (ST_BandMetadata(rast, 1)) +FROM foo; + INSERT INTO raster_nmapalgebra_in SELECT 30, ST_AddBand(ST_AddBand(ST_AddBand(ST_MakeEmptyRaster(2, 2, 0, 0, 1, -1, 0, 0, 0), 1, '16BUI', 1, 0), 2, '8BUI', 10, 0), 3, '32BUI', 100, 0) AS rast UNION ALL SELECT 31, ST_AddBand(ST_AddBand(ST_AddBand(ST_MakeEmptyRaster(2, 2, 0, 1, 1, -1, 0, 0, 0), 1, '16BUI', 2, 0), 2, '8BUI', 20, 0), 3, '32BUI', 300, 0) AS rast diff --git a/raster/test/regress/rt_mapalgebra_expected b/raster/test/regress/rt_mapalgebra_expected index d2251f402..575cb668b 100644 --- a/raster/test/regress/rt_mapalgebra_expected +++ b/raster/test/regress/rt_mapalgebra_expected @@ -130,7 +130,8 @@ NOTICE: value = {{{1}},{{2}}} NOTICE: pos = [0:2][1:2]={{1,1},{2,2},{1,1}} NOTICE: userargs = 20|21|(1,-1,1,1,1,-1,0,0,0,1)|(16BUI,0,f,) -ERROR: rt_raster_iterator: Computed raster for intersection extent is empty +NOTICE: rt_raster_iterator: Computed raster for intersection extent is empty +20|22|| NOTICE: value = {{{2}},{{3}}} NOTICE: pos = [0:2][1:2]={{1,1},{1,2},{2,1}} NOTICE: userargs = @@ -264,6 +265,8 @@ NOTICE: value = {{{NULL}},{{NULL}},{{3}}} NOTICE: pos = [0:3][1:2]={{2,2},{2,4},{1,3},{2,2}} NOTICE: userargs = 20|21|22|(0,-2,2,2,1,-1,0,0,0,1)|(16BUI,0,f,) +NOTICE: rt_raster_iterator: Computed raster for intersection extent is empty +20|21|22|| NOTICE: value = {{{1}},{{10}},{{100}}} NOTICE: pos = [0:3][1:2]={{1,1},{1,1},{1,1},{1,1}} NOTICE: userargs =