Skip to content

Commit ead62a6

Browse files
committed
GetFeatureInfo: fix for layers using a lon_wrap PROJECTION and requested in the wrapped part of the raster
1 parent 8cb8ee9 commit ead62a6

4 files changed

+109
-0
lines changed

maprasterquery.c

+28
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,9 @@ msRasterQueryByRectLow(mapObj *map, layerObj *layer, GDALDatasetH hDS,
415415
CPLErr eErr;
416416
rasterLayerInfo *rlinfo;
417417
rectObj searchrect;
418+
#if PROJ_VERSION_MAJOR < 6
419+
int mayNeedLonWrapAdjustment = MS_FALSE;
420+
#endif
418421

419422
rlinfo = (rasterLayerInfo *) layer->layerinfo;
420423

@@ -551,6 +554,16 @@ msRasterQueryByRectLow(mapObj *map, layerObj *layer, GDALDatasetH hDS,
551554
+ sqrt( rlinfo->range_dist );
552555
dfAdjustedRange = dfAdjustedRange * dfAdjustedRange;
553556

557+
#if PROJ_VERSION_MAJOR < 6
558+
if( layer->project &&
559+
msProjIsGeographicCRS(&(layer->projection)) &&
560+
msProjIsGeographicCRS(&(map->projection)) )
561+
{
562+
double dfLonWrap = 0;
563+
mayNeedLonWrapAdjustment = msProjectHasLonWrap(&(layer->projection), &dfLonWrap);
564+
}
565+
#endif
566+
554567
/* -------------------------------------------------------------------- */
555568
/* Loop over all pixels determining which are "in". */
556569
/* -------------------------------------------------------------------- */
@@ -576,8 +589,23 @@ msRasterQueryByRectLow(mapObj *map, layerObj *layer, GDALDatasetH hDS,
576589
/* coordinates if we have a hit */
577590
sReprojectedPixelLocation = sPixelLocation;
578591
if( layer->project )
592+
{
593+
#if PROJ_VERSION_MAJOR < 6
594+
/* Works around a bug in PROJ < 6 when reprojecting from a lon_wrap */
595+
/* geogCRS to a geogCRS, and the input abs(longitude) is > 180. Then */
596+
/* lon_wrap was ignored and the output longitude remained as the source */
597+
if( mayNeedLonWrapAdjustment )
598+
{
599+
if( rlinfo->target_point.x < sReprojectedPixelLocation.x - 180 )
600+
sReprojectedPixelLocation.x -= 360;
601+
else if( rlinfo->target_point.x > sReprojectedPixelLocation.x + 180 )
602+
sReprojectedPixelLocation.x += 360;
603+
}
604+
#endif
605+
579606
msProjectPoint( &(layer->projection), &(map->projection),
580607
&sReprojectedPixelLocation);
608+
}
581609

582610
/* If we are doing QueryByShape, check against the shape now */
583611
if( rlinfo->searchshape != NULL ) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
GetFeatureInfo results:
2+
3+
Layer 'test'
4+
Feature 0:
5+
x = '49.4'
6+
y = '-4.5'
7+
value_0 = '127'
8+
value_list = '127'
9+
red = '127'
10+
green = '127'
11+
blue = '127'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
GetFeatureInfo results:
2+
3+
Layer 'test'
4+
Feature 0:
5+
x = '-40.6'
6+
y = '-4.5'
7+
value_0 = '63'
8+
value_list = '63'
9+
red = '63'
10+
green = '63'
11+
blue = '63'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#
2+
# Test WMS GetfeatureInfo with a layer with lon_wrap=180
3+
#
4+
# REQUIRES: SUPPORTS=WMS
5+
#
6+
# RUN_PARMS: wms_getfeatureinfo_lon_wrap_180_right_part_raster.xml [MAPSERV] "QUERY_STRING=map=[MAPFILE]&service=WMS&request=GetFeatureInfo&version=1.3.0&CRS=EPSG:4326&width=200&height=200&layers=test&bbox=-90,-90,90,90&format=image/png&query_layers=test&i=50&j=100" > [RESULT_DEMIME]
7+
# RUN_PARMS: wms_getfeatureinfo_lon_wrap_180_left_part_raster.xml [MAPSERV] "QUERY_STRING=map=[MAPFILE]&service=WMS&request=GetFeatureInfo&version=1.3.0&CRS=EPSG:4326&width=200&height=200&layers=test&bbox=-90,-90,90,90&format=image/png&query_layers=test&i=150&j=100" > [RESULT_DEMIME]
8+
9+
MAP
10+
11+
NAME TEST
12+
STATUS ON
13+
SIZE 40 20
14+
EXTENT -180 -90 180 90
15+
IMAGECOLOR 0 0 0
16+
17+
PROJECTION
18+
"init=epsg:4326"
19+
END
20+
21+
OUTPUTFORMAT
22+
NAME "png"
23+
DRIVER AGG/PNG
24+
MIMETYPE "image/png"
25+
IMAGEMODE RGBA
26+
EXTENSION "png"
27+
END
28+
29+
WEB
30+
METADATA
31+
"ows_enable_request" "*"
32+
"ows_srs" "EPSG:4326"
33+
"ows_title" "WMS Getfeatureinfo"
34+
"wms_onlineresource" "http://localhost/cgi-bin/mapserv?map=mymap.map"
35+
END
36+
IMAGEPATH '/tmp/ms_tmp/'
37+
IMAGEURL '/ms_tmp/'
38+
END
39+
40+
LAYER
41+
NAME test
42+
TYPE RASTER
43+
STATUS ON
44+
DATA "../gdal/data/lon_wrap_180.asc"
45+
METADATA
46+
"wms_title" "test"
47+
"ows_srs" "EPSG:4326"
48+
"ows_include_items" "all"
49+
END
50+
PROJECTION
51+
"proj=longlat"
52+
"datum=WGS84"
53+
"lon_wrap=180"
54+
"no_defs"
55+
END
56+
TEMPLATE 'blank.html'
57+
END
58+
59+
END # of map file

0 commit comments

Comments
 (0)