]> granicus.if.org Git - postgis/commitdiff
Fixed ST_AsRaster to duplicate exactly the attributes of a reference raster.
authorBborie Park <bkpark at ucdavis.edu>
Wed, 30 Nov 2011 20:35:57 +0000 (20:35 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Wed, 30 Nov 2011 20:35:57 +0000 (20:35 +0000)
Associated ticket is #1336.

git-svn-id: http://svn.osgeo.org/postgis/trunk@8263 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_api.c
raster/rt_pg/rt_pg.c
raster/test/core/testapi.c
raster/test/regress/rt_asraster.sql

index 3451b9ad4e18cc44a3a81d80668667b0dc6c9b3b..767ffc2b9996c367a7f0625ba8c4b9e1c5f67552 100644 (file)
@@ -8000,6 +8000,23 @@ rt_raster_gdal_rasterize(const unsigned char *wkb,
        dst_gt[4] = _skew_y;
        dst_gt[5] = -1 * _scale_y;
 
+       /* user provided negative scale-x */
+       if (
+               (NULL != scale_x) &&
+               (*scale_x < 0.)
+       ) {
+               dst_gt[0] = src_env.MaxX;
+               dst_gt[1] = *scale_x;
+       }
+       /* user provided positive scale-y */
+       if (
+               (NULL != scale_y) &&
+               (*scale_y > 0)
+       ) {
+               dst_gt[3] = src_env.MinY;
+               dst_gt[5] = *scale_y;
+       }
+
        RASTER_DEBUGF(3, "Applied extent: %f, %f, %f, %f",
                src_env.MinX, src_env.MaxY, src_env.MaxX, src_env.MinY);
        RASTER_DEBUGF(3, "Applied geotransform: %f, %f, %f, %f, %f, %f",
@@ -8934,11 +8951,11 @@ rt_raster_same_alignment(
                err = 1;
        }
        /* scales must match */
-       else if (FLT_NEQ(rast1->scaleX, rast2->scaleX)) {
+       else if (FLT_NEQ(fabs(rast1->scaleX), fabs(rast2->scaleX))) {
                RASTER_DEBUG(3, "The two raster provided have different scales on the X axis");
                err = 1;
        }
-       else if (FLT_NEQ(rast1->scaleY, rast2->scaleY)) {
+       else if (FLT_NEQ(fabs(rast1->scaleY), fabs(rast2->scaleY))) {
                RASTER_DEBUG(3, "The two raster provided have different scales on the Y axis");
                err = 1;
        }
index 1f8452704aa5d93a626b54ea1486b773c09de6b2..e6b32d6118c0de77e1f0465cee82b74377f9d187 100644 (file)
@@ -485,13 +485,13 @@ rtpg_getSRTextSPI(int srid)
        len = sizeof(char) * (strlen("SELECT srtext FROM spatial_ref_sys WHERE srid =  LIMIT 1") + MAX_INT_CHARLEN + 1);
        sql = (char *) palloc(len);
        if (NULL == sql) {
-               elog(ERROR, "getSrtextSPI: Unable to allocate memory for sql\n");
+               elog(ERROR, "rtpg_getSRTextSPI: Unable to allocate memory for sql\n");
                return NULL;
        }
 
        spi_result = SPI_connect();
        if (spi_result != SPI_OK_CONNECT) {
-               elog(ERROR, "getSrtextSPI: Could not connect to database using SPI\n");
+               elog(ERROR, "rtpg_getSRTextSPI: Could not connect to database using SPI\n");
                pfree(sql);
                return NULL;
        }
@@ -501,7 +501,7 @@ rtpg_getSRTextSPI(int srid)
        spi_result = SPI_execute(sql, TRUE, 0);
        pfree(sql);
        if (spi_result != SPI_OK_SELECT || SPI_tuptable == NULL || SPI_processed != 1) {
-               elog(ERROR, "getSrtextSPI: Cannot find SRID (%d) in spatial_ref_sys", srid);
+               elog(ERROR, "rtpg_getSRTextSPI: Cannot find SRID (%d) in spatial_ref_sys", srid);
                if (SPI_tuptable) SPI_freetuptable(tuptable);
                SPI_finish();
                return NULL;
@@ -513,7 +513,7 @@ rtpg_getSRTextSPI(int srid)
 
        tmp = SPI_getvalue(tuple, tupdesc, 1);
        if (NULL == tmp || !strlen(tmp)) {
-               elog(ERROR, "getSrtextSPI: Cannot find SRID (%d) in spatial_ref_sys", srid);
+               elog(ERROR, "rtpg_getSRTextSPI: Cannot find SRID (%d) in spatial_ref_sys", srid);
                if (SPI_tuptable) SPI_freetuptable(tuptable);
                SPI_finish();
                return NULL;
@@ -525,7 +525,7 @@ rtpg_getSRTextSPI(int srid)
        len = strlen(tmp);
        srs = (char *) palloc(sizeof(char) * (len + 1));
        if (NULL == srs) {
-               elog(ERROR, "getSrtextSPI: Unable to allocate memory for srtext\n");
+               elog(ERROR, "rtpg_getSRTextSPI: Unable to allocate memory for srtext\n");
                return NULL;
        }
        srs = strncpy(srs, tmp, len + 1);
@@ -4011,7 +4011,7 @@ Datum RASTER_histogram(PG_FUNCTION_ARGS)
                                default:
                                        elog(ERROR, "RASTER_histogram: Invalid data type for width");
                                        rt_raster_destroy(raster);
-                                       PG_RETURN_NULL();
+                                       SRF_RETURN_DONE(funcctx);
                                        break;
                        }
 
@@ -4256,7 +4256,7 @@ Datum RASTER_histogramCoverage(PG_FUNCTION_ARGS)
                /* column name is null, return null */
                if (PG_ARGISNULL(1)) {
                        elog(NOTICE, "Column name must be provided");
-                       PG_RETURN_NULL();
+                       SRF_RETURN_DONE(funcctx);
                }
                colnametext = PG_GETARG_TEXT_P(1);
                colname = text_to_cstring(colnametext);
@@ -4787,7 +4787,7 @@ Datum RASTER_quantile(PG_FUNCTION_ARGS)
                                default:
                                        elog(ERROR, "RASTER_quantile: Invalid data type for quantiles");
                                        rt_raster_destroy(raster);
-                                       PG_RETURN_NULL();
+                                       SRF_RETURN_DONE(funcctx);
                                        break;
                        }
 
@@ -5016,7 +5016,7 @@ Datum RASTER_quantileCoverage(PG_FUNCTION_ARGS)
                /* column name is null, return null */
                if (PG_ARGISNULL(1)) {
                        elog(NOTICE, "Column name must be provided");
-                       PG_RETURN_NULL();
+                       SRF_RETURN_DONE(funcctx);
                }
                colnametext = PG_GETARG_TEXT_P(1);
                colname = text_to_cstring(colnametext);
@@ -5060,7 +5060,7 @@ Datum RASTER_quantileCoverage(PG_FUNCTION_ARGS)
                                default:
                                        elog(ERROR, "RASTER_quantileCoverage: Invalid data type for quantiles");
                                        rt_raster_destroy(raster);
-                                       PG_RETURN_NULL();
+                                       SRF_RETURN_DONE(funcctx);
                                        break;
                        }
 
@@ -5407,7 +5407,7 @@ Datum RASTER_valueCount(PG_FUNCTION_ARGS) {
                raster = rt_raster_deserialize(pgraster, FALSE);
                if (!raster) {
                        elog(ERROR, "RASTER_valueCount: Could not deserialize raster");
-                       PG_RETURN_NULL();
+                       SRF_RETURN_DONE(funcctx);
                }
 
                /* band index is 1-based */
@@ -5437,7 +5437,7 @@ Datum RASTER_valueCount(PG_FUNCTION_ARGS) {
                                default:
                                        elog(ERROR, "RASTER_valueCount: Invalid data type for values");
                                        rt_raster_destroy(raster);
-                                       PG_RETURN_NULL();
+                                       SRF_RETURN_DONE(funcctx);
                                        break;
                        }
 
@@ -5646,7 +5646,7 @@ Datum RASTER_valueCountCoverage(PG_FUNCTION_ARGS) {
                /* column name is null, return null */
                if (PG_ARGISNULL(1)) {
                        elog(NOTICE, "Column name must be provided");
-                       PG_RETURN_NULL();
+                       SRF_RETURN_DONE(funcctx);
                }
                colnametext = PG_GETARG_TEXT_P(1);
                colname = text_to_cstring(colnametext);
@@ -5677,7 +5677,7 @@ Datum RASTER_valueCountCoverage(PG_FUNCTION_ARGS) {
                                default:
                                        elog(ERROR, "RASTER_valueCountCoverage: Invalid data type for values");
                                        rt_raster_destroy(raster);
-                                       PG_RETURN_NULL();
+                                       SRF_RETURN_DONE(funcctx);
                                        break;
                        }
 
index b704aeb35a0f84dc914bdc8cbbbbf2b9011d8bdb..508f6ec7e682575d930c90381b849f57a2681524 100644 (file)
@@ -1554,7 +1554,7 @@ static void testGDALRasterize() {
        int wkb_len = 0;
        int i;
        double scale_x = 100;
-       double scale_y = 100;
+       double scale_y = -100;
 
        rt_pixtype pixtype[] = {PT_8BUI};
        double init[] = {0};
index d2eef29d7faa425dfa6d1acb8ef0d4142ae416a5..2d610750437f3bf00b444f1b3bcc845060bbcb3f 100644 (file)
@@ -63,7 +63,7 @@ INSERT INTO raster_asraster_dst (rid, rast) VALUES (
 ), (
        1.2, (SELECT ST_AsRaster(
                geom,
-               100., 100.
+               100., -100.
        ) FROM raster_asraster_geom)
 ), (
        1.3, (SELECT ST_AsRaster(
@@ -73,42 +73,42 @@ INSERT INTO raster_asraster_dst (rid, rast) VALUES (
 ), (
        1.4, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.
+               1000., -1000.
        ) FROM raster_asraster_geom)
 ), (
        1.5, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.,
+               1000., -1000.,
                '8BSI'
        ) FROM raster_asraster_geom)
 ), (
        1.6, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.,
+               1000., -1000.,
                '16BUI'
        ) FROM raster_asraster_geom)
 ), (
        1.7, (SELECT ST_AsRaster(
                geom,
-               100., 100.,
+               100., -100.,
                '32BF'
        ) FROM raster_asraster_geom)
 ), (
        1.8, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.,
+               1000., -1000.,
                ARRAY['8BSI']
        ) FROM raster_asraster_geom)
 ), (
        1.9, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.,
+               1000., -1000.,
                ARRAY['16BUI']
        ) FROM raster_asraster_geom)
 ), (
        1.10, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.,
+               1000., -1000.,
                ARRAY['32BF']
        ) FROM raster_asraster_geom)
 ), (
@@ -157,7 +157,7 @@ INSERT INTO raster_asraster_dst (rid, rast) VALUES (
 ), (
        1.17, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.,
+               1000., -1000.,
                ARRAY['32BF', '16BUI'],
                ARRAY[255, 1],
                ARRAY[NULL, 0]::double precision[]
@@ -173,7 +173,7 @@ INSERT INTO raster_asraster_dst (rid, rast) VALUES (
 ), (
        1.19, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.,
+               1000., -1000.,
                ARRAY['32BF', '16BUI', '64BF'],
                ARRAY[255, 1, -1],
                ARRAY[NULL, 0, NULL]::double precision[]
@@ -181,7 +181,7 @@ INSERT INTO raster_asraster_dst (rid, rast) VALUES (
 ), (
        1.20, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.,
+               1000., -1000.,
                ARRAY['1BB', '2BUI'],
                ARRAY[1, 1],
                ARRAY[1, 0]::double precision[]
@@ -192,7 +192,7 @@ INSERT INTO raster_asraster_dst (rid, rast) VALUES (
 INSERT INTO raster_asraster_dst (rid, rast) VALUES (
        2.1, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.,
+               1000., -1000.,
                '8BUI',
                255,
                0,
@@ -201,7 +201,7 @@ INSERT INTO raster_asraster_dst (rid, rast) VALUES (
 ), (
        2.2, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.,
+               1000., -1000.,
                '8BUI',
                255,
                0,
@@ -210,7 +210,7 @@ INSERT INTO raster_asraster_dst (rid, rast) VALUES (
 ), (
        2.3, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.,
+               1000., -1000.,
                '8BUI',
                255,
                0,
@@ -219,7 +219,7 @@ INSERT INTO raster_asraster_dst (rid, rast) VALUES (
 ), (
        2.4, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.,
+               1000., -1000.,
                '8BUI',
                255,
                0,
@@ -228,7 +228,7 @@ INSERT INTO raster_asraster_dst (rid, rast) VALUES (
 ), (
        2.5, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.,
+               1000., -1000.,
                '8BUI',
                255,
                0,
@@ -391,7 +391,7 @@ INSERT INTO raster_asraster_dst (rid, rast) VALUES (
 ), (
        4.8, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.,
+               1000., -1000.,
                0, 0,
                ARRAY['16BUI'],
                ARRAY[13],
@@ -401,7 +401,7 @@ INSERT INTO raster_asraster_dst (rid, rast) VALUES (
 ), (
        4.9, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.,
+               1000., -1000.,
                -175453, 114987,
                ARRAY['16BUI'],
                ARRAY[13],
@@ -411,7 +411,7 @@ INSERT INTO raster_asraster_dst (rid, rast) VALUES (
 ), (
        4.10, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.,
+               1000., -1000.,
                -100, 100,
                ARRAY['16BUI'],
                ARRAY[13],
@@ -421,7 +421,7 @@ INSERT INTO raster_asraster_dst (rid, rast) VALUES (
 ), (
        4.11, (SELECT ST_AsRaster(
                geom,
-               1000., 1000.,
+               1000., -1000.,
                -100, 100,
                '16BUI',
                13,