Skip to content

Commit 6a3000d

Browse files
committed
msTransformMapToSource(): extra fixes to handle lon_wrap=180 and source dataset whose longitude range is larger than 360 deg
1 parent ba27152 commit 6a3000d

5 files changed

+70
-7
lines changed

mapresample.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,7 @@ static int msTransformMapToSource( int nDstXSize, int nDstYSize,
12061206
double dfYMinOut = 0.0;
12071207
double dfXMaxOut = 0.0;
12081208
double dfYMaxOut = 0.0;
1209+
const double dfHalfRes = adfDstGeoTransform[1] / 2;
12091210

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

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

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

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

1293-
/* Does the raster cover a whole 360 deg range ? */
1294-
if( nSrcXSize == (int)(adfInvSrcGeoTransform[1] * 360 + 0.5) )
1294+
/* Does the raster cover, at least, a whole 360 deg range ? */
1295+
if( nSrcXSize >= (int)(adfInvSrcGeoTransform[1] * 360) )
12951296
{
12961297
psSrcExtent->minx = 0;
12971298
psSrcExtent->maxx = nSrcXSize;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
ncols 41
2+
nrows 20
3+
xllcorner -4.5
4+
yllcorner -90.000000000000
5+
cellsize 9.000000000000
6+
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
7+
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
8+
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
9+
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
10+
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
11+
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
12+
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
13+
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
14+
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
15+
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
16+
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
17+
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
18+
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
19+
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
20+
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
21+
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
22+
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
23+
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
24+
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
25+
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Test behaviour with a projection with lon_wrap=180
2+
3+
MAP
4+
5+
NAME TEST
6+
STATUS ON
7+
SIZE 40 20
8+
EXTENT -180 -89.9999 180 90
9+
IMAGECOLOR 0 0 0
10+
11+
PROJECTION
12+
"init=epsg:4326"
13+
END
14+
15+
OUTPUTFORMAT
16+
NAME "png"
17+
DRIVER AGG/PNG
18+
MIMETYPE "image/png"
19+
IMAGEMODE RGBA
20+
EXTENSION "png"
21+
END
22+
23+
LAYER
24+
NAME test
25+
TYPE RASTER
26+
STATUS default
27+
DATA "data/lon_wrap_180_covering_more_than_360deg.asc"
28+
PROJECTION
29+
"proj=longlat"
30+
"datum=WGS84"
31+
"lon_wrap=180"
32+
"no_defs"
33+
END
34+
END
35+
36+
END # of map file

0 commit comments

Comments
 (0)