Skip to content
Permalink
Browse files
PROJ6: do more projection context sharing
  • Loading branch information
rouault committed Oct 1, 2019
1 parent 1ca010b commit 5f6ebabf50eb9a086edc31d2b92b4fafaad83f7c
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 13 deletions.
@@ -425,6 +425,7 @@ int FLTApplySimpleSQLFilter(FilterEncodingNode *psNode, mapObj *map, int iLayerI
szEPSG = FLTGetBBOX(psNode, &sQueryRect);
if(szEPSG && map->projection.numargs > 0) {
msInitProjection(&sProjTmp);
msProjectionInheritContextFrom(&sProjTmp, &map->projection);
/* Use the non EPSG variant since axis swapping is done in FLTDoAxisSwappingIfNecessary */
if (msLoadProjectionString(&sProjTmp, szEPSG) == 0) {
msProjectRect(&sProjTmp, &map->projection, &sQueryRect);
@@ -768,6 +769,7 @@ int FLTLayerApplyPlainFilterToLayer(FilterEncodingNode *psNode, mapObj *map,
if(pszEPSG && map->projection.numargs > 0) {
projectionObj sProjTmp;
msInitProjection(&sProjTmp);
msProjectionInheritContextFrom(&sProjTmp, &map->projection);
/* Use the non EPSG variant since axis swapping is done in FLTDoAxisSwappingIfNecessary */
if (msLoadProjectionString(&sProjTmp, pszEPSG) == 0) {
rectObj oldRect = rect;
@@ -2923,11 +2925,15 @@ int FLTParseGMLEnvelope(CPLXMLNode *psRoot, rectObj *psBbox, char **ppszSRS)
/* FLTNeedSRSSwapping */
/************************************************************************/

static int FLTNeedSRSSwapping( const char* pszSRS )
static int FLTNeedSRSSwapping( mapObj *map, const char* pszSRS )
{
int bNeedSwapping = MS_FALSE;
projectionObj sProjTmp;
msInitProjection(&sProjTmp);
if( map )
{
msProjectionInheritContextFrom(&sProjTmp, &map->projection);
}
if (msLoadProjectionStringEPSG(&sProjTmp, pszSRS) == 0) {
bNeedSwapping = msIsAxisInvertedProj(&sProjTmp);
}
@@ -2944,7 +2950,8 @@ static int FLTNeedSRSSwapping( const char* pszSRS )
/* caller will have to determine its value from a more general */
/* context. */
/************************************************************************/
void FLTDoAxisSwappingIfNecessary(FilterEncodingNode *psFilterNode,
void FLTDoAxisSwappingIfNecessary(mapObj *map,
FilterEncodingNode *psFilterNode,
int bDefaultSRSNeedsAxisSwapping)
{
if( psFilterNode == NULL )
@@ -2955,7 +2962,7 @@ void FLTDoAxisSwappingIfNecessary(FilterEncodingNode *psFilterNode,
{
rectObj* rect = (rectObj *)psFilterNode->psRightNode->pOther;
const char* pszSRS = psFilterNode->pszSRS;
if( (pszSRS != NULL && FLTNeedSRSSwapping(pszSRS)) ||
if( (pszSRS != NULL && FLTNeedSRSSwapping(map, pszSRS)) ||
(pszSRS == NULL && bDefaultSRSNeedsAxisSwapping) )
{
double tmp;
@@ -2974,16 +2981,16 @@ void FLTDoAxisSwappingIfNecessary(FilterEncodingNode *psFilterNode,
{
shapeObj* shape = (shapeObj *)(psFilterNode->psRightNode->pOther);
const char* pszSRS = psFilterNode->pszSRS;
if( (pszSRS != NULL && FLTNeedSRSSwapping(pszSRS)) ||
if( (pszSRS != NULL && FLTNeedSRSSwapping(map, pszSRS)) ||
(pszSRS == NULL && bDefaultSRSNeedsAxisSwapping) )
{
msAxisSwapShape(shape);
}
}
else
{
FLTDoAxisSwappingIfNecessary(psFilterNode->psLeftNode, bDefaultSRSNeedsAxisSwapping);
FLTDoAxisSwappingIfNecessary(psFilterNode->psRightNode, bDefaultSRSNeedsAxisSwapping);
FLTDoAxisSwappingIfNecessary(map, psFilterNode->psLeftNode, bDefaultSRSNeedsAxisSwapping);
FLTDoAxisSwappingIfNecessary(map, psFilterNode->psRightNode, bDefaultSRSNeedsAxisSwapping);
}
}

@@ -130,7 +130,7 @@ MS_DLL_EXPORT int FLTApplyFilterToLayerCommonExpression(mapObj *map, int iLayerI
MS_DLL_EXPORT xmlNodePtr FLTGetCapabilities(xmlNsPtr psNsParent, xmlNsPtr psNsOgc, int bTemporal);
#endif

void FLTDoAxisSwappingIfNecessary(FilterEncodingNode *psFilterNode, int bDefaultSRSNeedsAxisSwapping);
void FLTDoAxisSwappingIfNecessary(mapObj *map, FilterEncodingNode *psFilterNode, int bDefaultSRSNeedsAxisSwapping);

void FLTPreParseFilterForAliasAndGroup(FilterEncodingNode *psFilterNode,
mapObj *map, int i, const char *namespaces);
@@ -517,8 +517,10 @@ char *FLTGetSpatialComparisonCommonExpression(FilterEncodingNode *psNode, layerO
fabs(sQueryRect.maxy - 90.0) < 1e-5)
{
if (lp->projection.numargs > 0) {
if (psNode->pszSRS)
if (psNode->pszSRS) {
msInitProjection(&sProjTmp);
msProjectionInheritContextFrom(&sProjTmp, &lp->projection);
}
if (psNode->pszSRS) {
/* Use the non EPSG variant since axis swapping is done in FLTDoAxisSwappingIfNecessary */
if (msLoadProjectionString(&sProjTmp, psNode->pszSRS) == 0) {
@@ -567,8 +569,10 @@ char *FLTGetSpatialComparisonCommonExpression(FilterEncodingNode *psNode, layerO
** target is layer projection
*/
if (!bAlreadyReprojected && lp->projection.numargs > 0) {
if (psNode->pszSRS)
if (psNode->pszSRS) {
msInitProjection(&sProjTmp);
msProjectionInheritContextFrom(&sProjTmp, &lp->projection);
}
if (psNode->pszSRS) {
/* Use the non EPSG variant since axis swapping is done in FLTDoAxisSwappingIfNecessary */
if (msLoadProjectionString(&sProjTmp, psNode->pszSRS) == 0) {
@@ -2122,6 +2122,7 @@ this request. Check sos/ows_enable_request settings.", "msSOSGetObservation()",

/* project MAP.EXTENT to this SRS */
msInitProjection(&po);
msProjectionInheritContextFrom(&po, &map->projection);

snprintf(srsbuffer, sizeof(srsbuffer), "+init=epsg:%.20s", sosparams->pszSrsName+strlen("EPSG:"));

@@ -495,6 +495,8 @@ void msFreeProjection(projectionObj *p)
#endif
#endif

p->gt.need_geotransform = MS_FALSE;
p->wellknownprojection = wkp_none;
msFreeCharArray(p->args, p->numargs);
p->args = NULL;
p->numargs = 0;
@@ -1974,6 +1974,7 @@ int msTiledSHPOpenFile(layerObj *layer)
tSHP = (msTiledSHPLayerInfo *) calloc(1, sizeof(msTiledSHPLayerInfo));
MS_CHECK_ALLOC(tSHP, sizeof(msTiledSHPLayerInfo), MS_FAILURE);
msInitProjection(&(tSHP->sTileProj));
msProjectionInheritContextFrom(&(tSHP->sTileProj), &layer->projection);

tSHP->shpfile = (shapefileObj *) malloc(sizeof(shapefileObj));
if (tSHP->shpfile == NULL) {
@@ -1458,6 +1458,7 @@ static int processExtentTag(mapservObj *mapserv, char **line, char *name, rectOb
} else if(rectProj && projectionString) {
projectionObj projection;
msInitProjection(&projection);
msProjectionInheritContextFrom(&projection, &mapserv->map->projection);

if(MS_SUCCESS != msLoadProjectionString(&projection, projectionString)) return MS_FAILURE;

@@ -1756,6 +1757,7 @@ static int processShplabelTag(layerObj *layer, char **line, shapeObj *origshape)
} else if(projectionString) {
projectionObj projection;
msInitProjection(&projection);
msProjectionInheritContextFrom(&projection, &layer->map->projection);

status = msLoadProjectionString(&projection, projectionString);
if(status != MS_SUCCESS) return MS_FAILURE;
@@ -2161,6 +2163,7 @@ static int processShpxyTag(layerObj *layer, char **line, shapeObj *shape)
} else if(projectionString) {
projectionObj projection;
msInitProjection(&projection);
msProjectionInheritContextFrom(&projection, &(layer->projection));

status = msLoadProjectionString(&projection, projectionString);
if(status != MS_SUCCESS) return MS_FAILURE;
@@ -1770,6 +1770,7 @@ static int msWCSGetCoverage(mapObj *map, cgiRequestObj *request,
projectionObj proj;

msInitProjection( &proj );
msProjectionInheritContextFrom(&proj, &(map->projection));
if( msLoadProjectionString( &proj, (char *) params->crs ) == 0 ) {
msAxisNormalizePoints( &proj, 1,
&(params->bbox.minx),
@@ -1958,6 +1959,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage()", par
projectionObj tmp_proj;

msInitProjection(&tmp_proj);
msProjectionInheritContextFrom(&tmp_proj, &(map->projection));
if (msLoadProjectionString(&tmp_proj, (char *) params->crs) != 0) {
msWCSFreeCoverageMetadata(&cm);
return msWCSException( map, NULL, NULL, params->version);
@@ -2803,6 +2805,7 @@ int msWCSGetCoverageMetadata( layerObj *layer, coverageMetadataObj *cm )
char projstring[32];

msInitProjection(&proj); /* or bad things happen */
msProjectionInheritContextFrom(&proj, &(layer->map->projection));

snprintf(projstring, sizeof(projstring), "init=epsg:%.20s", cm->srs_epsg+5);
if (msLoadProjectionString(&proj, projstring) != 0) return MS_FAILURE;
@@ -728,6 +728,7 @@ msWCSDescribeCoverage_CoverageDescription11(
double resy = cm.geotransform[5];

msInitProjection( &proj );
msProjectionInheritContextFrom(&proj, &(layer->projection));
if( msLoadProjectionString( &proj, cm.srs_urn ) == 0 ) {
msAxisNormalizePoints( &proj, 1, &x0, &y0 );
msAxisNormalizePoints( &proj, 1, &resx, &resy );
@@ -4383,6 +4383,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p
/************************************************************************/

msInitProjection(&imageProj);
msProjectionInheritContextFrom(&imageProj, &(layer->projection));
if (msLoadProjectionString(&imageProj, cm.srs_epsg) == -1) {
msFreeProjection(&imageProj);
msWCSClearCoverageMetadata20(&cm);
@@ -4474,6 +4475,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p

/* if the subsets have a crs given, project the image extent to it */
msInitProjection(&subsetProj);
msProjectionInheritContextFrom(&subsetProj, &(layer->projection));
if(msLoadProjectionString(&subsetProj, params->subsetcrs) != MS_SUCCESS) {
msFreeProjection(&subsetProj);
msFreeProjection(&imageProj);
@@ -4625,6 +4627,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p
projectionObj outputProj;

msInitProjection(&outputProj);
msProjectionInheritContextFrom(&outputProj, &(layer->projection));
if(msLoadProjectionString(&outputProj, params->outputcrs) == -1) {
msFreeProjection(&outputProj);
msWCSClearCoverageMetadata20(&cm);
@@ -379,6 +379,7 @@ static int msWFSGetFeatureApplySRS(mapObj *map, const char *srs, int nWFSVersion
if(pszMapSRS && nWFSVersion > OWS_1_0_0){
projectionObj proj;
msInitProjection(&proj);
msProjectionInheritContextFrom(&proj, &(map->projection));
if (map->projection.numargs > 0 && msLoadProjectionStringEPSG(&proj, pszMapSRS) == 0) {
msProjectRect(&(map->projection), &proj, &map->extent);
}
@@ -471,6 +472,7 @@ static int msWFSGetFeatureApplySRS(mapObj *map, const char *srs, int nWFSVersion
int nTmp=0;

msInitProjection(&sProjTmp);
msProjectionInheritContextFrom(&sProjTmp, &(map->projection));
if( nWFSVersion >= OWS_1_1_0 ) {
nTmp = msLoadProjectionStringEPSG(&(sProjTmp), pszOutputSRS);
} else {
@@ -604,6 +606,7 @@ int msWFSDumpLayer(mapObj *map, layerObj *lp, const char *script_url_encoded)
/* If layer has no proj set then use map->proj for bounding box. */
if (msOWSGetLayerExtent(map, lp, "FO", &ext) == MS_SUCCESS) {
msInitProjection(&poWfs);
msProjectionInheritContextFrom(&poWfs, &(map->projection));
if (pszWfsSrs != NULL)
msLoadProjectionString(&(poWfs), pszWfsSrs);

@@ -2081,7 +2084,7 @@ static int msWFSRunFilter(mapObj* map,
bDefaultSRSNeedsAxisSwapping = msIsAxisInverted(atoi(srs+5));
}
msFree(srs);
FLTDoAxisSwappingIfNecessary(psNode, bDefaultSRSNeedsAxisSwapping);
FLTDoAxisSwappingIfNecessary(map, psNode, bDefaultSRSNeedsAxisSwapping);
}

layerWasOpened = msLayerIsOpen(lp);
@@ -2548,6 +2551,7 @@ this request. Check wfs/ows_enable_request settings.", "msWFSGetFeature()",
projectionObj sProjTmp;

msInitProjection(&sProjTmp);
msProjectionInheritContextFrom(&sProjTmp, &(map->projection));
msOWSGetEPSGProj(&sProjTmp,&(map->web.metadata),"FO",MS_TRUE, &sBBoxSrs);
msFreeProjection(&sProjTmp);
}
@@ -2557,6 +2561,7 @@ this request. Check wfs/ows_enable_request settings.", "msWFSGetFeature()",
projectionObj sProjTmp;

msInitProjection(&sProjTmp);
msProjectionInheritContextFrom(&sProjTmp, &(map->projection));
/*do the axis order for now. It is unclear if the bbox are expected
ro respect the axis oder defined in the projectsion #3296*/

@@ -405,7 +405,7 @@ int msWMSApplyFilter(mapObj *map, int version, const char *filter,
* elements inside the filter(s)
*/
if (version >= OWS_1_3_0)
FLTDoAxisSwappingIfNecessary(psNode, def_srs_needs_axis_swap);
FLTDoAxisSwappingIfNecessary(map, psNode, def_srs_needs_axis_swap);

#ifdef do_we_need_this
FLTProcessPropertyIsNull(psNode, map, lp->index);
@@ -1335,6 +1335,7 @@ int msWMSLoadGetMapParams(mapObj *map, int nVersion,
/*try to adjust the axes if necessary*/
if (strlen(srsbuffer) > 1) {
msInitProjection(&proj);
msProjectionInheritContextFrom(&proj, &(map->projection));
if (msLoadProjectionStringEPSG(&proj, (char *)srsbuffer) == 0 &&
(need_axis_swap = msIsAxisInvertedProj(&proj) ) ) {
msAxisNormalizePoints( &proj, 1, &rect.minx, &rect.miny );
@@ -1610,6 +1611,7 @@ this request. Check wms/ows_enable_request settings.",
}

msInitProjection(&newProj);
msProjectionInheritContextFrom(&newProj, &map->projection);
if (strlen(srsbuffer) > 1) {
int nTmp;

@@ -1634,8 +1636,7 @@ this request. Check wms/ows_enable_request settings.",
/* that the srs given as parameter is valid for all layers */
if (strlen(srsbuffer) > 1) {
int nTmp;
msFreeProjection(&map->projection);
msInitProjection(&map->projection);
msFreeProjectionExceptContext(&map->projection);
if (nVersion >= OWS_1_3_0)
nTmp = msLoadProjectionStringEPSG(&(map->projection), srsbuffer);
else

0 comments on commit 5f6ebab

Please sign in to comment.