Skip to content
Permalink
Browse files
More uses of msProjectShapeEx()
  • Loading branch information
rouault committed Oct 1, 2019
1 parent 680e7e0 commit c3afefdafa8aa22f91572ef668ffda98c15cbf15
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 22 deletions.
@@ -1430,12 +1430,13 @@ int msGMLWriteQuery(mapObj *map, char *filename, const char *namespaces)
char *pszOutputSRS = NULL;
int nSRSDimension = 2;
const char* geomtype;

lp = (GET_LAYER(map, map->layerorder[i]));

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

#ifdef USE_PROJ
reprojectionObj* reprojector = NULL;

/* Determine output SRS, if map has none, then try using layer's native SRS */
if ((pszOutputSRS = pszMapSRS) == NULL) {
msOWSGetEPSGProj(&(lp->projection), NULL, namespaces, MS_TRUE, &pszOutputSRS);
@@ -1478,22 +1479,39 @@ int msGMLWriteQuery(mapObj *map, char *filename, const char *namespaces)
return MS_FAILURE;
}

#ifdef USE_PROJ
if(pszOutputSRS == pszMapSRS && msProjectionsDiffer(&(lp->projection), &(map->projection))) {
reprojector = msProjectCreateReprojector(&(lp->projection), &(map->projection));
if( reprojector == NULL ) {
msGMLFreeGroups(groupList);
msGMLFreeConstants(constantList);
msGMLFreeItems(itemList);
msGMLFreeGeometries(geometryList);
return MS_FAILURE;
}
}
#endif

for(j=0; j<lp->resultcache->numresults; j++) {
status = msLayerGetShape(lp, &shape, &(lp->resultcache->results[j]));
if(status != MS_SUCCESS) {
msGMLFreeGroups(groupList);
msGMLFreeConstants(constantList);
msGMLFreeItems(itemList);
msGMLFreeGeometries(geometryList);
#ifdef USE_PROJ
msProjectDestroyReprojector(reprojector);
#endif
return(status);
}

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

#ifdef USE_PROJ
msProjectDestroyReprojector(reprojector);
#endif

/* end this collection (layer) */
/* if no layer name provided fall back on the layer name + "_layer" */
value = (char*) msSmallMalloc(strlen(lp->name)+7);
@@ -1668,6 +1690,9 @@ int msGMLWriteWFSQuery(mapObj *map, FILE *stream, const char *default_namespace_
int bOutputGMLIdOnly = MS_FALSE;
int nSRSDimension = 2;
const char* geomtype;
#ifdef USE_PROJ
reprojectionObj* reprojector = NULL;
#endif

/* setup namespace, a layer can override the default */
namespace_prefix = msOWSLookupMetadata(&(lp->metadata), "OFG", "namespace_prefix");
@@ -1740,6 +1765,18 @@ int msGMLWriteWFSQuery(mapObj *map, FILE *stream, const char *default_namespace_
if (!srs)
msOWSGetEPSGProj(&(lp->projection), &(lp->metadata), "FGO", MS_TRUE, &srs);
}

if(msProjectionsDiffer(&(lp->projection), &(map->projection))) {
reprojector = msProjectCreateReprojector(&(lp->projection), &(map->projection));
if( reprojector == NULL ) {
msGMLFreeGroups(groupList);
msGMLFreeConstants(constantList);
msGMLFreeItems(itemList);
msGMLFreeGeometries(geometryList);
msFree(layerName);
return MS_FAILURE;
}
}
#endif

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

#ifdef USE_PROJ
/* project the shape into the map projection (if necessary), note that this projects the bounds as well */
if(msProjectionsDiffer(&(lp->projection), &(map->projection)))
msProjectShape(&lp->projection, &map->projection, &shape);
if(reprojector)
msProjectShapeEx(reprojector, &shape);
#endif

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

#ifdef USE_PROJ
msProjectDestroyReprojector(reprojector);
#endif

msFree(srs);

/* done with this layer, do a little clean-up */
@@ -766,6 +766,8 @@ int msQueryByFilter(mapObj *map)
start = stop = map->query.layer;

for(l=start; l>=stop; l--) {
reprojectionObj* reprojector = NULL;

lp = (GET_LAYER(map, l));
if (map->query.maxfeatures == 0)
break; /* nothing else to do */
@@ -941,8 +943,17 @@ int msQueryByFilter(mapObj *map)
}

#ifdef USE_PROJ
if(lp->project)
msProjectShape(&(lp->projection), &(map->projection), &shape);
if(lp->project) {
if( reprojector == NULL ) {
reprojector = msProjectCreateReprojector(&(lp->projection), &(map->projection));
if( reprojector == NULL ) {
msFreeShape(&shape);
status = MS_FAILURE;
break;
}
}
msProjectShapeEx(reprojector, &shape);
}
#endif

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

msProjectDestroyReprojector(reprojector);

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

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

#ifdef USE_PROJ
if(lp->project)
msProjectShape(&(lp->projection), &(map->projection), &shape);
if(lp->project) {
if( reprojector == NULL ) {
reprojector = msProjectCreateReprojector(&(lp->projection), &(map->projection));
if( reprojector == NULL ) {
msFreeShape(&shape);
status = MS_FAILURE;
break;
}
}
msProjectShapeEx(reprojector, &shape);
}
#endif

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

msProjectDestroyReprojector(reprojector);

if(status != MS_DONE) {
msFreeShape(&searchshape);
return(MS_FAILURE);
@@ -1348,6 +1373,7 @@ int msQueryByFeatures(mapObj *map)
msInitShape(&selectshape);

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

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

#ifdef USE_PROJ
if(lp->project)
msProjectShape(&(lp->projection), &(map->projection), &shape);
if(lp->project) {
if( reprojector == NULL ) {
reprojector = msProjectCreateReprojector(&(lp->projection), &(map->projection));
if( reprojector == NULL ) {
msFreeShape(&shape);
status = MS_FAILURE;
break;
}
}
msProjectShapeEx(reprojector, &shape);
}
#endif

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

if(status != MS_DONE) return(MS_FAILURE);
msProjectDestroyReprojector(reprojector);

msFreeShape(&selectshape);

if(status != MS_DONE) return(MS_FAILURE);

} /* next selection shape */

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

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

#ifdef USE_PROJ
if(lp->project)
msProjectShape(&(lp->projection), &(map->projection), &shape);
if(lp->project) {
if( reprojector == NULL ) {
reprojector = msProjectCreateReprojector(&(lp->projection), &(map->projection));
if( reprojector == NULL ) {
msFreeShape(&shape);
status = MS_FAILURE;
break;
}
}
msProjectShapeEx(reprojector, &shape);
}
#endif

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

msProjectDestroyReprojector(reprojector);

if(status != MS_DONE) return(MS_FAILURE);

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

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

#ifdef USE_PROJ
if(lp->project)
msProjectShape(&(lp->projection), &(map->projection), &shape);
if(lp->project) {
if( reprojector == NULL ) {
reprojector = msProjectCreateReprojector(&(lp->projection), &(map->projection));
if( reprojector == NULL ) {
msFreeShape(&shape);
status = MS_FAILURE;
break;
}
}
msProjectShapeEx(reprojector, &shape);
}
#endif

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

free(classgroup);
classgroup = NULL;

msProjectDestroyReprojector(reprojector);

if(status != MS_DONE) {
free(classgroup);
return(MS_FAILURE);
}

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

/* was anything found? */
@@ -1930,6 +1930,9 @@ static const char* msTiledSHPLoadEntry(layerObj *layer, int i, char* tilename, s
const char* filename;
msTiledSHPLayerInfo *tSHP= layer->layerinfo;

msProjectDestroyReprojector(tSHP->reprojectorFromTileProjToLayerProj);
tSHP->reprojectorFromTileProjToLayerProj = NULL;

msFreeProjection(&(tSHP->sTileProj));
if( layer->tilesrs != NULL )
{
@@ -1968,7 +1971,7 @@ int msTiledSHPOpenFile(layerObj *layer)
return MS_FAILURE;

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

@@ -2328,7 +2331,14 @@ int msTiledSHPNextShape(layerObj *layer, shapeObj *shape)
#ifdef USE_PROJ
if( tSHP->sTileProj.numargs > 0 )
{
msProjectShape( &(tSHP->sTileProj), &(layer->projection), shape);
if( tSHP->reprojectorFromTileProjToLayerProj == NULL )
{
tSHP->reprojectorFromTileProjToLayerProj = msProjectCreateReprojector(&(tSHP->sTileProj), &(layer->projection));
}
if( tSHP->reprojectorFromTileProjToLayerProj )
{
msProjectShapeEx( tSHP->reprojectorFromTileProjToLayerProj, shape);
}
}
#endif

@@ -2400,7 +2410,14 @@ int msTiledSHPGetShape(layerObj *layer, shapeObj *shape, resultObj *record)
#ifdef USE_PROJ
if( tSHP->sTileProj.numargs > 0 )
{
msProjectShape( &(tSHP->sTileProj), &(layer->projection), shape);
if( tSHP->reprojectorFromTileProjToLayerProj == NULL )
{
tSHP->reprojectorFromTileProjToLayerProj = msProjectCreateReprojector(&(tSHP->sTileProj), &(layer->projection));
}
if( tSHP->reprojectorFromTileProjToLayerProj )
{
msProjectShapeEx( tSHP->reprojectorFromTileProjToLayerProj, shape);
}
}
#endif

@@ -2435,6 +2452,9 @@ void msTiledSHPClose(layerObj *layer)
msShapefileClose(tSHP->tileshpfile);
free(tSHP->tileshpfile);
}

msProjectDestroyReprojector(tSHP->reprojectorFromTileProjToLayerProj);

msFreeProjection(&(tSHP->sTileProj));

free(tSHP);
@@ -181,6 +181,7 @@ extern "C" {
int tilelayerindex;
projectionObj sTileProj;
rectObj searchrect;
reprojectionObj* reprojectorFromTileProjToLayerProj;
} msTiledSHPLayerInfo;

/* shapefileObj function prototypes */

0 comments on commit c3afefd

Please sign in to comment.