Permalink
Browse files

Shapefile (vector layers or tileindex): PROJECTION AUTO in a shapefil…

…e layer now causes reading the .prj file
  • Loading branch information...
rouault committed Jun 30, 2013
1 parent 57012f8 commit e35978e22f28cd62397a3af7434011c3b57a5c7f
Showing with 60 additions and 1 deletion.
  1. +7 −0 mapraster.c
  2. +53 −1 mapshape.c
View
@@ -362,6 +362,13 @@ int msDrawRasterSetupTileLayer(mapObj *map, layerObj *layer,
}
}
if (layer->projection.numargs > 0 &&
EQUAL(layer->projection.args[0], "auto"))
{
tlp->projection.numargs = 1;
tlp->projection.args[0] = msStrdup("auto");
}
if (layer->filteritem)
tlp->filteritem = msStrdup(layer->filteritem);
if (layer->filter.string) {
View
@@ -38,7 +38,10 @@
#include <assert.h>
#include "mapserver.h"
#ifdef USE_GDAL
#include <cpl_conv.h>
#include <ogr_srs_api.h>
#endif
/* Only use this macro on 32-bit integers! */
#define SWAP_FOUR_BYTES(data) \
@@ -2507,6 +2510,55 @@ int msSHPLayerOpen(layerObj *layer)
return MS_FAILURE;
}
}
if (layer->projection.numargs > 0 &&
EQUAL(layer->projection.args[0], "auto"))
{
#ifdef USE_GDAL
const char* pszPRJFilename = CPLResetExtension(szPath, "prj");
int bOK = MS_FALSE;
FILE* fp = fopen(pszPRJFilename, "rb");
if( fp != NULL )
{
char szPRJ[2048];
OGRSpatialReferenceH hSRS;
int nRead;
nRead = (int)fread(szPRJ, 1, sizeof(szPRJ) - 1, fp);
szPRJ[nRead] = '\0';
hSRS = OSRNewSpatialReference(szPRJ);
if( hSRS != NULL )
{
if( OSRMorphFromESRI( hSRS ) == OGRERR_NONE )
{
char* pszWKT = NULL;
if( OSRExportToWkt( hSRS, &pszWKT ) == OGRERR_NONE )
{
if( msOGCWKT2ProjectionObj(pszWKT, &(layer->projection),
layer->debug ) == MS_SUCCESS )
{
bOK = MS_TRUE;
}
}
CPLFree(pszWKT);
}
OSRDestroySpatialReference(hSRS);
}
}
fclose(fp);
if( bOK != MS_TRUE )
{
if( layer->debug || (layer->map && layer->map->debug) ) {
msDebug( "Unable to get SRS from shapefile '%s' for layer '%s'.\n", szPath, layer->name );
}
}
#else
if( layer->debug || (layer->map && layer->map->debug) ) {
msDebug( "Unable to get SRS from shapefile '%s' for layer '%s'. GDAL support needed\n", szPath, layer->name );
}
#endif
}
return MS_SUCCESS;
}

0 comments on commit e35978e

Please sign in to comment.