]> granicus.if.org Git - postgis/commitdiff
Refactored return and parameters of rt_raster_from_two_rasters()
authorBborie Park <bkpark at ucdavis.edu>
Wed, 28 Nov 2012 19:31:59 +0000 (19:31 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Wed, 28 Nov 2012 19:31:59 +0000 (19:31 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@10745 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_api.c
raster/rt_core/rt_api.h
raster/rt_pg/rt_pg.c
raster/test/core/testapi.c

index 6064f6026707a1feb27898d02a7919821d64c367..34c5e091352960b93395630ba6cba06693e9bca5 100644 (file)
@@ -12452,17 +12452,17 @@ rt_raster_same_alignment(
  * @param rast1 : the first raster
  * @param rast2 : the second raster
  * @param extenttype : type of extent for the output raster
- * @param noerr : if 0, error occurred
- * @param offset : 4-element array indicating the X,Y offsets
+ * @param *rtnraster : raster of computed extent
+ * @param *offset : 4-element array indicating the X,Y offsets
  * for each raster. 0,1 for rast1 X,Y. 2,3 for rast2 X,Y.
  *
- * @return raster object if success, NULL otherwise
+ * @return ES_NONE if success, ES_ERROR if error
  */
-rt_raster
+rt_errorstate
 rt_raster_from_two_rasters(
        rt_raster rast1, rt_raster rast2,
        rt_extenttype extenttype,
-       int *noerr, double *offset
+       rt_raster *rtnraster, double *offset
 ) {
        int i;
 
@@ -12477,17 +12477,19 @@ rt_raster_from_two_rasters(
 
        assert(NULL != rast1);
        assert(NULL != rast2);
+       assert(NULL != rtnraster);
 
-       *noerr = 0;
+       /* set rtnraster to NULL */
+       *rtnraster = NULL;
 
        /* rasters must be aligned */
        if (rt_raster_same_alignment(rast1, rast2, &aligned, NULL) != ES_NONE) {
                rterror("rt_raster_from_two_rasters: Unable to test for alignment on the two rasters");
-               return NULL;
+               return ES_ERROR;
        }
        if (!aligned) {
                rterror("rt_raster_from_two_rasters: The two rasters provided do not have the same alignment");
-               return NULL;
+               return ES_ERROR;
        }
 
        /* dimensions */
@@ -12504,7 +12506,7 @@ rt_raster_from_two_rasters(
                NULL
        ) != ES_NONE) {
                rterror("rt_raster_from_two_rasters: Unable to compute offsets of the second raster relative to the first raster");
-               return NULL;
+               return ES_ERROR;
        }
        _offset[1][0] = -1 * _offset[1][0];
        _offset[1][1] = -1 * _offset[1][1];
@@ -12535,7 +12537,7 @@ rt_raster_from_two_rasters(
                        );
                        if (raster == NULL) {
                                rterror("rt_raster_from_two_rasters: Unable to create output raster");
-                               return NULL;
+                               return ES_ERROR;
                        }
                        rt_raster_set_srid(raster, _rast[i]->srid);
                        rt_raster_get_geotransform_matrix(_rast[i], gt);
@@ -12578,7 +12580,7 @@ rt_raster_from_two_rasters(
                                NULL
                        ) != ES_NONE) {
                                rterror("rt_raster_from_two_rasters: Unable to get spatial coordinates of upper-left pixel of output raster");
-                               return NULL;
+                               return ES_ERROR;
                        }
 
                        dim[0] = off[2] - off[0] + 1;
@@ -12597,7 +12599,7 @@ rt_raster_from_two_rasters(
                        );
                        if (raster == NULL) {
                                rterror("rt_raster_from_two_rasters: Unable to create output raster");
-                               return NULL;
+                               return ES_ERROR;
                        }
                        rt_raster_set_srid(raster, _rast[0]->srid);
                        rt_raster_set_geotransform_matrix(raster, gt);
@@ -12619,7 +12621,7 @@ rt_raster_from_two_rasters(
                        ) != ES_NONE) {
                                rterror("rt_raster_from_two_rasters: Unable to get offsets of the FIRST raster relative to the output raster");
                                rt_raster_destroy(raster);
-                               return NULL;
+                               return ES_ERROR;
                        }
                        _offset[0][0] *= -1;
                        _offset[0][1] *= -1;
@@ -12632,7 +12634,7 @@ rt_raster_from_two_rasters(
                        ) != ES_NONE) {
                                rterror("rt_raster_from_two_rasters: Unable to get offsets of the SECOND raster relative to the output raster");
                                rt_raster_destroy(raster);
-                               return NULL;
+                               return ES_ERROR;
                        }
                        _offset[1][0] *= -1;
                        _offset[1][1] *= -1;
@@ -12651,7 +12653,7 @@ rt_raster_from_two_rasters(
                                raster = rt_raster_new(0, 0);
                                if (raster == NULL) {
                                        rterror("rt_raster_from_two_rasters: Unable to create output raster");
-                                       return NULL;
+                                       return ES_ERROR;
                                }
                                rt_raster_set_srid(raster, _rast[0]->srid);
                                rt_raster_set_scale(raster, 0, 0);
@@ -12662,8 +12664,8 @@ rt_raster_from_two_rasters(
                                                offset[i] = _offset[i / 2][i % 2];
                                }
 
-                               *noerr = 1;
-                               return raster;
+                               *rtnraster = raster;
+                               return ES_NONE;
                        }
 
                        if (_offset[1][0] > 0)
@@ -12686,7 +12688,7 @@ rt_raster_from_two_rasters(
                        );
                        if (raster == NULL) {
                                rterror("rt_raster_from_two_rasters: Unable to create output raster");
-                               return NULL;
+                               return ES_ERROR;
                        }
                        rt_raster_set_srid(raster, _rast[0]->srid);
 
@@ -12700,7 +12702,7 @@ rt_raster_from_two_rasters(
                        ) != ES_NONE) {
                                rterror("rt_raster_from_two_rasters: Unable to get spatial coordinates of upper-left pixel of output raster");
                                rt_raster_destroy(raster);
-                               return NULL;
+                               return ES_ERROR;
                        }
 
                        rt_raster_set_geotransform_matrix(raster, gt);
@@ -12714,7 +12716,7 @@ rt_raster_from_two_rasters(
                        ) != ES_NONE) {
                                rterror("rt_raster_from_two_rasters: Unable to get pixel coordinates to compute the offsets of the FIRST raster relative to the output raster");
                                rt_raster_destroy(raster);
-                               return NULL;
+                               return ES_ERROR;
                        }
                        _offset[0][0] *= -1;
                        _offset[0][1] *= -1;
@@ -12727,7 +12729,7 @@ rt_raster_from_two_rasters(
                        ) != ES_NONE) {
                                rterror("rt_raster_from_two_rasters: Unable to get pixel coordinates to compute the offsets of the SECOND raster relative to the output raster");
                                rt_raster_destroy(raster);
-                               return NULL;
+                               return ES_ERROR;
                        }
                        _offset[1][0] *= -1;
                        _offset[1][1] *= -1;
@@ -12744,8 +12746,8 @@ rt_raster_from_two_rasters(
                        offset[i] = _offset[i / 2][i % 2];
        }
 
-       *noerr = 1;
-       return raster;
+       *rtnraster = raster;
+       return ES_NONE;
 }
 
 /**
@@ -13731,10 +13733,10 @@ rt_raster_iterator(
                                if (_param->isempty[i])
                                        continue;
 
-                               rast = rt_raster_from_two_rasters(rtnrast, _param->raster[i], extenttype, &status, NULL);
+                               status = rt_raster_from_two_rasters(rtnrast, _param->raster[i], extenttype, &rast, NULL);
                                rtdealloc(rtnrast);
 
-                               if (rast == NULL || !status) {
+                               if (rast == NULL || status != ES_NONE) {
                                        rterror("rt_raster_iterator: Unable to compute %s extent of rasters",
                                                extenttype == ET_UNION ? "union" : "intersection"
                                        );
@@ -13902,9 +13904,9 @@ rt_raster_iterator(
                if (_param->isempty[i])
                        continue;
 
-               rast = rt_raster_from_two_rasters(rtnrast, _param->raster[i], ET_FIRST, &status, offset);
+               status = rt_raster_from_two_rasters(rtnrast, _param->raster[i], ET_FIRST, &rast, offset);
                rtdealloc(rast);
-               if (!status) {
+               if (status != ES_NONE) {
                        rterror("rt_raster_iterator: Unable to compute raster offsets");
 
                        _rti_iterator_arg_destroy(_param);
index 9dda9c057c9f3fb26cf76ef4bc0a12d84420f87e..0d5f3a8bfa0503f891bdf5356e9ae12cbe64691b 100644 (file)
@@ -1871,17 +1871,17 @@ rt_errorstate rt_raster_same_alignment(
  * @param rast1 : the first raster
  * @param rast2 : the second raster
  * @param extenttype : type of extent for the output raster
- * @param noerr : if 0, error occurred
- * @param offset : 4-element array indicating the X,Y offsets
+ * @param *rtnraster : raster of computed extent
+ * @param *offset : 4-element array indicating the X,Y offsets
  * for each raster. 0,1 for rast1 X,Y. 2,3 for rast2 X,Y.
  *
- * @return raster object if success, NULL otherwise
+ * @return ES_NONE if success, ES_ERROR if error
  */
-rt_raster
+rt_errorstate
 rt_raster_from_two_rasters(
        rt_raster rast1, rt_raster rast2,
        rt_extenttype extenttype,
-       int *noerr, double *offset
+       rt_raster *rtnraster, double *offset
 );
 
 /**
index 745b03eb7faf43670cb295e75f2e8f417d2fe551..979c0045eeb25669519ded974d68af3500542a06 100644 (file)
@@ -13490,12 +13490,12 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS)
        POSTGIS_RT_DEBUGF(3, "extenttype: %d %s", extenttype, extenttypename);
 
        /* computed raster from extent type */
-       raster = rt_raster_from_two_rasters(
+       err = rt_raster_from_two_rasters(
                _rast[0], _rast[1],
                extenttype,
-               &err, _offset
+               &raster, _offset
        );
-       if (!err) {
+       if (err != ES_NONE) {
                elog(ERROR, "RASTER_mapAlgebra2: Unable to get output raster of correct extent");
                for (k = 0; k < set_count; k++) {
                        if (_rast[k] != NULL)
@@ -17021,8 +17021,8 @@ Datum RASTER_clip(PG_FUNCTION_ARGS)
                if (rt_band_get_isnodata_flag(band)) {
                        /* create raster */
                        if (rtn == NULL) {
-                               rtn = rt_raster_from_two_rasters(arg->raster, arg->mask, arg->extenttype, &noerr, NULL);
-                               if (!noerr) {
+                               noerr = rt_raster_from_two_rasters(arg->raster, arg->mask, arg->extenttype, &rtn, NULL);
+                               if (noerr != ES_NONE) {
                                        elog(ERROR, "RASTER_clip: Unable to create output raster");
                                        rtpg_clip_arg_destroy(arg);
                                        PG_FREE_IF_COPY(pgraster, 0);
index 44cfeb2be130ad1cce52bdc43c57c514b6cd559b..48d85e369f729b13c7548e04004df00e550b8787 100644 (file)
@@ -6776,13 +6776,13 @@ static void testFromTwoRasters() {
        assert(rast2);
        rt_raster_set_scale(rast2, 1, 1);
 
-       rast = rt_raster_from_two_rasters(
+       err = rt_raster_from_two_rasters(
                rast1, rast2,
                ET_FIRST,
-               &err,
+               &rast,
                offset
        );
-       CHECK((err != 0));
+       CHECK(err == ES_NONE);
        CHECK(rast);
        CHECK((rt_raster_get_width(rast) == 4));
        CHECK((rt_raster_get_height(rast) == 4));
@@ -6792,13 +6792,13 @@ static void testFromTwoRasters() {
        CHECK(FLT_EQ(offset[3], 2));
        deepRelease(rast);
 
-       rast = rt_raster_from_two_rasters(
+       err = rt_raster_from_two_rasters(
                rast1, rast2,
                ET_SECOND,
-               &err,
+               &rast,
                offset
        );
-       CHECK((err != 0));
+       CHECK(err == ES_NONE);
        CHECK(rast);
        CHECK((rt_raster_get_width(rast) == 2));
        CHECK((rt_raster_get_height(rast) == 2));
@@ -6808,13 +6808,13 @@ static void testFromTwoRasters() {
        CHECK(FLT_EQ(offset[3], 0));
        deepRelease(rast);
 
-       rast = rt_raster_from_two_rasters(
+       err = rt_raster_from_two_rasters(
                rast1, rast2,
                ET_INTERSECTION,
-               &err,
+               &rast,
                offset
        );
-       CHECK((err != 0));
+       CHECK(err == ES_NONE);
        CHECK(rast);
        CHECK((rt_raster_get_width(rast) == 2));
        CHECK((rt_raster_get_height(rast) == 2));
@@ -6824,13 +6824,13 @@ static void testFromTwoRasters() {
        CHECK(FLT_EQ(offset[3], 0));
        deepRelease(rast);
 
-       rast = rt_raster_from_two_rasters(
+       err = rt_raster_from_two_rasters(
                rast1, rast2,
                ET_UNION,
-               &err,
+               &rast,
                offset
        );
-       CHECK((err != 0));
+       CHECK(err == ES_NONE);
        CHECK(rast);
        CHECK((rt_raster_get_width(rast) == 4));
        CHECK((rt_raster_get_height(rast) == 4));
@@ -6841,33 +6841,33 @@ static void testFromTwoRasters() {
        deepRelease(rast);
 
        rt_raster_set_scale(rast2, 1, 0.1);
-       rast = rt_raster_from_two_rasters(
+       err = rt_raster_from_two_rasters(
                rast1, rast2,
                ET_UNION,
-               &err,
+               &rast,
                offset
        );
-       CHECK((err == 0));
+       CHECK(err != ES_NONE);
        rt_raster_set_scale(rast2, 1, 1);
 
        rt_raster_set_srid(rast2, 9999);
-       rast = rt_raster_from_two_rasters(
+       err = rt_raster_from_two_rasters(
                rast1, rast2,
                ET_UNION,
-               &err,
+               &rast,
                offset
        );
-       CHECK((err == 0));
+       CHECK(err != ES_NONE);
        rt_raster_set_srid(rast2, 0);
 
        rt_raster_set_skews(rast2, -1, 1);
-       rast = rt_raster_from_two_rasters(
+       err = rt_raster_from_two_rasters(
                rast1, rast2,
                ET_UNION,
-               &err,
+               &rast,
                offset
        );
-       CHECK((err == 0));
+       CHECK(err != ES_NONE);
 
        deepRelease(rast2);
        deepRelease(rast1);