Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHAPEZIP OutputFormat should be able to use EPSG codes #4658

Merged
merged 1 commit into from Jul 8, 2013
Merged

SHAPEZIP OutputFormat should be able to use EPSG codes #4658

merged 1 commit into from Jul 8, 2013

Conversation

tbonfort
Copy link
Member

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

@rouault rouault merged commit 17034af into MapServer:master Jul 8, 2013
@rouault
Copy link
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants