From: Bborie Park Date: Thu, 23 Feb 2012 22:25:54 +0000 (+0000) Subject: Added correct handling of negative scale-x and positive scale-y in rt_raster_gdal_warp(). X-Git-Tag: 2.0.0beta1~75 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5bb4a73a5f1fb4f2bbb366aa7a383cb7a6620e7c;p=postgis Added correct handling of negative scale-x and positive scale-y in rt_raster_gdal_warp(). git-svn-id: http://svn.osgeo.org/postgis/trunk@9281 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index 87c6bfc92..d1e32dad2 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -5221,10 +5221,13 @@ rt_raster_gdal_polygonize( /* for checking that a geometry is valid */ GEOSGeom ggeom = NULL; - int msgValid = 0; int isValid; LWGEOM *lwgeomValid = NULL; +#if POSTGIS_GEOS_VERSION < 33 + int msgValid = 0; +#endif + uint32_t bandNums[1] = {nband}; /* checks */ @@ -8303,6 +8306,84 @@ rt_raster rt_raster_gdal_warp( _gt[4] = _skew[1]; _gt[5] = -1 * _scale[1]; + /* scale-x is negative or scale-y is positive */ + if (( + (NULL != scale_x) && (*scale_x < 0.) + ) || ( + (NULL != scale_y) && (*scale_y > 0) + )) { + double _w[2] = {0}; + + rast = rt_raster_new(1, 1); + if (rast == NULL) { + rterror("rt_raster_gdal_warp: Out of memory allocating temporary raster"); + + GDALClose(src_ds); + + for (i = 0; i < transform_opts_len; i++) rtdealloc(transform_opts[i]); + rtdealloc(transform_opts); + + return NULL; + } + rt_raster_set_geotransform_matrix(rast, _gt); + + /* negative scale-x */ + if ( + (NULL != scale_x) && + (*scale_x < 0.) + ) { + if (!rt_raster_cell_to_geopoint( + rast, + _dim[0], 0, + &(_w[0]), &(_w[1]), + NULL + )) { + rterror("rt_raster_gdal_warp: Unable to compute spatial coordinates for raster pixel"); + + rt_raster_destroy(rast); + + GDALClose(src_ds); + + for (i = 0; i < transform_opts_len; i++) rtdealloc(transform_opts[i]); + rtdealloc(transform_opts); + + return NULL; + } + + _gt[0] = _w[0]; + _gt[1] = *scale_x; + } + /* positive scale-y */ + if ( + (NULL != scale_y) && + (*scale_y > 0) + ) { + if (!rt_raster_cell_to_geopoint( + rast, + 0, _dim[1], + &(_w[0]), &(_w[1]), + NULL + )) { + rterror("rt_raster_gdal_warp: Unable to compute spatial coordinates for raster pixel"); + + rt_raster_destroy(rast); + + GDALClose(src_ds); + + for (i = 0; i < transform_opts_len; i++) rtdealloc(transform_opts[i]); + rtdealloc(transform_opts); + + return NULL; + } + + _gt[3] = _w[1]; + _gt[5] = *scale_y; + } + + rt_raster_destroy(rast); + rast = NULL; + } + RASTER_DEBUGF(3, "Applied geotransform: %f, %f, %f, %f, %f, %f", _gt[0], _gt[1], _gt[2], _gt[3], _gt[4], _gt[5]); RASTER_DEBUGF(3, "Raster dimensions (width x height): %d x %d", diff --git a/raster/test/regress/rt_resample_expected b/raster/test/regress/rt_resample_expected index deddc4289..9c3c6fe5b 100644 --- a/raster/test/regress/rt_resample_expected +++ b/raster/test/regress/rt_resample_expected @@ -4,21 +4,21 @@ NOTICE: Values must be provided for both X and Y when specifying the scale. Re NOTICE: Values must be provided for both X and Y when specifying the scale. Returning original raster 1.0||||||||||||| 1.1|992163|10|10|1|1000.000|-1000.000|0.000|0.000|-500000.000|600000.000|t|t|t -1.10|992163|40|40|1|250.000|-250.000|0.000|0.000|-500000.000|600000.000|t|t|t +1.10|992163|40|40|1|250.000|250.000|0.000|0.000|-500000.000|590000.000|t|t|t 1.11|992163|10|10|1|1000.000|-1000.000|0.000|0.000|-500000.000|600000.000|t|t|t 1.12|992163|11|10|1|1000.000|-1000.000|0.000|0.000|-500001.000|600000.000|t|t|t 1.13|992163|10|11|1|1000.000|-1000.000|0.000|0.000|-500000.000|600009.000|t|t|t 1.14|992163|11|11|1|1000.000|-1000.000|0.000|0.000|-500100.000|600950.000|t|t|t -1.15|992163|201|201|1|50.000|-50.000|0.000|0.000|-500040.000|600007.000|t|t|t -1.16|992163|84|83|1|121.000|-121.000|0.000|0.000|-500093.000|600039.000|t|t|t -1.17|993310|243|243|1|50.000|-50.000|0.000|0.000|950710.000|1409307.000|t|t|t -1.18|993309|243|243|1|50.000|-50.000|0.000|0.000|950760.000|1409107.000|t|t|t +1.15|992163|201|201|1|50.000|50.000|0.000|0.000|-500040.000|589957.000|t|t|t +1.16|992163|84|83|1|121.000|121.000|0.000|0.000|-500093.000|589996.000|t|t|t +1.17|993310|243|243|1|50.000|50.000|0.000|0.000|950710.000|1397157.000|t|t|t +1.18|993309|243|243|1|50.000|50.000|0.000|0.000|950760.000|1396957.000|t|t|t 1.19|992163|10|10|1|1000.000|-1000.000|3.000|3.000|-500030.000|600000.000|t|t|t 1.2|993310|12|12|1|1009.894|-1009.894|0.000|0.000|950732.188|1409281.783|t|t|t 1.20|993310|12|12|1|1009.894|-1009.894|3.000|3.000|950691.792|1409281.783|t|t|t 1.21|993309|12|12|1|1009.916|-1009.916|1.000|3.000|950742.107|1409088.896|t|t|t -1.22|993310|24|24|1|500.000|-500.000|3.000|3.000|950657.188|1409281.783|t|t|t -1.23|993310|25|26|1|500.000|-500.000|0.000|6.000|950452.000|1409732.000|t|t|t +1.22|993310|24|24|1|500.000|500.000|3.000|3.000|950657.188|1397281.783|t|t|t +1.23|993310|25|26|1|500.000|500.000|0.000|6.000|950452.000|1396732.000|t|t|t 1.24|992163|207|101|1|50.000|-100.000|3.000|0.000|-500319.000|600056.000|t|t|t 1.25|992163|207|101|1|50.000|-100.000|3.000|0.000|-500319.000|600056.000|t|t|t 1.26|992163|150|150|1|66.667|-66.667|0.000|0.000|-500000.000|600000.000|t|t|t @@ -27,18 +27,18 @@ NOTICE: Values must be provided for both X and Y when specifying the scale. Re 1.29||||||||||||| 1.3|993309|12|12|1|1009.916|-1009.916|0.000|0.000|950762.305|1409088.896|t|t|t 1.4|994269|12|8|1|0.012|-0.012|0.000|0.000|-107.029|50.206|t|t|t -1.5|993310|24|24|1|500.000|-500.000|0.000|0.000|950732.188|1409281.783|t|t|t +1.5|993310|24|24|1|500.000|500.000|0.000|0.000|950732.188|1397281.783|t|t|t 1.6|992163|10|10|1|1000.000|-1000.000|0.000|0.000|-500000.000|600000.000|t|t|t 1.7|992163|10|10|1|1000.000|-1000.000|0.000|0.000|-500000.000|600000.000|t|t|t -1.8|992163|20|20|1|500.000|-500.000|0.000|0.000|-500000.000|600000.000|t|t|t -1.9|992163|40|40|1|250.000|-250.000|0.000|0.000|-500000.000|600000.000|t|t|t +1.8|992163|20|20|1|500.000|500.000|0.000|0.000|-500000.000|590000.000|t|t|t +1.9|992163|40|40|1|250.000|250.000|0.000|0.000|-500000.000|590000.000|t|t|t 2.1|993310|12|12|1|1009.894|-1009.894|0.000|0.000|950732.188|1409281.783|t|t|t -2.10|993310|24|24|1|500.000|-500.000|0.000|0.000|950732.188|1409281.783|t|t|t -2.11|993309|121|121|1|100.000|-100.000|0.000|0.000|950762.305|1409088.896|t|t|t -2.12|993310|6|6|1|2000.000|-2000.000|0.000|0.000|950732.188|1409281.783|t|t|t -2.13|993310|8|8|1|1500.000|-1500.000|0.000|0.000|950732.188|1409281.783|t|t|t -2.14|993310|24|24|1|500.000|-500.000|0.000|0.000|950732.188|1409281.783|t|t|t -2.15|993310|16|16|1|750.000|-750.000|0.000|0.000|950732.188|1409281.783|t|t|t +2.10|993310|24|24|1|500.000|500.000|0.000|0.000|950732.188|1397281.783|t|t|t +2.11|993309|121|121|1|100.000|100.000|0.000|0.000|950762.305|1396988.896|t|t|t +2.12|993310|6|6|1|2000.000|2000.000|0.000|0.000|950732.188|1397281.783|t|t|t +2.13|993310|8|8|1|1500.000|1500.000|0.000|0.000|950732.188|1397281.783|t|t|t +2.14|993310|24|24|1|500.000|500.000|0.000|0.000|950732.188|1397281.783|t|t|t +2.15|993310|16|16|1|750.000|750.000|0.000|0.000|950732.188|1397281.783|t|t|t 2.2|993309|12|12|1|1009.916|-1009.916|0.000|0.000|950762.305|1409088.896|t|t|t 2.3|994269|12|8|1|0.012|-0.012|0.000|0.000|-107.029|50.206|t|t|t 2.4||||||||||||| @@ -47,12 +47,12 @@ NOTICE: Values must be provided for both X and Y when specifying the scale. Re 2.7|993310|12|12|1|1009.894|-1009.894|0.000|0.000|950732.188|1409281.783|t|t|t 2.8|993310|12|12|1|1009.894|-1009.894|0.000|0.000|950732.188|1409281.783|t|t|t 2.9|993310|12|12|1|1009.894|-1009.894|0.000|0.000|950732.188|1409281.783|t|t|t -3.1|992163|100|100|1|100.000|-100.000|0.000|0.000|-500000.000|600000.000|t|t|t -3.2|992163|100|100|1|100.000|-100.000|0.000|0.000|-500000.000|600000.000|t|t|t +3.1|992163|100|100|1|100.000|100.000|0.000|0.000|-500000.000|590000.000|t|t|t +3.2|992163|100|100|1|100.000|100.000|0.000|0.000|-500000.000|590000.000|t|t|t 3.3|992163|10|10|1|1000.000|-1000.000|0.000|0.000|-500000.000|600000.000|t|t|t 3.4|992163|10|10|1|1000.000|-1000.000|0.000|0.000|-500000.000|600000.000|t|t|t -3.5|992163|100|100|1|100.000|-100.000|0.000|0.000|-500000.000|600000.000|t|t|t -3.6|992163|67|80|1|150.000|-125.000|0.000|0.000|-500000.000|600000.000|t|t|t +3.5|992163|100|100|1|100.000|100.000|0.000|0.000|-500000.000|590000.000|t|t|t +3.6|992163|67|80|1|150.000|125.000|0.000|0.000|-500000.000|590000.000|t|t|t 4.1|992163|10|10|1|1000.000|-1000.000|0.000|0.000|-500000.000|600000.000|t|t|t 4.2|992163|10|10|1|1000.000|-1000.000|1.000|1.000|-500010.000|600000.000|t|t|t 4.3|992163|10|10|1|1000.000|-1000.000|0.500|0.000|-500010.000|600000.000|t|t|t @@ -62,23 +62,23 @@ NOTICE: Values must be provided for both X and Y when specifying the scale. Re 5.1|992163|10|10|1|1000.000|-1000.000|0.000|0.000|-500000.000|600000.000|t|t|t 5.10|992163|11|11|1|1000.000|-1000.000|0.000|0.000|-500005.000|600001.000|t|t|t 5.11|992163|11|11|1|1000.000|-1000.000|0.000|0.000|-500991.000|600991.000|t|t|t -5.12|992163|200|200|1|50.000|-50.000|0.000|0.000|-500000.000|600000.000|t|t|t -5.13|992163|200|200|1|50.000|-50.000|0.000|0.000|-500000.000|600000.000|t|t|t -5.14|992163|201|200|1|50.000|-50.000|0.000|0.000|-500001.000|600000.000|t|t|t -5.15|992163|201|200|1|50.000|-50.000|0.000|0.000|-500001.000|600000.000|t|t|t -5.16|992163|201|200|1|50.000|-50.000|0.000|0.000|-500049.000|600000.000|t|t|t -5.17|992163|200|201|1|50.000|-50.000|0.000|0.000|-500000.000|600049.000|t|t|t -5.18|992163|200|201|1|50.000|-50.000|0.000|0.000|-500000.000|600041.000|t|t|t -5.19|992163|200|201|1|50.000|-50.000|0.000|0.000|-500000.000|600001.000|t|t|t +5.12|992163|200|200|1|50.000|50.000|0.000|0.000|-500000.000|590000.000|t|t|t +5.13|992163|200|200|1|50.000|50.000|0.000|0.000|-500000.000|590000.000|t|t|t +5.14|992163|201|200|1|50.000|50.000|0.000|0.000|-500001.000|590000.000|t|t|t +5.15|992163|201|200|1|50.000|50.000|0.000|0.000|-500001.000|590000.000|t|t|t +5.16|992163|201|200|1|50.000|50.000|0.000|0.000|-500049.000|590000.000|t|t|t +5.17|992163|200|201|1|50.000|50.000|0.000|0.000|-500000.000|589999.000|t|t|t +5.18|992163|200|201|1|50.000|50.000|0.000|0.000|-500000.000|589991.000|t|t|t +5.19|992163|200|201|1|50.000|50.000|0.000|0.000|-500000.000|589951.000|t|t|t 5.2|992163|10|10|1|1000.000|-1000.000|0.000|0.000|-500000.000|600000.000|t|t|t -5.20|992163|200|201|1|50.000|-50.000|0.000|0.000|-500000.000|600009.000|t|t|t -5.21|992163|201|201|1|50.000|-50.000|0.000|0.000|-500005.000|600001.000|t|t|t -5.22|992163|201|201|1|50.000|-50.000|0.000|0.000|-500041.000|600041.000|t|t|t -5.23|992163|84|83|1|121.000|-121.000|0.000|0.000|-500093.000|600039.000|t|t|t -5.24|992163|83|83|1|121.000|-121.000|0.000|0.000|-500000.000|600040.000|t|t|t -5.25|992163|83|84|1|121.000|-121.000|0.000|0.000|-500000.000|600048.000|t|t|t -5.26|992163|84|83|1|121.000|-121.000|0.000|0.000|-500098.000|600040.000|t|t|t -5.27|992163|84|83|1|121.000|-121.000|0.000|0.000|-500084.000|600030.000|t|t|t +5.20|992163|200|201|1|50.000|50.000|0.000|0.000|-500000.000|589959.000|t|t|t +5.21|992163|201|201|1|50.000|50.000|0.000|0.000|-500005.000|589951.000|t|t|t +5.22|992163|201|201|1|50.000|50.000|0.000|0.000|-500041.000|589991.000|t|t|t +5.23|992163|84|83|1|121.000|121.000|0.000|0.000|-500093.000|589996.000|t|t|t +5.24|992163|83|83|1|121.000|121.000|0.000|0.000|-500000.000|589997.000|t|t|t +5.25|992163|83|84|1|121.000|121.000|0.000|0.000|-500000.000|589884.000|t|t|t +5.26|992163|84|83|1|121.000|121.000|0.000|0.000|-500098.000|589997.000|t|t|t +5.27|992163|84|83|1|121.000|121.000|0.000|0.000|-500084.000|589987.000|t|t|t 5.3|992163|11|10|1|1000.000|-1000.000|0.000|0.000|-500001.000|600000.000|t|t|t 5.4|992163|11|10|1|1000.000|-1000.000|0.000|0.000|-500001.000|600000.000|t|t|t 5.5|992163|11|10|1|1000.000|-1000.000|0.000|0.000|-500999.000|600000.000|t|t|t