Skip to content

Commit c3afefd

Browse files
committed
More uses of msProjectShapeEx()
1 parent 680e7e0 commit c3afefd

File tree

4 files changed

+149
-22
lines changed

4 files changed

+149
-22
lines changed

mapgml.c

+49-5
Original file line numberDiff line numberDiff line change
@@ -1430,12 +1430,13 @@ int msGMLWriteQuery(mapObj *map, char *filename, const char *namespaces)
14301430
char *pszOutputSRS = NULL;
14311431
int nSRSDimension = 2;
14321432
const char* geomtype;
1433-
14341433
lp = (GET_LAYER(map, map->layerorder[i]));
14351434

14361435
if(lp->resultcache && lp->resultcache->numresults > 0) { /* found results */
14371436

14381437
#ifdef USE_PROJ
1438+
reprojectionObj* reprojector = NULL;
1439+
14391440
/* Determine output SRS, if map has none, then try using layer's native SRS */
14401441
if ((pszOutputSRS = pszMapSRS) == NULL) {
14411442
msOWSGetEPSGProj(&(lp->projection), NULL, namespaces, MS_TRUE, &pszOutputSRS);
@@ -1478,22 +1479,39 @@ int msGMLWriteQuery(mapObj *map, char *filename, const char *namespaces)
14781479
return MS_FAILURE;
14791480
}
14801481

1482+
#ifdef USE_PROJ
1483+
if(pszOutputSRS == pszMapSRS && msProjectionsDiffer(&(lp->projection), &(map->projection))) {
1484+
reprojector = msProjectCreateReprojector(&(lp->projection), &(map->projection));
1485+
if( reprojector == NULL ) {
1486+
msGMLFreeGroups(groupList);
1487+
msGMLFreeConstants(constantList);
1488+
msGMLFreeItems(itemList);
1489+
msGMLFreeGeometries(geometryList);
1490+
return MS_FAILURE;
1491+
}
1492+
}
1493+
#endif
1494+
14811495
for(j=0; j<lp->resultcache->numresults; j++) {
14821496
status = msLayerGetShape(lp, &shape, &(lp->resultcache->results[j]));
14831497
if(status != MS_SUCCESS) {
14841498
msGMLFreeGroups(groupList);
14851499
msGMLFreeConstants(constantList);
14861500
msGMLFreeItems(itemList);
14871501
msGMLFreeGeometries(geometryList);
1502+
#ifdef USE_PROJ
1503+
msProjectDestroyReprojector(reprojector);
1504+
#endif
14881505
return(status);
14891506
}
14901507

14911508
#ifdef USE_PROJ
14921509
/* project the shape into the map projection (if necessary), note that this projects the bounds as well */
1493-
if(pszOutputSRS == pszMapSRS && msProjectionsDiffer(&(lp->projection), &(map->projection))) {
1494-
status = msProjectShape(&lp->projection, &map->projection, &shape);
1510+
if(reprojector) {
1511+
status = msProjectShapeEx(reprojector, &shape);
14951512
if(status != MS_SUCCESS) {
14961513
msIO_fprintf(stream, "<!-- Warning: Failed to reproject shape: %s -->\n",msGetErrorString(","));
1514+
msFreeShape(&shape);
14971515
continue;
14981516
}
14991517
}
@@ -1543,6 +1561,10 @@ int msGMLWriteQuery(mapObj *map, char *filename, const char *namespaces)
15431561
msFreeShape(&shape); /* init too */
15441562
}
15451563

1564+
#ifdef USE_PROJ
1565+
msProjectDestroyReprojector(reprojector);
1566+
#endif
1567+
15461568
/* end this collection (layer) */
15471569
/* if no layer name provided fall back on the layer name + "_layer" */
15481570
value = (char*) msSmallMalloc(strlen(lp->name)+7);
@@ -1668,6 +1690,9 @@ int msGMLWriteWFSQuery(mapObj *map, FILE *stream, const char *default_namespace_
16681690
int bOutputGMLIdOnly = MS_FALSE;
16691691
int nSRSDimension = 2;
16701692
const char* geomtype;
1693+
#ifdef USE_PROJ
1694+
reprojectionObj* reprojector = NULL;
1695+
#endif
16711696

16721697
/* setup namespace, a layer can override the default */
16731698
namespace_prefix = msOWSLookupMetadata(&(lp->metadata), "OFG", "namespace_prefix");
@@ -1740,6 +1765,18 @@ int msGMLWriteWFSQuery(mapObj *map, FILE *stream, const char *default_namespace_
17401765
if (!srs)
17411766
msOWSGetEPSGProj(&(lp->projection), &(lp->metadata), "FGO", MS_TRUE, &srs);
17421767
}
1768+
1769+
if(msProjectionsDiffer(&(lp->projection), &(map->projection))) {
1770+
reprojector = msProjectCreateReprojector(&(lp->projection), &(map->projection));
1771+
if( reprojector == NULL ) {
1772+
msGMLFreeGroups(groupList);
1773+
msGMLFreeConstants(constantList);
1774+
msGMLFreeItems(itemList);
1775+
msGMLFreeGeometries(geometryList);
1776+
msFree(layerName);
1777+
return MS_FAILURE;
1778+
}
1779+
}
17431780
#endif
17441781

17451782
for(j=0; j<lp->resultcache->numresults; j++) {
@@ -1759,14 +1796,17 @@ int msGMLWriteWFSQuery(mapObj *map, FILE *stream, const char *default_namespace_
17591796
msGMLFreeItems(itemList);
17601797
msGMLFreeGeometries(geometryList);
17611798
msFree(layerName);
1799+
#ifdef USE_PROJ
1800+
msProjectDestroyReprojector(reprojector);
1801+
#endif
17621802
return(status);
17631803
}
17641804
}
17651805

17661806
#ifdef USE_PROJ
17671807
/* project the shape into the map projection (if necessary), note that this projects the bounds as well */
1768-
if(msProjectionsDiffer(&(lp->projection), &(map->projection)))
1769-
msProjectShape(&lp->projection, &map->projection, &shape);
1808+
if(reprojector)
1809+
msProjectShapeEx(reprojector, &shape);
17701810
#endif
17711811

17721812
if(featureIdIndex != -1) {
@@ -1854,6 +1894,10 @@ int msGMLWriteWFSQuery(mapObj *map, FILE *stream, const char *default_namespace_
18541894
msFreeShape(&shape); /* init too */
18551895
}
18561896

1897+
#ifdef USE_PROJ
1898+
msProjectDestroyReprojector(reprojector);
1899+
#endif
1900+
18571901
msFree(srs);
18581902

18591903
/* done with this layer, do a little clean-up */

mapquery.c

+76-14
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,8 @@ int msQueryByFilter(mapObj *map)
766766
start = stop = map->query.layer;
767767

768768
for(l=start; l>=stop; l--) {
769+
reprojectionObj* reprojector = NULL;
770+
769771
lp = (GET_LAYER(map, l));
770772
if (map->query.maxfeatures == 0)
771773
break; /* nothing else to do */
@@ -941,8 +943,17 @@ int msQueryByFilter(mapObj *map)
941943
}
942944

943945
#ifdef USE_PROJ
944-
if(lp->project)
945-
msProjectShape(&(lp->projection), &(map->projection), &shape);
946+
if(lp->project) {
947+
if( reprojector == NULL ) {
948+
reprojector = msProjectCreateReprojector(&(lp->projection), &(map->projection));
949+
if( reprojector == NULL ) {
950+
msFreeShape(&shape);
951+
status = MS_FAILURE;
952+
break;
953+
}
954+
}
955+
msProjectShapeEx(reprojector, &shape);
956+
}
946957
#endif
947958

948959
/* Should we skip this feature? */
@@ -976,6 +987,8 @@ int msQueryByFilter(mapObj *map)
976987
msCopyExpression(&lp->filter, &old_filter); /* restore old filter */
977988
msFreeExpression(&old_filter);
978989

990+
msProjectDestroyReprojector(reprojector);
991+
979992
if(status != MS_DONE) goto query_error;
980993
if(!map->query.only_cache_result_count && lp->resultcache->numresults == 0)
981994
msLayerClose(lp); /* no need to keep the layer open */
@@ -1034,6 +1047,7 @@ int msQueryByRect(mapObj *map)
10341047
start = stop = map->query.layer;
10351048

10361049
for(l=start; l>=stop; l--) {
1050+
reprojectionObj* reprojector = NULL;
10371051
lp = (GET_LAYER(map, l));
10381052
/* Set the global maxfeatures */
10391053
if (map->query.maxfeatures == 0)
@@ -1220,8 +1234,17 @@ int msQueryByRect(mapObj *map)
12201234
}
12211235

12221236
#ifdef USE_PROJ
1223-
if(lp->project)
1224-
msProjectShape(&(lp->projection), &(map->projection), &shape);
1237+
if(lp->project) {
1238+
if( reprojector == NULL ) {
1239+
reprojector = msProjectCreateReprojector(&(lp->projection), &(map->projection));
1240+
if( reprojector == NULL ) {
1241+
msFreeShape(&shape);
1242+
status = MS_FAILURE;
1243+
break;
1244+
}
1245+
}
1246+
msProjectShapeEx(reprojector, &shape);
1247+
}
12251248
#endif
12261249

12271250
if(msRectContained(&shape.bounds, &searchrectInMapProj) == MS_TRUE) { /* if the whole shape is in, don't intersect */
@@ -1268,6 +1291,8 @@ int msQueryByRect(mapObj *map)
12681291
if (classgroup)
12691292
msFree(classgroup);
12701293

1294+
msProjectDestroyReprojector(reprojector);
1295+
12711296
if(status != MS_DONE) {
12721297
msFreeShape(&searchshape);
12731298
return(MS_FAILURE);
@@ -1348,6 +1373,7 @@ int msQueryByFeatures(mapObj *map)
13481373
msInitShape(&selectshape);
13491374

13501375
for(l=start; l>=stop; l--) {
1376+
reprojectionObj* reprojector = NULL;
13511377
if(l == map->query.slayer) continue; /* skip the selection layer */
13521378

13531379
lp = (GET_LAYER(map, l));
@@ -1495,8 +1521,17 @@ int msQueryByFeatures(mapObj *map)
14951521
}
14961522

14971523
#ifdef USE_PROJ
1498-
if(lp->project)
1499-
msProjectShape(&(lp->projection), &(map->projection), &shape);
1524+
if(lp->project) {
1525+
if( reprojector == NULL ) {
1526+
reprojector = msProjectCreateReprojector(&(lp->projection), &(map->projection));
1527+
if( reprojector == NULL ) {
1528+
msFreeShape(&shape);
1529+
status = MS_FAILURE;
1530+
break;
1531+
}
1532+
}
1533+
msProjectShapeEx(reprojector, &shape);
1534+
}
15001535
#endif
15011536

15021537
switch(selectshape.type) { /* may eventually support types other than polygon on line */
@@ -1588,9 +1623,12 @@ int msQueryByFeatures(mapObj *map)
15881623
if (classgroup)
15891624
msFree(classgroup);
15901625

1591-
if(status != MS_DONE) return(MS_FAILURE);
1626+
msProjectDestroyReprojector(reprojector);
15921627

15931628
msFreeShape(&selectshape);
1629+
1630+
if(status != MS_DONE) return(MS_FAILURE);
1631+
15941632
} /* next selection shape */
15951633

15961634
if(lp->resultcache->numresults == 0) msLayerClose(lp); /* no need to keep the layer open */
@@ -1655,6 +1693,7 @@ int msQueryByPoint(mapObj *map)
16551693
start = stop = map->query.layer;
16561694

16571695
for(l=start; l>=stop; l--) {
1696+
reprojectionObj* reprojector = NULL;
16581697
lp = (GET_LAYER(map, l));
16591698
if (map->query.maxfeatures == 0)
16601699
break; /* nothing else to do */
@@ -1782,8 +1821,17 @@ int msQueryByPoint(mapObj *map)
17821821
}
17831822

17841823
#ifdef USE_PROJ
1785-
if(lp->project)
1786-
msProjectShape(&(lp->projection), &(map->projection), &shape);
1824+
if(lp->project) {
1825+
if( reprojector == NULL ) {
1826+
reprojector = msProjectCreateReprojector(&(lp->projection), &(map->projection));
1827+
if( reprojector == NULL ) {
1828+
msFreeShape(&shape);
1829+
status = MS_FAILURE;
1830+
break;
1831+
}
1832+
}
1833+
msProjectShapeEx(reprojector, &shape);
1834+
}
17871835
#endif
17881836

17891837
d = msDistancePointToShape(&(map->query.point), &shape);
@@ -1823,6 +1871,8 @@ int msQueryByPoint(mapObj *map)
18231871
if (classgroup)
18241872
msFree(classgroup);
18251873

1874+
msProjectDestroyReprojector(reprojector);
1875+
18261876
if(status != MS_DONE) return(MS_FAILURE);
18271877

18281878
if(lp->resultcache->numresults == 0) msLayerClose(lp); /* no need to keep the layer open */
@@ -1882,6 +1932,7 @@ int msQueryByShape(mapObj *map)
18821932
msComputeBounds(qshape); /* make sure an accurate extent exists */
18831933

18841934
for(l=start; l>=stop; l--) { /* each layer */
1935+
reprojectionObj* reprojector = NULL;
18851936
lp = (GET_LAYER(map, l));
18861937
if (map->query.maxfeatures == 0)
18871938
break; /* nothing else to do */
@@ -2005,8 +2056,17 @@ int msQueryByShape(mapObj *map)
20052056
}
20062057

20072058
#ifdef USE_PROJ
2008-
if(lp->project)
2009-
msProjectShape(&(lp->projection), &(map->projection), &shape);
2059+
if(lp->project) {
2060+
if( reprojector == NULL ) {
2061+
reprojector = msProjectCreateReprojector(&(lp->projection), &(map->projection));
2062+
if( reprojector == NULL ) {
2063+
msFreeShape(&shape);
2064+
status = MS_FAILURE;
2065+
break;
2066+
}
2067+
}
2068+
msProjectShapeEx(reprojector, &shape);
2069+
}
20102070
#endif
20112071

20122072
switch(qshape->type) { /* may eventually support types other than polygon or line */
@@ -2100,14 +2160,16 @@ int msQueryByShape(mapObj *map)
21002160
}
21012161
} /* next shape */
21022162

2163+
free(classgroup);
2164+
classgroup = NULL;
2165+
2166+
msProjectDestroyReprojector(reprojector);
2167+
21032168
if(status != MS_DONE) {
2104-
free(classgroup);
21052169
return(MS_FAILURE);
21062170
}
21072171

21082172
if(lp->resultcache->numresults == 0) msLayerClose(lp); /* no need to keep the layer open */
2109-
free(classgroup);
2110-
classgroup = NULL;
21112173
} /* next layer */
21122174

21132175
/* was anything found? */

mapshape.c

+23-3
Original file line numberDiff line numberDiff line change
@@ -1930,6 +1930,9 @@ static const char* msTiledSHPLoadEntry(layerObj *layer, int i, char* tilename, s
19301930
const char* filename;
19311931
msTiledSHPLayerInfo *tSHP= layer->layerinfo;
19321932

1933+
msProjectDestroyReprojector(tSHP->reprojectorFromTileProjToLayerProj);
1934+
tSHP->reprojectorFromTileProjToLayerProj = NULL;
1935+
19331936
msFreeProjection(&(tSHP->sTileProj));
19341937
if( layer->tilesrs != NULL )
19351938
{
@@ -1968,7 +1971,7 @@ int msTiledSHPOpenFile(layerObj *layer)
19681971
return MS_FAILURE;
19691972

19701973
/* allocate space for a shapefileObj using layer->layerinfo */
1971-
tSHP = (msTiledSHPLayerInfo *) malloc(sizeof(msTiledSHPLayerInfo));
1974+
tSHP = (msTiledSHPLayerInfo *) calloc(1, sizeof(msTiledSHPLayerInfo));
19721975
MS_CHECK_ALLOC(tSHP, sizeof(msTiledSHPLayerInfo), MS_FAILURE);
19731976
msInitProjection(&(tSHP->sTileProj));
19741977

@@ -2328,7 +2331,14 @@ int msTiledSHPNextShape(layerObj *layer, shapeObj *shape)
23282331
#ifdef USE_PROJ
23292332
if( tSHP->sTileProj.numargs > 0 )
23302333
{
2331-
msProjectShape( &(tSHP->sTileProj), &(layer->projection), shape);
2334+
if( tSHP->reprojectorFromTileProjToLayerProj == NULL )
2335+
{
2336+
tSHP->reprojectorFromTileProjToLayerProj = msProjectCreateReprojector(&(tSHP->sTileProj), &(layer->projection));
2337+
}
2338+
if( tSHP->reprojectorFromTileProjToLayerProj )
2339+
{
2340+
msProjectShapeEx( tSHP->reprojectorFromTileProjToLayerProj, shape);
2341+
}
23322342
}
23332343
#endif
23342344

@@ -2400,7 +2410,14 @@ int msTiledSHPGetShape(layerObj *layer, shapeObj *shape, resultObj *record)
24002410
#ifdef USE_PROJ
24012411
if( tSHP->sTileProj.numargs > 0 )
24022412
{
2403-
msProjectShape( &(tSHP->sTileProj), &(layer->projection), shape);
2413+
if( tSHP->reprojectorFromTileProjToLayerProj == NULL )
2414+
{
2415+
tSHP->reprojectorFromTileProjToLayerProj = msProjectCreateReprojector(&(tSHP->sTileProj), &(layer->projection));
2416+
}
2417+
if( tSHP->reprojectorFromTileProjToLayerProj )
2418+
{
2419+
msProjectShapeEx( tSHP->reprojectorFromTileProjToLayerProj, shape);
2420+
}
24042421
}
24052422
#endif
24062423

@@ -2435,6 +2452,9 @@ void msTiledSHPClose(layerObj *layer)
24352452
msShapefileClose(tSHP->tileshpfile);
24362453
free(tSHP->tileshpfile);
24372454
}
2455+
2456+
msProjectDestroyReprojector(tSHP->reprojectorFromTileProjToLayerProj);
2457+
24382458
msFreeProjection(&(tSHP->sTileProj));
24392459

24402460
free(tSHP);

mapshape.h

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ extern "C" {
181181
int tilelayerindex;
182182
projectionObj sTileProj;
183183
rectObj searchrect;
184+
reprojectionObj* reprojectorFromTileProjToLayerProj;
184185
} msTiledSHPLayerInfo;
185186

186187
/* shapefileObj function prototypes */

0 commit comments

Comments
 (0)