]> granicus.if.org Git - postgis/commitdiff
Corrected handling of NULL raster resulting from NO intersection of input rasters...
authorBborie Park <bkpark at ucdavis.edu>
Tue, 16 Oct 2012 19:55:34 +0000 (19:55 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Tue, 16 Oct 2012 19:55:34 +0000 (19:55 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@10439 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_api.c
raster/rt_pg/rt_pg.c
raster/test/regress/rt_mapalgebra.sql
raster/test/regress/rt_mapalgebra_expected

index 9ddb18c241ecac4f63dd0dfb8c2fd8ef2e9a8ffb..f65f200564b396fa54c7fa53257c9882d05b98f2 100644 (file)
@@ -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;
                        }
index d9789ea5992f48e215148f1332ca3a943116153f..44670aefaa0950e97ae37a9d3ec5275c49375a99 100644 (file)
@@ -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)
index 96167deed4b2fdc895d8edf2627307472264384a..d0a8780570c10f0a515f8f02286a110d81c4bbb3 100644 (file)
@@ -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
index d2251f402ca40386f945d9bcf6b62f69e86ae1a9..575cb668be5690245cfe44d5a10e5eb5c85eddca 100644 (file)
@@ -130,7 +130,8 @@ NOTICE:  value = {{{1}},{{2}}}
 NOTICE:  pos = [0:2][1:2]={{1,1},{2,2},{1,1}}
 NOTICE:  userargs = <NULL>
 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 = <NULL>
@@ -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 = <NULL>
 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 = <NULL>