Skip to content
Permalink
Browse files
msTransformMapToSource(): extra fixes to handle lon_wrap=180 and sour…
…ce dataset whose longitude range is larger than 360 deg
  • Loading branch information
rouault committed Jan 3, 2020
1 parent ba27152 commit 6a3000d0bf0a61b5f05a5e5ad06f7e46e89eb0cf
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 7 deletions.
@@ -1206,6 +1206,7 @@ static int msTransformMapToSource( int nDstXSize, int nDstYSize,
double dfYMinOut = 0.0;
double dfXMaxOut = 0.0;
double dfYMaxOut = 0.0;
const double dfHalfRes = adfDstGeoTransform[1] / 2;

/* Find out average y coordinate in src projection */
for( i = 0; i < nSamples; i++ ) {
@@ -1255,7 +1256,7 @@ static int msTransformMapToSource( int nDstXSize, int nDstYSize,
msReleaseLock( TLOCK_PROJ );
#endif

if( x2[0] >= dfXMinOut && x2[0] <= dfXMaxOut &&
if( x2[0] >= dfXMinOut - dfHalfRes && x2[0] <= dfXMaxOut + dfHalfRes &&
y2[0] >= dfYMinOut && y2[0] <= dfYMaxOut )
{
double x_out = adfInvSrcGeoTransform[0]
@@ -1265,8 +1266,8 @@ static int msTransformMapToSource( int nDstXSize, int nDstYSize,
+ (dfLonWrap-180)*adfInvSrcGeoTransform[4]
+ dfY*adfInvSrcGeoTransform[5];

/* Does the raster cover a whole 360 deg range ? */
if( nSrcXSize == (int)(adfInvSrcGeoTransform[1] * 360 + 0.5) )
/* Does the raster cover, at least, a whole 360 deg range ? */
if( nSrcXSize >= (int)(adfInvSrcGeoTransform[1] * 360) )
{
psSrcExtent->minx = 0;
psSrcExtent->maxx = nSrcXSize;
@@ -1280,8 +1281,8 @@ static int msTransformMapToSource( int nDstXSize, int nDstYSize,
psSrcExtent->maxy = MS_MAX(psSrcExtent->maxy, y_out);
}

if( x2[1] >= dfXMinOut && x2[1] <= dfXMaxOut &&
x2[1] >= dfYMinOut && y2[1] <= dfYMaxOut )
if( x2[1] >= dfXMinOut - dfHalfRes && x2[1] <= dfXMaxOut + dfHalfRes &&
y2[1] >= dfYMinOut && y2[1] <= dfYMaxOut )
{
double x_out = adfInvSrcGeoTransform[0]
+ (dfLonWrap+180)*adfInvSrcGeoTransform[1]
@@ -1290,8 +1291,8 @@ static int msTransformMapToSource( int nDstXSize, int nDstYSize,
+ (dfLonWrap+180)*adfInvSrcGeoTransform[4]
+ dfY*adfInvSrcGeoTransform[5];

/* Does the raster cover a whole 360 deg range ? */
if( nSrcXSize == (int)(adfInvSrcGeoTransform[1] * 360 + 0.5) )
/* Does the raster cover, at least, a whole 360 deg range ? */
if( nSrcXSize >= (int)(adfInvSrcGeoTransform[1] * 360) )
{
psSrcExtent->minx = 0;
psSrcExtent->maxx = nSrcXSize;
@@ -0,0 +1,25 @@
ncols 41
nrows 20
xllcorner -4.5
yllcorner -90.000000000000
cellsize 9.000000000000
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 127 127
@@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,36 @@
# Test behaviour with a projection with lon_wrap=180

MAP

NAME TEST
STATUS ON
SIZE 40 20
EXTENT -180 -89.9999 180 90
IMAGECOLOR 0 0 0

PROJECTION
"init=epsg:4326"
END

OUTPUTFORMAT
NAME "png"
DRIVER AGG/PNG
MIMETYPE "image/png"
IMAGEMODE RGBA
EXTENSION "png"
END

LAYER
NAME test
TYPE RASTER
STATUS default
DATA "data/lon_wrap_180_covering_more_than_360deg.asc"
PROJECTION
"proj=longlat"
"datum=WGS84"
"lon_wrap=180"
"no_defs"
END
END

END # of map file

0 comments on commit 6a3000d

Please sign in to comment.