Skip to content

Commit 1ca010b

Browse files
committed
PROJ6: more uses of reprojectionObj to improve performance
1 parent b73b82b commit 1ca010b

12 files changed

+168
-43
lines changed

Diff for: kerneldensity.c

+14-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,20 @@ int msComputeKernelDensityDataset(mapObj *map, imageObj *image, layerObj *kernel
201201
values = (float*) msSmallCalloc(im_width * im_height, sizeof(float));
202202
#ifdef USE_PROJ
203203
if(layer->project)
204-
msProjectShape(&layer->projection, &map->projection, &shape);
204+
{
205+
if( layer->reprojectorLayerToMap == NULL )
206+
{
207+
layer->reprojectorLayerToMap = msProjectCreateReprojector(
208+
&layer->projection, &map->projection);
209+
if( layer->reprojectorLayerToMap == NULL )
210+
{
211+
msFreeShape(&shape);
212+
msLayerClose(layer);
213+
return MS_FAILURE;
214+
}
215+
}
216+
msProjectShapeEx(layer->reprojectorLayerToMap, &shape);
217+
}
205218
#endif
206219

207220
/* the weight for the sample is set to 1.0 by default. If the

Diff for: mapchart.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,18 @@ int getNextShape(mapObj *map, layerObj *layer, double *values, int *nvalues, sty
251251
if(status == MS_SUCCESS) {
252252
#ifdef USE_PROJ
253253
if(layer->project)
254-
msProjectShape(&layer->projection, &map->projection, shape);
254+
{
255+
if( layer->reprojectorLayerToMap == NULL )
256+
{
257+
layer->reprojectorLayerToMap = msProjectCreateReprojector(
258+
&layer->projection, &map->projection);
259+
if( layer->reprojectorLayerToMap == NULL )
260+
{
261+
return MS_FAILURE;
262+
}
263+
}
264+
msProjectShapeEx(layer->reprojectorLayerToMap, shape);
265+
}
255266
#endif
256267

257268
if(msBindLayerToShape(layer, shape, MS_DRAWMODE_FEATURES|MS_DRAWMODE_LABELS) != MS_SUCCESS)

Diff for: mapcluster.c

+15-2
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,7 @@ int RebuildClusters(layerObj *layer, int isQuery)
10011001
#ifdef USE_CLUSTER_EXTERNAL
10021002
int layerIndex;
10031003
#endif
1004+
reprojectionObj* reprojector = NULL;
10041005

10051006
msClusterLayerInfo* layerinfo = layer->layerinfo;
10061007

@@ -1133,11 +1134,18 @@ int RebuildClusters(layerObj *layer, int isQuery)
11331134
if ((current = clusterInfoCreate(layerinfo)) == NULL)
11341135
return MS_FAILURE;
11351136

1137+
#if defined(USE_PROJ) && defined(USE_CLUSTER_EXTERNAL)
1138+
if(srcLayer->transform == MS_TRUE && srcLayer->project && layer->transform == MS_TRUE && layer->project &&msProjectionsDiffer(&(srcLayer->projection), &(layer->projection)))
1139+
{
1140+
reprojector = msProjectCreateReprojector(&srcLayer->projection, &layer->projection);
1141+
}
1142+
#endif
1143+
11361144
while((status = msLayerNextShape(srcLayer, &current->shape)) == MS_SUCCESS) {
11371145
#if defined(USE_PROJ) && defined(USE_CLUSTER_EXTERNAL)
11381146
/* transform the shape to the projection of this layer */
1139-
if(srcLayer->transform == MS_TRUE && srcLayer->project && layer->transform == MS_TRUE && layer->project &&msProjectionsDiffer(&(srcLayer->projection), &(layer->projection)))
1140-
msProjectShape(&srcLayer->projection, &layer->projection, &current->shape);
1147+
if( reprojector )
1148+
msProjectShapeEx(reprojector, &current->shape);
11411149
#endif
11421150
/* set up positions and variance */
11431151
current->avgx = current->x = current->shape.bounds.minx;
@@ -1173,6 +1181,7 @@ int RebuildClusters(layerObj *layer, int isQuery)
11731181
/* add this shape to the tree */
11741182
if (treeNodeAddShape(layerinfo, layerinfo->root, current, depth) != MS_SUCCESS) {
11751183
clusterInfoDestroyList(layerinfo, current);
1184+
msProjectDestroyReprojector(reprojector);
11761185
return MS_FAILURE;
11771186
}
11781187
}
@@ -1190,17 +1199,21 @@ int RebuildClusters(layerObj *layer, int isQuery)
11901199
/* if not found add this shape as a new cluster */
11911200
if (treeNodeAddShape(layerinfo, layerinfo->root, current, depth) != MS_SUCCESS) {
11921201
clusterInfoDestroyList(layerinfo, current);
1202+
msProjectDestroyReprojector(reprojector);
11931203
return MS_FAILURE;
11941204
}
11951205
}
11961206
}
11971207

11981208
if ((current = clusterInfoCreate(layerinfo)) == NULL) {
11991209
clusterInfoDestroyList(layerinfo, current);
1210+
msProjectDestroyReprojector(reprojector);
12001211
return MS_FAILURE;
12011212
}
12021213
}
12031214

1215+
msProjectDestroyReprojector(reprojector);
1216+
12041217
clusterInfoDestroyList(layerinfo, current);
12051218

12061219
if (layerinfo->algorithm == MSCLUSTER_ALGORITHM_FULL) {

Diff for: mapdraw.c

+25-2
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,7 @@ int circleLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj
16791679
/* TODO: need to handle circle annotation */
16801680
}
16811681

1682+
static
16821683
int pointLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj *shape, int drawmode)
16831684
{
16841685
int l, c = shape->classindex, j, i, s;
@@ -1687,7 +1688,18 @@ int pointLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer, shapeObj
16871688

16881689
#ifdef USE_PROJ
16891690
if (layer->project && layer->transform == MS_TRUE)
1690-
msProjectShape(&layer->projection, &map->projection, shape);
1691+
{
1692+
if( layer->reprojectorLayerToMap == NULL )
1693+
{
1694+
layer->reprojectorLayerToMap = msProjectCreateReprojector(
1695+
&layer->projection, &map->projection);
1696+
if( layer->reprojectorLayerToMap == NULL )
1697+
{
1698+
return MS_FAILURE;
1699+
}
1700+
}
1701+
msProjectShapeEx(layer->reprojectorLayerToMap, shape);
1702+
}
16911703
#endif
16921704

16931705
// Only take into account map rotation if the label and style angles are
@@ -2015,7 +2027,18 @@ int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, imageObj *image,
20152027

20162028
#ifdef USE_PROJ
20172029
if (layer->project && layer->transform == MS_TRUE)
2018-
msProjectShape(&layer->projection, &map->projection, shape);
2030+
{
2031+
if( layer->reprojectorLayerToMap == NULL )
2032+
{
2033+
layer->reprojectorLayerToMap = msProjectCreateReprojector(
2034+
&layer->projection, &map->projection);
2035+
if( layer->reprojectorLayerToMap == NULL )
2036+
{
2037+
return MS_FAILURE;
2038+
}
2039+
}
2040+
msProjectShapeEx(layer->reprojectorLayerToMap, shape);
2041+
}
20192042
#endif
20202043

20212044
/* check if we'll need the unclipped shape */

Diff for: mapfile.c

+4
Original file line numberDiff line numberDiff line change
@@ -3577,6 +3577,8 @@ int initLayer(layerObj *layer, mapObj *map)
35773577
}
35783578

35793579
layer->project = MS_TRUE;
3580+
layer->reprojectorLayerToMap = NULL;
3581+
layer->reprojectorMapToLayer = NULL;
35803582

35813583
initCluster(&layer->cluster);
35823584

@@ -3720,6 +3722,8 @@ int freeLayer(layerObj *layer)
37203722
msFree(layer->vtable);
37213723
msFree(layer->classgroup);
37223724

3725+
msProjectDestroyReprojector(layer->reprojectorLayerToMap);
3726+
msProjectDestroyReprojector(layer->reprojectorMapToLayer);
37233727
msFreeProjection(&(layer->projection));
37243728
msFreeExpression(&layer->_geomtransform);
37253729

Diff for: mapgraticule.c

+23-4
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,15 @@ graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map,
702702
msCopyShape(&shapegrid, &tmpshape);
703703
/* status = msDrawShape(map, layer, &tmpshape, image, -1); */
704704

705-
if(layer->project)
706-
msProjectShape(&layer->projection, &map->projection, &shapegrid);
705+
if(layer->project) {
706+
if( layer->reprojectorLayerToMap == NULL )
707+
{
708+
layer->reprojectorLayerToMap = msProjectCreateReprojector(
709+
&layer->projection, &map->projection);
710+
}
711+
if( layer->reprojectorLayerToMap )
712+
msProjectShapeEx(layer->reprojectorLayerToMap, &shapegrid);
713+
}
707714

708715
msClipPolylineRect(&shapegrid, cliprect);
709716

@@ -1070,7 +1077,13 @@ static int _AdjustLabelPosition( layerObj *pLayer, shapeObj *pShape, msGraticule
10701077
#ifdef USE_PROJ
10711078
if(pLayer->project)
10721079
{
1073-
msProjectShape( &pLayer->projection, &pLayer->map->projection, pShape );
1080+
if( pLayer->reprojectorLayerToMap == NULL )
1081+
{
1082+
pLayer->reprojectorLayerToMap = msProjectCreateReprojector(
1083+
&pLayer->projection, &pLayer->map->projection);
1084+
}
1085+
if( pLayer->reprojectorLayerToMap )
1086+
msProjectShapeEx(pLayer->reprojectorLayerToMap, pShape );
10741087

10751088
/* Poor man detection of reprojection failure */
10761089
if( msProjIsGeographicCRS(&(pLayer->projection)) !=
@@ -1191,7 +1204,13 @@ static int _AdjustLabelPosition( layerObj *pLayer, shapeObj *pShape, msGraticule
11911204
}
11921205
}
11931206

1194-
msProjectShape( &pLayer->map->projection, &pLayer->projection, pShape );
1207+
if( pLayer->reprojectorMapToLayer == NULL )
1208+
{
1209+
pLayer->reprojectorMapToLayer = msProjectCreateReprojector(
1210+
&pLayer->map->projection, &pLayer->projection);
1211+
}
1212+
if( pLayer->reprojectorMapToLayer )
1213+
msProjectShapeEx(pLayer->reprojectorMapToLayer, pShape );
11951214
}
11961215
#endif
11971216

Diff for: maplayer.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,7 @@ int LayerDefaultGetShapeCount(layerObj *layer, rectObj rect, projectionObj *rect
15891589
shapeObj shape, searchshape;
15901590
int nShapeCount = 0;
15911591
rectObj searchrect = rect;
1592+
reprojectionObj* reprojector = NULL;
15921593

15931594
msInitShape(&searchshape);
15941595
msRectToPolygon(searchrect, &searchshape);
@@ -1622,7 +1623,12 @@ int LayerDefaultGetShapeCount(layerObj *layer, rectObj rect, projectionObj *rect
16221623
{
16231624
#ifdef USE_PROJ
16241625
if(layer->project && msProjectionsDiffer(&(layer->projection), rectProjection))
1625-
msProjectShape(&(layer->projection), rectProjection, &shape);
1626+
{
1627+
if( reprojector == NULL )
1628+
reprojector = msProjectCreateReprojector(&(layer->projection), rectProjection);
1629+
if( reprojector )
1630+
msProjectShapeEx(reprojector, &shape);
1631+
}
16261632
else
16271633
layer->project = MS_FALSE;
16281634
#endif
@@ -1656,6 +1662,7 @@ int LayerDefaultGetShapeCount(layerObj *layer, rectObj rect, projectionObj *rect
16561662
}
16571663

16581664
msFreeShape(&searchshape);
1665+
msProjectDestroyReprojector(reprojector);
16591666

16601667
return nShapeCount;
16611668
}

Diff for: mapmvt.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,17 @@ int msMVTWriteTile( mapObj *map, int sendheaders ) {
510510
}
511511

512512
if( layer->project ) {
513-
status = msProjectShape(&layer->projection, &layer->map->projection, &shape);
514-
} if( status == MS_SUCCESS ) {
513+
if( layer->reprojectorLayerToMap == NULL )
514+
{
515+
layer->reprojectorLayerToMap = msProjectCreateReprojector(
516+
&layer->projection, &map->projection);
517+
}
518+
if( layer->reprojectorLayerToMap )
519+
status = msProjectShapeEx(layer->reprojectorLayerToMap, &shape);
520+
else
521+
status = MS_FAILURE;
522+
}
523+
if( status == MS_SUCCESS ) {
515524
status = mvtWriteShape( layer, &shape, mvt_layer, item_list, &value_lookup_cache, &map->extent, buffer );
516525
}
517526

Diff for: mapogroutput.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -1179,9 +1179,15 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
11791179
}
11801180

11811181
if( layer->project ) {
1182-
status =
1183-
msProjectShape(&layer->projection, &layer->map->projection,
1184-
&resultshape);
1182+
if( layer->reprojectorLayerToMap == NULL )
1183+
{
1184+
layer->reprojectorLayerToMap = msProjectCreateReprojector(
1185+
&layer->projection, &layer->map->projection);
1186+
}
1187+
if( layer->reprojectorLayerToMap )
1188+
status = msProjectShapeEx(layer->reprojectorLayerToMap, &resultshape);
1189+
else
1190+
status = MS_FAILURE;
11851191
}
11861192

11871193
/*

Diff for: mapproject.c

+16-18
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
static char *ms_proj_lib = NULL;
4141

4242
static int msTestNeedWrap( pointObj pt1, pointObj pt2, pointObj pt2_geo,
43-
projectionObj *src_proj,
44-
projectionObj *dst_proj );
43+
reprojectionObj* reprojector );
4544

4645
#if defined(USE_PROJ) && PROJ_VERSION_MAJOR >= 6
4746

@@ -964,7 +963,7 @@ static void msProjectGrowRect(reprojectionObj* reprojector,
964963
/* reprojects and the other end does not. Finds the horizon. */
965964
/************************************************************************/
966965
#ifdef USE_PROJ
967-
static int msProjectSegment( projectionObj *in, projectionObj *out,
966+
static int msProjectSegment( reprojectionObj* reprojector,
968967
pointObj *start, pointObj *end )
969968

970969
{
@@ -976,12 +975,12 @@ static int msProjectSegment( projectionObj *in, projectionObj *out,
976975
/* then re-call with the points reversed. */
977976
/* -------------------------------------------------------------------- */
978977
testPoint = *start;
979-
if( msProjectPoint( in, out, &testPoint ) == MS_FAILURE ) {
978+
if( msProjectPointEx( reprojector, &testPoint ) == MS_FAILURE ) {
980979
testPoint = *end;
981-
if( msProjectPoint( in, out, &testPoint ) == MS_FAILURE )
980+
if( msProjectPointEx( reprojector, &testPoint ) == MS_FAILURE )
982981
return MS_FAILURE;
983982
else
984-
return msProjectSegment( in, out, end, start );
983+
return msProjectSegment( reprojector, end, start );
985984
}
986985

987986
/* -------------------------------------------------------------------- */
@@ -1002,7 +1001,7 @@ static int msProjectSegment( projectionObj *in, projectionObj *out,
10021001

10031002
testPoint = midPoint;
10041003

1005-
if( msProjectPoint( in, out, &testPoint ) == MS_FAILURE ) {
1004+
if( msProjectPointEx( reprojector, &testPoint ) == MS_FAILURE ) {
10061005
if (midPoint.x == subEnd.x && midPoint.y == subEnd.y)
10071006
return MS_FAILURE; /* break infinite loop */
10081007

@@ -1021,8 +1020,8 @@ static int msProjectSegment( projectionObj *in, projectionObj *out,
10211020
/* -------------------------------------------------------------------- */
10221021
*end = subStart;
10231022

1024-
if( msProjectPoint( in, out, end ) == MS_FAILURE
1025-
|| msProjectPoint( in, out, start ) == MS_FAILURE )
1023+
if( msProjectPointEx( reprojector, end ) == MS_FAILURE
1024+
|| msProjectPointEx( reprojector, start ) == MS_FAILURE )
10261025
return MS_FAILURE;
10271026
else
10281027
return MS_SUCCESS;
@@ -1126,7 +1125,7 @@ msProjectShapeLine(reprojectionObj* reprojector,
11261125
dist = wrkPoint.x - pt1Geo.x;
11271126
if( fabs(dist) > 180.0
11281127
&& msTestNeedWrap( thisPoint, lastPoint,
1129-
pt1Geo, in, out ) ) {
1128+
pt1Geo, reprojector ) ) {
11301129
if( dist > 0.0 )
11311130
wrkPoint.x -= 360.0;
11321131
else if( dist < 0.0 )
@@ -1150,7 +1149,7 @@ msProjectShapeLine(reprojectionObj* reprojector,
11501149

11511150
startPoint = lastPoint;
11521151
endPoint = thisPoint;
1153-
if( msProjectSegment( in, out, &startPoint, &endPoint )
1152+
if( msProjectSegment( reprojector, &startPoint, &endPoint )
11541153
== MS_SUCCESS ) {
11551154
line_out->point[line_out->numpoints++] = endPoint;
11561155
}
@@ -1181,7 +1180,7 @@ msProjectShapeLine(reprojectionObj* reprojector,
11811180

11821181
startPoint = lastPoint;
11831182
endPoint = thisPoint;
1184-
if( msProjectSegment( in, out, &endPoint, &startPoint )
1183+
if( msProjectSegment( reprojector, &endPoint, &startPoint )
11851184
== MS_SUCCESS ) {
11861185
lineObj newLine;
11871186

@@ -1382,7 +1381,7 @@ int msProjectLineEx(reprojectionObj* reprojector, lineObj *line)
13821381
dist = line->point[i].x - line->point[0].x;
13831382
if( fabs(dist) > 180.0 ) {
13841383
if( msTestNeedWrap( thisPoint, startPoint,
1385-
line->point[0], reprojector->in, reprojector->out ) ) {
1384+
line->point[0], reprojector ) ) {
13861385
if( dist > 0.0 ) {
13871386
line->point[i].x -= 360.0;
13881387
} else if( dist < 0.0 ) {
@@ -2125,18 +2124,17 @@ reprojected to geographic space. However, it does not:
21252124

21262125
#ifdef USE_PROJ
21272126
static int msTestNeedWrap( pointObj pt1, pointObj pt2, pointObj pt2_geo,
2128-
projectionObj *in,
2129-
projectionObj *out )
2127+
reprojectionObj* reprojector )
21302128

21312129
{
21322130
pointObj middle;
21332131

21342132
middle.x = (pt1.x + pt2.x) * 0.5;
21352133
middle.y = (pt1.y + pt2.y) * 0.5;
21362134

2137-
if( msProjectPoint( in, out, &pt1 ) == MS_FAILURE
2138-
|| msProjectPoint( in, out, &pt2 ) == MS_FAILURE
2139-
|| msProjectPoint( in, out, &middle ) == MS_FAILURE )
2135+
if( msProjectPointEx( reprojector, &pt1 ) == MS_FAILURE
2136+
|| msProjectPointEx( reprojector, &pt2 ) == MS_FAILURE
2137+
|| msProjectPointEx( reprojector, &middle ) == MS_FAILURE )
21402138
return 0;
21412139

21422140
/*

0 commit comments

Comments
 (0)