SHAPEZIP OutputFormat should be able to use EPSG codes #4658

Merged
merged 1 commit into from Jul 8, 2013

Projects

None yet

3 participants

@gsueur
Contributor
gsueur commented May 17, 2013

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 :

--- ../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

@tbonfort tbonfort was assigned May 17, 2013
@tbonfort tbonfort added a commit to tbonfort/mapserver that referenced this pull request May 17, 2013
@tbonfort Guillaume Sueur + tbonfort Use EPSG code instead of Proj.4 string if possible (#4658) e689914
@rouault rouault merged commit 17034af into mapserver:master Jul 8, 2013

1 check failed

default The Travis CI build failed
Details
@rouault
Contributor
rouault commented Jul 8, 2013

Fixed as #4698

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment