]> granicus.if.org Git - postgis/commitdiff
syntax cleanup
authorBborie Park <bkpark at ucdavis.edu>
Mon, 5 Oct 2015 17:37:18 +0000 (17:37 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Mon, 5 Oct 2015 17:37:18 +0000 (17:37 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@14195 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_mapalgebra.c
raster/rt_core/rt_pixel.c
raster/rt_pg/rtpg_mapalgebra.c
raster/test/regress/rt_mapalgebra_mask_expected

index 0efe61ccf2547a964b59a18de6db93d8516f26f8..8f00cfd5a31ea37c8cda279a395c2932c524395e 100644 (file)
@@ -1348,7 +1348,7 @@ rt_raster_iterator(
 
                                /* convert set of rt_pixel to 2D array */
                                status = rt_pixel_set_to_array(
-                                       npixels, status,mask,
+                                       npixels, status, mask,
                                        x, y,
                                        distancex, distancey,
                                        &(_param->arg->values[i]),
index 099e9098b64cb9663039c0bdceca3a10b5f412db..00f6263bbedf16ca096c76913c91ea62e897bedb 100644 (file)
@@ -310,18 +310,19 @@ rt_errorstate rt_pixel_set_to_array(
        RASTER_DEBUGF(4, "dimensions = %d x %d", dim[0], dim[1]);
 
        /* make sure that the dimx and dimy match mask */
-       ifmask != NULL) {
-         if ( dim[0] != mask->dimx || dim[1] != mask->dimy ){
+       if (mask != NULL) {
+         if (dim[0] != mask->dimx || dim[1] != mask->dimy) {
            rterror("rt_pixel_set_array: mask dimensions %d x %d do not match given dims %d x %d", mask->dimx, mask->dimy,  dim[0],  dim[1]);
            return ES_ERROR;
          }
          
-         if ( mask->values == NULL || mask->nodata == NULL ) {
-           rterror("rt_pixel_set_array: was not properly setup");
+         if (mask->values == NULL || mask->nodata == NULL) {
+           rterror("rt_pixel_set_array: Invalid mask");
            return ES_ERROR;
          }
 
        }
+
        /* establish 2D arrays (Y axis) */
        values = rtalloc(sizeof(double *) * dim[1]);
        nodatas = rtalloc(sizeof(int *) * dim[1]);
@@ -382,27 +383,39 @@ rt_errorstate rt_pixel_set_to_array(
                RASTER_DEBUGF(4, "absolute x,y: %d x %d", npixel[i].x, npixel[i].y);
                RASTER_DEBUGF(4, "relative x,y: %d x %d", _x, _y);
 
-               if ( mask == NULL ) {
-                 values[_y][_x] = npixel[i].value;
-                 nodatas[_y][_x] = 0;
-               }else{ 
-                 if( mask->weighted == 0 ){
-                   if( FLT_EQ( mask->values[_y][_x],0) || mask->nodata[_y][_x] == 1 ){
-                     values[_y][_x] = 0;
-                     nodatas[_y][_x] = 1;
-                   }else{
-                     values[_y][_x] = npixel[i].value;
-                     nodatas[_y][_x] = 0;
-                   }
-                 }else{
-                   if( mask->nodata[_y][_x] == 1 ){
-                     values[_y][_x] = 0;
-                     nodatas[_y][_x] = 1;
-                   }else{
-                     values[_y][_x] = npixel[i].value * mask->values[_y][_x];
-                     nodatas[_y][_x] = 0;
-                   }
-                 }
+               /* no mask */
+               if (mask == NULL) {
+                       values[_y][_x] = npixel[i].value;
+                       nodatas[_y][_x] = 0;
+               }
+               /* mask */
+               else { 
+                       /* unweighted (boolean) mask */
+                       if (mask->weighted == 0) {
+                               /* pixel is set to zero or nodata */
+                               if (FLT_EQ(mask->values[_y][_x],0) || mask->nodata[_y][_x] == 1) {
+                                       values[_y][_x] = 0;
+                                       nodatas[_y][_x] = 1;
+                               }
+                               /* use pixel */
+                               else {
+                                       values[_y][_x] = npixel[i].value;
+                                       nodatas[_y][_x] = 0;
+                               }
+                       }
+                       /* weighted mask */
+                       else {
+                               /* nodata */
+                               if(mask->nodata[_y][_x] == 1) {
+                                       values[_y][_x] = 0;
+                                       nodatas[_y][_x] = 1;
+                               }
+                               /* apply weight to pixel value */
+                               else {
+                                       values[_y][_x] = npixel[i].value * mask->values[_y][_x];
+                                       nodatas[_y][_x] = 0;
+                               }
+                       }
                }
 
                RASTER_DEBUGF(4, "(x, y, nodata, value) = (%d, %d, %d, %f)", _x, _y, nodatas[_y][_x], values[_y][_x]);
index 4908e94cc020ae44c31faad98ae34e194af5d45c..867165b4dbee7f521d2bc64e57d02c0fcad3ab27 100644 (file)
@@ -634,112 +634,115 @@ Datum RASTER_nMapAlgebra(PG_FUNCTION_ARGS)
                }
        }
 
-       noerr = 1;
-       
        /* mask (7) */
 
        if( PG_ARGISNULL(7) ){
-         pfree(arg->mask);
-         arg->mask = NULL;
-       }else{
-       maskArray = PG_GETARG_ARRAYTYPE_P(7);
-       etype = ARR_ELEMTYPE(maskArray);
-       get_typlenbyvalalign(etype,&typlen,&typbyval,&typalign);
-       
-       switch(etype){
-             case FLOAT4OID:
-             case FLOAT8OID:
-               break;
-             default:
-               rtpg_nmapalgebra_arg_destroy(arg);
-               elog(ERROR,"RASTER_nMapAlgebra: Mask data type must be FLOAT8 or FLOAT4.");
-               PG_RETURN_NULL();
+               pfree(arg->mask);
+               arg->mask = NULL;
        }
+       else {
+               maskArray = PG_GETARG_ARRAYTYPE_P(7);
+               etype = ARR_ELEMTYPE(maskArray);
+               get_typlenbyvalalign(etype,&typlen,&typbyval,&typalign);
 
-       ndims = ARR_NDIM(maskArray);
+               switch (etype) {
+                       case FLOAT4OID:
+                       case FLOAT8OID:
+                               break;
+                       default:
+                               rtpg_nmapalgebra_arg_destroy(arg);
+                               elog(ERROR,"RASTER_nMapAlgebra: Mask data type must be FLOAT8 or FLOAT4");
+                               PG_RETURN_NULL();
+               }
+
+               ndims = ARR_NDIM(maskArray);
+
+               if (ndims != 2) { 
+                       elog(ERROR, "RASTER_nMapAlgebra: Mask Must be a 2D array");
+                       rtpg_nmapalgebra_arg_destroy(arg);
+                       PG_RETURN_NULL();
+               }
        
-       if( ndims != 2 ){ 
-         elog(ERROR, "RASTER_nMapAlgebra: Mask Must be a 2D array.");
-         rtpg_nmapalgebra_arg_destroy(arg);
-         PG_RETURN_NULL();
-       }
+               maskDims = ARR_DIMS(maskArray);
+
+               if (maskDims[0] % 2 == 0 || maskDims[1] % 2 == 0) {
+                       elog(ERROR,"RASTER_nMapAlgebra: Mask dimensions must be odd");
+                       rtpg_nmapalgebra_arg_destroy(arg);
+                       PG_RETURN_NULL();
+               } 
        
-       maskDims = ARR_DIMS(maskArray);
+               deconstruct_array(
+                       maskArray,
+                       etype,
+                       typlen, typbyval,typalign,
+                       &maskElements,&maskNulls,&num
+               );
 
+               if (num < 1 || num != (maskDims[0] * maskDims[1])) {
+                       if (num) {
+                               pfree(maskElements);
+                               pfree(maskNulls);
+                       }
+                       elog(ERROR, "RASTER_nMapAlgebra: Could not deconstruct new values array");
+                       rtpg_nmapalgebra_arg_destroy(arg);
+                       PG_RETURN_NULL();
+               }
 
-       if ( maskDims[0] % 2 == 0 || maskDims[1] % 2 == 0 ){
-         elog(ERROR,"RASTER_nMapAlgebra: Mask dimensions must be odd.");
-         rtpg_nmapalgebra_arg_destroy(arg);
-         PG_RETURN_NULL();
-       } 
-       
-       deconstruct_array(
-                         maskArray,
-                         etype,
-                         typlen, typbyval,typalign,
-                         &maskElements,&maskNulls,&num
-                         );
-
-       if (num < 1 || num != (maskDims[0] * maskDims[1])) {
-                if (num) {
-                        pfree(maskElements);
-                        pfree(maskNulls);
-                }
-               elog(ERROR, "RASTER_nMapAlgebra: Could not deconstruct new values array.");
-                rtpg_nmapalgebra_arg_destroy(arg);
-               PG_RETURN_NULL();
-       }
+               /* allocate mem for mask array */
+               arg->mask->values = palloc(sizeof(double*)* maskDims[0]);
+               arg->mask->nodata =  palloc(sizeof(int*)*maskDims[0]);
+               for (i = 0; i < maskDims[0]; i++) {
+                       arg->mask->values[i] = (double*) palloc(sizeof(double) * maskDims[1]);
+                       arg->mask->nodata[i] = (int*) palloc(sizeof(int) * maskDims[1]);
+               }
 
+               /* place values in to mask */
+               i = 0;
+               for (y = 0; y < maskDims[0]; y++) {
+                       for (x = 0; x < maskDims[1]; x++) {
+                               if (maskNulls[i]) {
+                                       arg->mask->values[y][x] = 0;
+                                       arg->mask->nodata[y][x] = 1;
+                               }
+                               else {
+                                       switch (etype) {
+                                               case FLOAT4OID:
+                                                       arg->mask->values[y][x] = (double) DatumGetFloat4(maskElements[i]);
+                                                       arg->mask->nodata[y][x] = 0;
+                                                       break;
+                                               case FLOAT8OID:
+                                                       arg->mask->values[y][x] = (double) DatumGetFloat8(maskElements[i]);
+                                                       arg->mask->nodata[y][x] = 0;
+                                       }
+                               }
+                               i++;
+                       }
+               }
 
-       /* allocate mem for mask array */
-       arg->mask->values = palloc(sizeof(double*)* maskDims[0]);
-       arg->mask->nodata =  palloc(sizeof(int*)*maskDims[0]);
-       for(i = 0; i < maskDims[0]; i++){
-         arg->mask->values[i] = (double*) palloc(sizeof(double) * maskDims[1]);
-         arg->mask->nodata[i] = (int*) palloc(sizeof(int) * maskDims[1]);
-       }
-       /* place values in to mask */
-       i = 0;
-       for( y = 0; y < maskDims[0]; y++ ){
-         for( x = 0; x < maskDims[1]; x++){
-           if(maskNulls[i]){
-             arg->mask->values[y][x] = 0;
-             arg->mask->nodata[y][x] = 1;
-           }else{
-             switch(etype){
-             case FLOAT4OID:
-               arg->mask->values[y][x] = (double) DatumGetFloat4(maskElements[i]);
-               arg->mask->nodata[y][x] = 0;
-               break;
-             case FLOAT8OID:
-               arg->mask->values[y][x] = (double) DatumGetFloat8(maskElements[i]);
-               arg->mask->nodata[y][x] = 0;
-             }
-           }
-           i++;
-         }
-       }
-       /*set mask dimensions*/ 
-       arg->mask->dimx = maskDims[0];
-       arg->mask->dimy = maskDims[1];
-       if ( maskDims[0] == 1 && maskDims[1] == 1){
-         arg->distance[0] = 0;
-         arg->distance[1] = 0;
-       }else{
-         arg->distance[0] = maskDims[0] % 2;
-         arg->distance[1] = maskDims[1] % 2;
-       }
+               /*set mask dimensions*/ 
+               arg->mask->dimx = maskDims[0];
+               arg->mask->dimy = maskDims[1];
+               if (maskDims[0] == 1 && maskDims[1] == 1) {
+                       arg->distance[0] = 0;
+                       arg->distance[1] = 0;
+               }
+               else {
+                       arg->distance[0] = maskDims[0] % 2;
+                       arg->distance[1] = maskDims[1] % 2;
+               }
        }/*end if else argisnull*/
 
        /* (8) weighted boolean */
-       if (PG_ARGISNULL(8) || !PG_GETARG_BOOL(8) ){
-         if ( arg->mask != NULL 
-           arg->mask->weighted = 0;
+       if (PG_ARGISNULL(8) || !PG_GETARG_BOOL(8){
+               if (arg->mask != NULL
+                       arg->mask->weighted = 0;
        }else{
-         if(arg->mask !=NULL )
-           arg->mask->weighted = 1;
+               if(arg->mask !=NULL)
+                       arg->mask->weighted = 1;
        }
 
+       noerr = 1;
+       
        /* all rasters are empty, return empty raster */
        if (allempty == arg->numraster) {
                elog(NOTICE, "All input rasters are empty. Returning empty raster");
index 68a9a60657c4713d8cf3bbb5b95d4fc08706ed67..a70a1b86d25a2860c76f13a8eca11f133dd7eacf 100644 (file)
@@ -1,12 +1,12 @@
 NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
 NOTICE:  All input rasters are NULL. Returning NULL
-ERROR:  RASTER_nMapAlgebra: Mask dimensions must be odd.
+ERROR:  RASTER_nMapAlgebra: Mask dimensions must be odd
 NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
 NOTICE:  All input rasters are NULL. Returning NULL
-ERROR:  RASTER_nMapAlgebra: Mask dimensions must be odd.
+ERROR:  RASTER_nMapAlgebra: Mask dimensions must be odd
 NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
 NOTICE:  All input rasters are NULL. Returning NULL
-ERROR:  RASTER_nMapAlgebra: Mask dimensions must be odd.
+ERROR:  RASTER_nMapAlgebra: Mask dimensions must be odd
 NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
 NOTICE:  All input rasters are NULL. Returning NULL
 NOTICE:  All input rasters do not have bands at indicated indexes. Returning empty raster
@@ -52,10 +52,10 @@ NOTICE:  userargs = <NULL>
 4|(1,"{{255,255},{255,255}}")
 NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
 NOTICE:  All input rasters are NULL. Returning NULL
-ERROR:  RASTER_nMapAlgebra: Mask Must be a 2D array.
+ERROR:  RASTER_nMapAlgebra: Mask Must be a 2D array
 NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
 NOTICE:  All input rasters are NULL. Returning NULL
-ERROR:  RASTER_nMapAlgebra: Mask Must be a 2D array.
+ERROR:  RASTER_nMapAlgebra: Mask Must be a 2D array
 NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
 NOTICE:  All input rasters are NULL. Returning NULL
 NOTICE:  All input rasters do not have bands at indicated indexes. Returning empty raster
@@ -230,10 +230,10 @@ NOTICE:  userargs = <NULL>
 4|(1,"{{255,255},{255,255}}")
 NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
 NOTICE:  All input rasters are NULL. Returning NULL
-ERROR:  RASTER_nMapAlgebra: Mask dimensions must be odd.
+ERROR:  RASTER_nMapAlgebra: Mask dimensions must be odd
 NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
 NOTICE:  All input rasters are NULL. Returning NULL
-ERROR:  RASTER_nMapAlgebra: Mask dimensions must be odd.
+ERROR:  RASTER_nMapAlgebra: Mask dimensions must be odd
 NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
 NOTICE:  All input rasters are NULL. Returning NULL
 NOTICE:  All input rasters do not have bands at indicated indexes. Returning empty raster
@@ -279,10 +279,10 @@ NOTICE:  userargs = <NULL>
 4|(1,"{{255,255},{255,255}}")
 NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
 NOTICE:  All input rasters are NULL. Returning NULL
-ERROR:  RASTER_nMapAlgebra: Mask Must be a 2D array.
+ERROR:  RASTER_nMapAlgebra: Mask Must be a 2D array
 NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
 NOTICE:  All input rasters are NULL. Returning NULL
-ERROR:  RASTER_nMapAlgebra: Mask Must be a 2D array.
+ERROR:  RASTER_nMapAlgebra: Mask Must be a 2D array
 NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
 NOTICE:  All input rasters are NULL. Returning NULL
 NOTICE:  All input rasters do not have bands at indicated indexes. Returning empty raster
@@ -457,13 +457,13 @@ NOTICE:  userargs = <NULL>
 4|(1,"{{255,255},{255,255}}")
 NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
 NOTICE:  All input rasters are NULL. Returning NULL
-ERROR:  RASTER_nMapAlgebra: Mask dimensions must be odd.
+ERROR:  RASTER_nMapAlgebra: Mask dimensions must be odd
 NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
 NOTICE:  All input rasters are NULL. Returning NULL
-ERROR:  RASTER_nMapAlgebra: Mask dimensions must be odd.
+ERROR:  RASTER_nMapAlgebra: Mask dimensions must be odd
 NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
 NOTICE:  All input rasters are NULL. Returning NULL
-ERROR:  RASTER_nMapAlgebra: Mask Must be a 2D array.
+ERROR:  RASTER_nMapAlgebra: Mask Must be a 2D array
 NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
 NOTICE:  All input rasters are NULL. Returning NULL
 NOTICE:  All input rasters do not have bands at indicated indexes. Returning empty raster