Skip to content

Commit 6acfaf4

Browse files
committed
Avoid calling msProjectionsDiffer over and over again (#5259)
1 parent 40c8ffd commit 6acfaf4

File tree

6 files changed

+46
-86
lines changed

6 files changed

+46
-86
lines changed

mapchart.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,8 @@ int getNextShape(mapObj *map, layerObj *layer, double *values, int *nvalues, sty
250250
status = msLayerNextShape(layer, shape);
251251
if(status == MS_SUCCESS) {
252252
#ifdef USE_PROJ
253-
if(layer->project && msProjectionsDiffer(&(layer->projection), &(map->projection)))
253+
if(layer->project)
254254
msProjectShape(&layer->projection, &map->projection, shape);
255-
else
256-
layer->project = MS_FALSE;
257255
#endif
258256

259257
if(msBindLayerToShape(layer, shape, MS_DRAWMODE_FEATURES|MS_DRAWMODE_LABELS) != MS_SUCCESS)
@@ -363,6 +361,9 @@ int msDrawPieChartLayer(mapObj *map, layerObj *layer, imageObj *image)
363361
return MS_FAILURE;
364362
}
365363
}
364+
#ifdef USE_PROJ
365+
layer->project = msProjectionsDiffer(&(layer->projection), &(map->projection));
366+
#endif
366367
/* step through the target shapes */
367368
msInitShape(&shape);
368369

mapdraw.c

+10-18
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,9 @@ int msDrawLayer(mapObj *map, layerObj *layer, imageObj *image)
665665
if(layer->compositer && !layer->compositer->next && layer->compositer->opacity == 0) return MS_SUCCESS; /* layer is completely transparent, skip it */
666666

667667

668-
/* conditions may have changed since this layer last drawn, so set
669-
layer->project true to recheck projection needs (Bug #673) */
670-
layer->project = MS_TRUE;
668+
/* conditions may have changed since this layer last drawn, so retest
669+
layer->project (Bug #673) */
670+
layer->project = msProjectionsDiffer(&(layer->projection),&(map->projection));
671671

672672
/* make sure labelcache setting is set correctly if postlabelcache is set. This is done by the parser but
673673
may have been altered by a mapscript. see #5142 */
@@ -1182,9 +1182,9 @@ int msDrawQueryLayer(mapObj *map, layerObj *layer, imageObj *image)
11821182

11831183
if(!msLayerIsVisible(map, layer)) return(MS_SUCCESS); /* not an error, just nothing to do */
11841184

1185-
/* conditions may have changed since this layer last drawn, so set
1186-
layer->project true to recheck projection needs (Bug #673) */
1187-
layer->project = MS_TRUE;
1185+
/* conditions may have changed since this layer last drawn, so reset
1186+
layer->project to recheck projection needs (Bug #673) */
1187+
layer->project = msProjectionsDiffer(&(layer->projection),&(map->projection));
11881188

11891189
/* set annotation status */
11901190
annotate = msEvalContext(map, layer, layer->labelrequires);
@@ -1511,10 +1511,8 @@ int circleLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj
15111511
if (layer->transform == MS_TRUE) {
15121512

15131513
#ifdef USE_PROJ
1514-
if (layer->project && msProjectionsDiffer(&(layer->projection), &(map->projection)))
1514+
if (layer->project)
15151515
msProjectPoint(&layer->projection, &map->projection, &center);
1516-
else
1517-
layer->project = MS_FALSE;
15181516
#endif
15191517

15201518
center.x = MS_MAP2IMAGE_X(center.x, map->extent.minx, map->cellsize);
@@ -1542,10 +1540,8 @@ int pointLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj
15421540
pointObj *point;
15431541

15441542
#ifdef USE_PROJ
1545-
if (layer->project && layer->transform == MS_TRUE && msProjectionsDiffer(&(layer->projection), &(map->projection)))
1543+
if (layer->project && layer->transform == MS_TRUE)
15461544
msProjectShape(&layer->projection, &map->projection, shape);
1547-
else
1548-
layer->project = MS_FALSE;
15491545
#endif
15501546

15511547
for (l = 0; l < layer->class[c]->numlabels; l++)
@@ -1840,10 +1836,8 @@ int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, imageObj *image,
18401836
}
18411837

18421838
#ifdef USE_PROJ
1843-
if (layer->project && layer->transform == MS_TRUE && msProjectionsDiffer(&(layer->projection), &(map->projection)))
1839+
if (layer->project && layer->transform == MS_TRUE)
18441840
msProjectShape(&layer->projection, &map->projection, shape);
1845-
else
1846-
layer->project = MS_FALSE;
18471841
#endif
18481842

18491843
/* check if we'll need the unclipped shape */
@@ -2028,10 +2022,8 @@ int msDrawPoint(mapObj *map, layerObj *layer, pointObj *point, imageObj *image,
20282022
labelObj *label=NULL;
20292023

20302024
#ifdef USE_PROJ
2031-
if(layer->transform == MS_TRUE && layer->project && msProjectionsDiffer(&(layer->projection), &(map->projection)))
2025+
if(layer->transform == MS_TRUE && layer->project)
20322026
msProjectPoint(&layer->projection, &map->projection, point);
2033-
else
2034-
layer->project = MS_FALSE;
20352027
#endif
20362028

20372029
if(labeltext && theclass->numlabels > 0) {

mapgraticule.c

+8-15
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,9 @@ int msGraticuleLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery)
205205
pInfo->pboundinglines[0].point[1].y = rectMapCoordinates.maxy;
206206

207207
#ifdef USE_PROJ
208-
if(layer->project && msProjectionsDiffer(&(layer->projection), &(layer->map->projection)))
208+
layer->project = msProjectionsDiffer(&(layer->projection), &(layer->map->projection));
209+
if(layer->project)
209210
msProjectLine(&layer->map->projection, &layer->projection, &pInfo->pboundinglines[0]);
210-
else
211-
layer->project = MS_FALSE;
212211
#endif
213212

214213
/*
@@ -222,10 +221,8 @@ int msGraticuleLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery)
222221
pInfo->pboundinglines[1].point[1].y = rectMapCoordinates.miny;
223222

224223
#ifdef USE_PROJ
225-
if(layer->project && msProjectionsDiffer(&(layer->projection), &(layer->map->projection)))
224+
if(layer->project)
226225
msProjectLine(&layer->map->projection, &layer->projection, &pInfo->pboundinglines[1]);
227-
else
228-
layer->project = MS_FALSE;
229226
#endif
230227

231228
/*
@@ -239,10 +236,8 @@ int msGraticuleLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery)
239236
pInfo->pboundinglines[2].point[1].y = rectMapCoordinates.maxy;
240237

241238
#ifdef USE_PROJ
242-
if(layer->project && msProjectionsDiffer(&(layer->projection), &(layer->map->projection)))
239+
if(layer->project)
243240
msProjectLine(&layer->map->projection, &layer->projection, &pInfo->pboundinglines[2]);
244-
else
245-
layer->project = MS_FALSE;
246241
#endif
247242

248243
/*
@@ -256,10 +251,8 @@ int msGraticuleLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery)
256251
pInfo->pboundinglines[3].point[1].y = rectMapCoordinates.maxy;
257252

258253
#ifdef USE_PROJ
259-
if(layer->project && msProjectionsDiffer(&(layer->projection), &(layer->map->projection)))
254+
if(layer->project)
260255
msProjectLine(&layer->map->projection, &layer->projection, &pInfo->pboundinglines[3]);
261-
else
262-
layer->project = MS_FALSE;
263256
#endif
264257
}
265258

@@ -680,7 +673,7 @@ graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map,
680673
msCopyShape(&shapegrid, &tmpshape);
681674
/* status = msDrawShape(map, layer, &tmpshape, image, -1); */
682675

683-
if(layer->project && msProjectionsDiffer(&(layer->projection), &(map->projection)))
676+
if(layer->project)
684677
msProjectShape(&layer->projection, &map->projection, &shapegrid);
685678

686679
msClipPolylineRect(&shapegrid, cliprect);
@@ -1045,7 +1038,7 @@ static int _AdjustLabelPosition( layerObj *pLayer, shapeObj *pShape, msGraticule
10451038
ptPoint = pShape->line->point[0];
10461039

10471040
#ifdef USE_PROJ
1048-
if(pLayer->project && msProjectionsDiffer( &pLayer->projection, &pLayer->map->projection ))
1041+
if(pLayer->project)
10491042
msProjectShape( &pLayer->projection, &pLayer->map->projection, pShape );
10501043
#endif
10511044

@@ -1087,7 +1080,7 @@ static int _AdjustLabelPosition( layerObj *pLayer, shapeObj *pShape, msGraticule
10871080
msTransformPixelToShape( pShape, pLayer->map->extent, pLayer->map->cellsize );
10881081

10891082
#ifdef USE_PROJ
1090-
if(pLayer->project && msProjectionsDiffer( &pLayer->map->projection, &pLayer->projection ))
1083+
if(pLayer->project)
10911084
msProjectShape( &pLayer->map->projection, &pLayer->projection, pShape );
10921085
#endif
10931086

mapogroutput.c

+4-7
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,6 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
883883
gmlItemListObj *item_list = NULL;
884884
const char *value;
885885
char *pszWKT;
886-
int reproject = MS_FALSE;
887886
int nFirstOGRFieldIndex = -1;
888887
const char *pszFeatureid = NULL;
889888

@@ -893,11 +892,9 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
893892
/* -------------------------------------------------------------------- */
894893
/* Will we need to reproject? */
895894
/* -------------------------------------------------------------------- */
896-
if(layer->transform == MS_TRUE
897-
&& layer->project
898-
&& msProjectionsDiffer(&(layer->projection),
899-
&(layer->map->projection)) )
900-
reproject = MS_TRUE;
895+
if(layer->transform == MS_TRUE)
896+
layer->project = msProjectionsDiffer(&(layer->projection),
897+
&(layer->map->projection));
901898

902899
/* -------------------------------------------------------------------- */
903900
/* Establish the geometry type to use for the created layer. */
@@ -1119,7 +1116,7 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
11191116
}
11201117
}
11211118

1122-
if( reproject ) {
1119+
if( layer->project ) {
11231120
status =
11241121
msProjectShape(&layer->projection, &layer->map->projection,
11251122
&resultshape);

mapquery.c

+17-36
Original file line numberDiff line numberDiff line change
@@ -762,10 +762,9 @@ int msQueryByFilter(mapObj *map)
762762

763763
search_rect = map->query.rect;
764764
#ifdef USE_PROJ
765-
if(lp->project && msProjectionsDiffer(&(lp->projection), &(map->projection))) {
765+
lp->project = msProjectionsDiffer(&(lp->projection), &(map->projection));
766+
if(lp->project)
766767
msProjectRect(&(map->projection), &(lp->projection), &search_rect); /* project the searchrect to source coords */
767-
} else
768-
lp->project = MS_FALSE;
769768
#endif
770769

771770
status = msLayerWhichShapes(lp, search_rect, MS_TRUE);
@@ -809,10 +808,8 @@ int msQueryByFilter(mapObj *map)
809808
}
810809

811810
#ifdef USE_PROJ
812-
if(lp->project && msProjectionsDiffer(&(lp->projection), &(map->projection)))
811+
if(lp->project)
813812
msProjectShape(&(lp->projection), &(map->projection), &shape);
814-
else
815-
lp->project = MS_FALSE;
816813
#endif
817814

818815
/* Should we skip this feature? */
@@ -979,10 +976,9 @@ int msQueryByRect(mapObj *map)
979976
}
980977

981978
#ifdef USE_PROJ
982-
if(lp->project && msProjectionsDiffer(&(lp->projection), &(map->projection)))
979+
lp->project = msProjectionsDiffer(&(lp->projection), &(map->projection));
980+
if(lp->project)
983981
msProjectRect(&(map->projection), &(lp->projection), &searchrect); /* project the searchrect to source coords */
984-
else
985-
lp->project = MS_FALSE;
986982
#endif
987983

988984
status = msLayerWhichShapes(lp, searchrect, MS_TRUE);
@@ -1031,10 +1027,8 @@ int msQueryByRect(mapObj *map)
10311027
}
10321028

10331029
#ifdef USE_PROJ
1034-
if(lp->project && msProjectionsDiffer(&(lp->projection), &(map->projection)))
1030+
if(lp->project)
10351031
msProjectShape(&(lp->projection), &(map->projection), &shape);
1036-
else
1037-
lp->project = MS_FALSE;
10381032
#endif
10391033

10401034
if(msRectContained(&shape.bounds, &searchrectInMapProj) == MS_TRUE) { /* if the whole shape is in, don't intersect */
@@ -1142,7 +1136,7 @@ int msQueryByFeatures(mapObj *map)
11421136

11431137
/* conditions may have changed since this layer last drawn, so set
11441138
layer->project true to recheck projection needs (Bug #673) */
1145-
slp->project = MS_TRUE;
1139+
slp->project = msProjectionsDiffer(&(slp->projection), &(map->projection));
11461140

11471141
if(map->query.layer < 0 || map->query.layer >= map->numlayers)
11481142
start = map->numlayers-1;
@@ -1171,7 +1165,7 @@ int msQueryByFeatures(mapObj *map)
11711165

11721166
/* conditions may have changed since this layer last drawn, so set
11731167
layer->project true to recheck projection needs (Bug #673) */
1174-
lp->project = MS_TRUE;
1168+
lp->project = msProjectionsDiffer(&(lp->projection), &(map->projection));
11751169

11761170
/* free any previous search results, do it now in case one of the next few tests fail */
11771171
if(lp->resultcache) {
@@ -1234,11 +1228,8 @@ int msQueryByFeatures(mapObj *map)
12341228
}
12351229

12361230
#ifdef USE_PROJ
1237-
if(slp->project && msProjectionsDiffer(&(slp->projection), &(map->projection))) {
1231+
if(slp->project)
12381232
msProjectShape(&(slp->projection), &(map->projection), &selectshape);
1239-
msComputeBounds(&selectshape); /* recompute the bounding box AFTER projection */
1240-
} else
1241-
slp->project = MS_FALSE;
12421233
#endif
12431234

12441235
/* identify target shapes */
@@ -1250,10 +1241,8 @@ int msQueryByFeatures(mapObj *map)
12501241
searchrect.maxy += tolerance;
12511242

12521243
#ifdef USE_PROJ
1253-
if(lp->project && msProjectionsDiffer(&(lp->projection), &(map->projection)))
1244+
if(lp->project)
12541245
msProjectRect(&(map->projection), &(lp->projection), &searchrect); /* project the searchrect to source coords */
1255-
else
1256-
lp->project = MS_FALSE;
12571246
#endif
12581247

12591248
status = msLayerWhichShapes(lp, searchrect, MS_TRUE);
@@ -1309,10 +1298,8 @@ int msQueryByFeatures(mapObj *map)
13091298
}
13101299

13111300
#ifdef USE_PROJ
1312-
if(lp->project && msProjectionsDiffer(&(lp->projection), &(map->projection)))
1301+
if(lp->project)
13131302
msProjectShape(&(lp->projection), &(map->projection), &shape);
1314-
else
1315-
lp->project = MS_FALSE;
13161303
#endif
13171304

13181305
switch(selectshape.type) { /* may eventually support types other than polygon on line */
@@ -1545,10 +1532,9 @@ int msQueryByPoint(mapObj *map)
15451532
/* identify target shapes */
15461533
searchrect = rect;
15471534
#ifdef USE_PROJ
1548-
if(lp->project && msProjectionsDiffer(&(lp->projection), &(map->projection)))
1535+
lp->project = msProjectionsDiffer(&(lp->projection), &(map->projection));
1536+
if(lp->project)
15491537
msProjectRect(&(map->projection), &(lp->projection), &searchrect); /* project the searchrect to source coords */
1550-
else
1551-
lp->project = MS_FALSE;
15521538
#endif
15531539
status = msLayerWhichShapes(lp, searchrect, MS_TRUE);
15541540
if(status == MS_DONE) { /* no overlap */
@@ -1595,10 +1581,8 @@ int msQueryByPoint(mapObj *map)
15951581
}
15961582

15971583
#ifdef USE_PROJ
1598-
if(lp->project && msProjectionsDiffer(&(lp->projection), &(map->projection)))
1584+
if(lp->project)
15991585
msProjectShape(&(lp->projection), &(map->projection), &shape);
1600-
else
1601-
lp->project = MS_FALSE;
16021586
#endif
16031587

16041588
d = msDistancePointToShape(&(map->query.point), &shape);
@@ -1767,10 +1751,9 @@ int msQueryByShape(mapObj *map)
17671751
searchrect.maxy += tolerance;
17681752

17691753
#ifdef USE_PROJ
1770-
if(lp->project && msProjectionsDiffer(&(lp->projection), &(map->projection)))
1754+
lp->project = msProjectionsDiffer(&(lp->projection), &(map->projection));
1755+
if(lp->project)
17711756
msProjectRect(&(map->projection), &(lp->projection), &searchrect); /* project the searchrect to source coords */
1772-
else
1773-
lp->project = MS_FALSE;
17741757
#endif
17751758

17761759
status = msLayerWhichShapes(lp, searchrect, MS_TRUE);
@@ -1817,10 +1800,8 @@ int msQueryByShape(mapObj *map)
18171800
}
18181801

18191802
#ifdef USE_PROJ
1820-
if(lp->project && msProjectionsDiffer(&(lp->projection), &(map->projection)))
1803+
if(lp->project)
18211804
msProjectShape(&(lp->projection), &(map->projection), &shape);
1822-
else
1823-
lp->project = MS_FALSE;
18241805
#endif
18251806

18261807
switch(qshape->type) { /* may eventually support types other than polygon or line */

maprasterquery.c

+3-7
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ msRasterQueryByRectLow(mapObj *map, layerObj *layer, GDALDatasetH hDS,
416416
CPLErr eErr;
417417
rasterLayerInfo *rlinfo;
418418
rectObj searchrect;
419-
int needReproject = MS_FALSE;
420419

421420
rlinfo = (rasterLayerInfo *) layer->layerinfo;
422421

@@ -426,12 +425,9 @@ msRasterQueryByRectLow(mapObj *map, layerObj *layer, GDALDatasetH hDS,
426425
/* -------------------------------------------------------------------- */
427426
searchrect = queryRect;
428427
#ifdef USE_PROJ
429-
if(layer->project
430-
&& msProjectionsDiffer(&(layer->projection), &(map->projection))) {
428+
layer->project = msProjectionsDiffer(&(layer->projection), &(map->projection));
429+
if(layer->project)
431430
msProjectRect(&(map->projection), &(layer->projection), &searchrect);
432-
needReproject = MS_TRUE;
433-
} else
434-
layer->project = MS_FALSE;
435431
#endif
436432

437433
/* -------------------------------------------------------------------- */
@@ -582,7 +578,7 @@ msRasterQueryByRectLow(mapObj *map, layerObj *layer, GDALDatasetH hDS,
582578
/* in sPixelLocationInLayerSRS, so that we can return those */
583579
/* coordinates if we have a hit */
584580
sReprojectedPixelLocation = sPixelLocation;
585-
if( needReproject )
581+
if( layer->project )
586582
msProjectPoint( &(layer->projection), &(map->projection),
587583
&sReprojectedPixelLocation);
588584

0 commit comments

Comments
 (0)