mapserver/mapserver — pull request #4658 by tbonfort (2013-05-17 10:09:55+00:00)
Title: SHAPEZIP OutputFormat should be able to use EPSG codes

When using a SHAPEZIP OUTPUTFORMAT, the PROJECTION object of the LAYER is parsed to build a proj4 string, which is then translated as an OGRSpatialReference with OSRImportFromProj4. The resulting .prj file if then only build with proj4 informations, which are not complete enough to write the full OGC WKT.
If the PROJECTION object is defined with an EPSG code, this code should be used to allow OGR to use the full information about the CRS and build a correct WKT.
Here is the proposed patch :
```patch
--- ../mapserver-6.0.1/mapgdal.c	2011-03-18 14:41:32.000000000 +0100
+++ mapgdal.c	2013-05-16 15:38:53.786435882 +0200
@@ -681,6 +681,7 @@
char *pszWKT=NULL, *pszProj4;
int nLength = 0, i;
OGRErr eErr;
+ int epsg_code = -1;

if( projection->proj == NULL )
return NULL;
@@ -696,6 +697,11 @@

for( i = 0; i < projection->numargs; i++ )
{
+ /* Get the EPSG code starting at offset 9 */
+ if ( strncmp( "init=epsg:", projection->args[i], 10 ) == 0 ||
+ strncmp( "init=EPSG:", projection->args[i], 10 ) == 0 )
+	epsg_code = atoi( projection->args[i] + 10 );
+
strcat( pszProj4, "+" );
strcat( pszProj4, projection->args[i] );
strcat( pszProj4, " " );
@@ -705,7 +711,10 @@
/* Ingest the string into OGRSpatialReference. */
/* -------------------------------------------------------------------- */
hSRS = OSRNewSpatialReference( NULL );
- eErr = OSRImportFromProj4( hSRS, pszProj4 );
+ if ( epsg_code >= 0 )
+ eErr = OSRImportFromEPSG(hSRS, epsg_code);
+ else
+ eErr = OSRImportFromProj4( hSRS, pszProj4 );
CPLFree( pszProj4 );

/* -------------------------------------------------------------------- */
```

It applies to mapserver 6.0 branch but can be used on master from line 640 of mapgdal.c