Permalink
Browse files

Use EPSG code instead of Proj.4 string if possible (#4658)

  • Loading branch information...
Guillaume Sueur authored and tbonfort committed May 17, 2013
1 parent 395acdb commit 17034af6accec6363cdc6e873889d2bbfd195a84
Showing with 28 additions and 19 deletions.
  1. +28 −19 mapgdal.c
View
@@ -627,35 +627,44 @@ char *msProjectionObj2OGCWKT( projectionObj *projection )
#else /* defined USE_GDAL or USE_OGR */
OGRSpatialReferenceH hSRS;
char *pszWKT=NULL, *pszProj4;
int nLength = 0, i;
char *pszWKT=NULL, *pszProj4, *pszInitEpsg=NULL;
int nLength = 0, i, nEpsgCode=-1;
OGRErr eErr;
if( projection->proj == NULL )
return NULL;
hSRS = OSRNewSpatialReference( NULL );
/* -------------------------------------------------------------------- */
/* Form arguments into a full Proj.4 definition string. */
/* Look for an EPSG-like projection argument */
/* -------------------------------------------------------------------- */
for( i = 0; i < projection->numargs; i++ )
nLength += strlen(projection->args[i]) + 2;
pszProj4 = (char *) CPLMalloc(nLength+2);
pszProj4[0] = '\0';
if( projection->numargs == 1 &&
(pszInitEpsg = strcasestr(projection->args[0],"init=epsg:"))) {
int nEpsgCode = atoi(pszInitEpsg + strlen("init=epsg:"));
eErr = OSRImportFromEPSG(hSRS, nEpsgCode);
} else {
/* -------------------------------------------------------------------- */
/* Form arguments into a full Proj.4 definition string. */
/* -------------------------------------------------------------------- */
for( i = 0; i < projection->numargs; i++ )
nLength += strlen(projection->args[i]) + 2;
pszProj4 = (char *) CPLMalloc(nLength+2);
pszProj4[0] = '\0';
for( i = 0; i < projection->numargs; i++ ) {
strcat( pszProj4, "+" );
strcat( pszProj4, projection->args[i] );
strcat( pszProj4, " " );
}
for( i = 0; i < projection->numargs; i++ ) {
strcat( pszProj4, "+" );
strcat( pszProj4, projection->args[i] );
strcat( pszProj4, " " );
/* -------------------------------------------------------------------- */
/* Ingest the string into OGRSpatialReference. */
/* -------------------------------------------------------------------- */
eErr = OSRImportFromProj4( hSRS, pszProj4 );
CPLFree( pszProj4 );
}
/* -------------------------------------------------------------------- */
/* Ingest the string into OGRSpatialReference. */
/* -------------------------------------------------------------------- */
hSRS = OSRNewSpatialReference( NULL );
eErr = OSRImportFromProj4( hSRS, pszProj4 );
CPLFree( pszProj4 );
/* -------------------------------------------------------------------- */
/* Export as a WKT string. */
/* -------------------------------------------------------------------- */

0 comments on commit 17034af

Please sign in to comment.