]> granicus.if.org Git - postgis/commitdiff
Changed output array of ST_Neighborhood to have dimensions of Y,X
authorBborie Park <bkpark at ucdavis.edu>
Mon, 24 Sep 2012 15:07:58 +0000 (15:07 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Mon, 24 Sep 2012 15:07:58 +0000 (15:07 +0000)
instead of X,Y. This matches that found for GDAL blocks.

git-svn-id: http://svn.osgeo.org/postgis/trunk@10323 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/regress/rt_neighborhood_expected

index d07e3c7db665280de27f42355f9310767426d57e..b3e694eaf5507131e04203c14317085b2d70343b 100644 (file)
@@ -1151,7 +1151,9 @@ int rt_pixtype_compare_clamped_values(rt_pixtype pixtype, double val, double ref
 /*- rt_pixel ----------------------------------------------------------*/
 
 /*
- * Convert an array of rt_pixel objects to two 2D arrays of value and NODATA
+ * Convert an array of rt_pixel objects to two 2D arrays of value and NODATA.
+ * The dimensions of the returned 2D array are [Y][X], going by row Y and
+ * then column X.
  *
  * @param npixel: array of rt_pixel objects
  * @param count: number of elements in npixel
@@ -1193,19 +1195,19 @@ int rt_pixel_set_to_array(
        dim[1] = distancey * 2 + 1;
        RASTER_DEBUGF(4, "dimensions = %d x %d", dim[0], dim[1]);
 
-       /* establish 2D arrays (X axis) */
-       values = rtalloc(sizeof(double *) * dim[0]);
-       nodatas = rtalloc(sizeof(int *) * dim[0]);
+       /* establish 2D arrays (Y axis) */
+       values = rtalloc(sizeof(double *) * dim[1]);
+       nodatas = rtalloc(sizeof(int *) * dim[1]);
 
        if (values == NULL || nodatas == NULL) {
                rterror("rt_pixel_set_to_array: Unable to allocate memory for 2D array");
                return 0;
        }
 
-       /* initialize Y axis */
-       for (i = 0; i < dim[0]; i++) {
-               values[i] = rtalloc(sizeof(double) * dim[1]);
-               nodatas[i] = rtalloc(sizeof(int) * dim[1]);
+       /* initialize X axis */
+       for (i = 0; i < dim[1]; i++) {
+               values[i] = rtalloc(sizeof(double) * dim[0]);
+               nodatas[i] = rtalloc(sizeof(int) * dim[0]);
 
                if (values[i] == NULL || nodatas[i] == NULL) {
                        rterror("rt_pixel_set_to_array: Unable to allocate memory for dimension of 2D array");
@@ -1231,14 +1233,14 @@ int rt_pixel_set_to_array(
                }
 
                /* set values to 0 */
-               memset(values[i], 0, sizeof(double) * dim[1]);
+               memset(values[i], 0, sizeof(double) * dim[0]);
 
                /* set nodatas to 1 */
-               for (j = 0; j < dim[1]; j++)
+               for (j = 0; j < dim[0]; j++)
                        nodatas[i][j] = 1;
        }
 
-       /* get zero, zero of grid */
+       /* get 0,0 of grid */
        zero[0] = x - distancex;
        zero[1] = y - distancey;
 
@@ -1253,10 +1255,10 @@ int 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);
 
-               values[_x][_y] = npixel[i].value;
-               nodatas[_x][_y] = 0;
+               values[_y][_x] = npixel[i].value;
+               nodatas[_y][_x] = 0;
 
-               RASTER_DEBUGF(4, "(x, y, nodata, value) = (%d, %d, %d, %f)", _x, _y, nodatas[_x][_y], values[_x][_y]);
+               RASTER_DEBUGF(4, "(x, y, nodata, value) = (%d, %d, %d, %f)", _x, _y, nodatas[_y][_x], values[_y][_x]);
        }
 
        *value = &(*values);
index 9911278b21b2358d32621a1ab1ab8fedcdcfb95b..1f0cfd5e5a4e5c112aee90b6ea91acbdc480cd03 100644 (file)
@@ -339,7 +339,9 @@ int rt_pixtype_compare_clamped_values(rt_pixtype pixtype, double val, double ref
 /*- rt_pixel ----------------------------------------------------------*/
 
 /*
- * Convert an array of rt_pixel objects to two 2D arrays of value and NODATA
+ * Convert an array of rt_pixel objects to two 2D arrays of value and NODATA.
+ * The dimensions of the returned 2D array are [Y][X], going by row Y and
+ * then column X.
  *
  * @param npixel: array of rt_pixel objects
  * @param count: number of elements in npixel
index 1e92c9d80c734db8a375d413099089c4313bc04c..558f06126c2386d2d396ffbf615ffdaba44510f2 100644 (file)
@@ -3966,8 +3966,10 @@ Datum RASTER_neighborhood(PG_FUNCTION_ARGS)
 
        /* copy values from 2D arrays to 1D arrays */
        k = 0;
-       for (i = 0; i < dim[0]; i++) {
-               for (j = 0; j < dim[1]; j++) {
+       /* Y-axis */
+       for (i = 0; i < dim[1]; i++) {
+               /* X-axis */
+               for (j = 0; j < dim[0]; j++) {
                        nodata1D[k] = (bool) nodata2D[i][j];
                        if (!nodata1D[k])
                                value1D[k] = Float8GetDatum(value2D[i][j]);
@@ -3979,7 +3981,7 @@ Datum RASTER_neighborhood(PG_FUNCTION_ARGS)
        }
 
        /* no more need for 2D arrays */
-       for (i = 0; i < dim[0]; i++) {
+       for (i = 0; i < dim[1]; i++) {
                pfree(value2D[i]);
                pfree(nodata2D[i]);
        }
index 61dc6fe4a0d9e9874544187706fc109ecd4e1140..a45cdbd3b60cf041de9e4d30f65253bc683a98bf 100644 (file)
@@ -1,15 +1,15 @@
 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}}
+{{NULL,1,1},{1,1,1},{1,NULL,1}}
+{{1,1,1},{1,1,NULL},{1,1,1}}
+{{1,1,NULL,1,1},{1,1,1,1,1},{NULL,1,1,NULL,1},{1,1,1,1,1},{1,NULL,1,1,NULL}}
 {{1,NULL,NULL},{NULL,NULL,NULL},{NULL,NULL,NULL}}
 NOTICE:  Pixel has no neighbors for band at distance 1 x 1
 NOTICE:  Pixel has no neighbors for band at distance 1 x 1
-{{NULL,NULL,NULL},{NULL,NULL,NULL},{NULL,1,1}}
+{{NULL,NULL,NULL},{NULL,NULL,1},{NULL,NULL,1}}
 NOTICE:  Pixel has no neighbors for band at distance 1 x 1
 NOTICE:  Pixel has no neighbors for band at distance 3 x 3
 {{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0}}
 {{1,1,NULL},{1,1,1},{NULL,1,1}}
-{{1,1,1,NULL,1},{1,1,1,1,1},{1,NULL,1,1,1}}
+{{1,1,1,1,1},{NULL,1,1,1,NULL},{1,1,1,1,1}}