Skip to content
Permalink
Browse files

Merge pull request #5960 from rouault/lon_wrap_180_source_dataset_lar…

…ger_than_360

msTransformMapToSource(): extra fixes to handle lon_wrap=180 and source dataset whose longitude range is larger than 360 deg
  • Loading branch information
rouault committed Jan 8, 2020
2 parents 6b3b000 + 6a3000d commit 8cb8ee9b543ea8822dabb91b261d27a551051aa5
@@ -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]]
Binary file not shown.
@@ -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 8cb8ee9

Please sign in to comment.
You can’t perform that action at this time.