Skip to content

Commit 05ff84f

Browse files
committed
Allow map->projection inheritance for layers referenced by connection (#4873)
1 parent bab4738 commit 05ff84f

File tree

4 files changed

+50
-30
lines changed

4 files changed

+50
-30
lines changed

mapserver.h

+1
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ extern "C" {
492492
#define MS_GIANT 16
493493
enum MS_QUERYMAP_STYLES {MS_NORMAL, MS_HILITE, MS_SELECTED};
494494
enum MS_CONNECTION_TYPE {MS_INLINE, MS_SHAPEFILE, MS_TILED_SHAPEFILE, MS_SDE, MS_OGR, MS_UNUSED_1, MS_POSTGIS, MS_WMS, MS_ORACLESPATIAL, MS_WFS, MS_GRATICULE, MS_MYSQL, MS_RASTER, MS_PLUGIN, MS_UNION, MS_UVRASTER, MS_CONTOUR, MS_KERNELDENSITY };
495+
#define IS_THIRDPARTY_LAYER_CONNECTIONTYPE(type) ((type) == MS_UNION || (type) == MS_KERNELDENSITY)
495496
enum MS_JOIN_CONNECTION_TYPE {MS_DB_XBASE, MS_DB_CSV, MS_DB_MYSQL, MS_DB_ORACLE, MS_DB_POSTGRES};
496497
enum MS_JOIN_TYPE {MS_JOIN_ONE_TO_ONE, MS_JOIN_ONE_TO_MANY};
497498

maputil.c

+47-6
Original file line numberDiff line numberDiff line change
@@ -2437,21 +2437,62 @@ int msMapSetLayerProjections(mapObj* map)
24372437
}
24382438

24392439
for(i=0; i<map->numlayers; i++) {
2440+
layerObj *lp = GET_LAYER(map,i);
24402441
/* This layer is turned on and needs a projection? */
2441-
if (GET_LAYER(map, i)->projection.numargs <= 0 &&
2442-
GET_LAYER(map, i)->status != MS_OFF &&
2443-
GET_LAYER(map, i)->transform == MS_TRUE) {
2442+
if (lp->projection.numargs <= 0 &&
2443+
lp->status != MS_OFF &&
2444+
lp->transform == MS_TRUE) {
24442445

24452446
/* Fetch main map projection string only now that we need it */
24462447
if (mapProjStr == NULL)
24472448
mapProjStr = msGetProjectionString(&(map->projection));
24482449

24492450
/* Set the projection to the map file projection */
2450-
if (msLoadProjectionString(&(GET_LAYER(map, i)->projection), mapProjStr) != 0) {
2451-
msSetError(MS_CGIERR, "Unable to set projection on layer.", "msTileSetProjectionst()");
2451+
if (msLoadProjectionString(&(lp->projection), mapProjStr) != 0) {
2452+
msSetError(MS_CGIERR, "Unable to set projection on layer.", "msMapSetLayerProjections()");
24522453
return(MS_FAILURE);
24532454
}
2454-
GET_LAYER(map, i)->project = MS_TRUE;
2455+
lp->project = MS_TRUE;
2456+
if(lp->connection && IS_THIRDPARTY_LAYER_CONNECTIONTYPE(lp->connectiontype)) {
2457+
char **reflayers;
2458+
int numreflayers,j;
2459+
reflayers = msStringSplit(lp->connection,',',&numreflayers);
2460+
for(j=0; j<numreflayers; j++) {
2461+
int *lidx, nlidx;
2462+
/* first check layers referenced by group name */
2463+
lidx = msGetLayersIndexByGroup(map, reflayers[i], &nlidx);
2464+
if(lidx) {
2465+
int k;
2466+
for(k=0; k<nlidx; k++) {
2467+
layerObj *glp = GET_LAYER(map,lidx[k]);
2468+
if (glp->projection.numargs <= 0 && glp->transform == MS_TRUE) {
2469+
2470+
/* Set the projection to the map file projection */
2471+
if (msLoadProjectionString(&(glp->projection), mapProjStr) != 0) {
2472+
msSetError(MS_CGIERR, "Unable to set projection on layer.", "msMapSetLayerProjections()");
2473+
return(MS_FAILURE);
2474+
}
2475+
glp->project = MS_TRUE;
2476+
}
2477+
}
2478+
free(lidx);
2479+
} else {
2480+
/* group name did not match, check by layer name */
2481+
int layer_idx = msGetLayerIndex(map,lp->connection);
2482+
layerObj *glp = GET_LAYER(map,layer_idx);
2483+
if (glp->projection.numargs <= 0 && glp->transform == MS_TRUE) {
2484+
2485+
/* Set the projection to the map file projection */
2486+
if (msLoadProjectionString(&(glp->projection), mapProjStr) != 0) {
2487+
msSetError(MS_CGIERR, "Unable to set projection on layer.", "msMapSetLayerProjections()");
2488+
return(MS_FAILURE);
2489+
}
2490+
glp->project = MS_TRUE;
2491+
}
2492+
}
2493+
}
2494+
msFreeCharArray(reflayers, numreflayers);
2495+
}
24552496
}
24562497
}
24572498
msFree(mapProjStr);

mapwms.c

+1-23
Original file line numberDiff line numberDiff line change
@@ -1410,30 +1410,8 @@ this request. Check wms/ows_enable_request settings.",
14101410

14111411
if (nonsquare_enabled ||
14121412
msProjectionsDiffer(&(map->projection), &newProj)) {
1413-
char *original_srs = NULL;
1414-
1415-
for(i=0; i<map->numlayers; i++) {
1416-
if (GET_LAYER(map, i)->projection.numargs <= 0 &&
1417-
GET_LAYER(map, i)->status != MS_OFF &&
1418-
GET_LAYER(map, i)->transform == MS_TRUE) {
1419-
/* This layer is turned on and needs a projection */
1420-
1421-
/* Fetch main map projection string only now that we need it */
1422-
if (original_srs == NULL)
1423-
original_srs = msGetProjectionString(&(map->projection));
1424-
1425-
if (msLoadProjectionString(&(GET_LAYER(map, i)->projection),
1426-
original_srs) != 0) {
1427-
msFreeProjection(&newProj);
1428-
return msWMSException(map, nVersion, NULL, wms_exception_format);
1429-
}
1430-
GET_LAYER(map, i)->project = MS_TRUE;
1431-
}
1432-
}
1433-
1434-
msFree(original_srs);
1413+
msMapSetLayerProjections(map);
14351414
}
1436-
14371415
msFreeProjection(&newProj);
14381416
}
14391417

msautotest

Submodule msautotest updated from 3e4822a to ebe1ed1

0 commit comments

Comments
 (0)