MCPcopy Create free account
hub / github.com/MapServer/MapServer / msProjectionObj2OGCWKT

Function msProjectionObj2OGCWKT

mapgdal.c:668–729  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

666/************************************************************************/
667
668char *msProjectionObj2OGCWKT( projectionObj *projection )
669
670{
671
672#if !defined(USE_GDAL) && !defined(USE_OGR)
673 msSetError(MS_OGRERR,
674 "Not implemented since neither OGR nor GDAL is enabled.",
675 "msProjectionObj2OGCWKT()");
676 return NULL;
677
678#else /* defined USE_GDAL or USE_OGR */
679
680 OGRSpatialReferenceH hSRS;
681 char *pszWKT=NULL, *pszProj4;
682 int nLength = 0, i;
683 OGRErr eErr;
684
685 if( projection->proj == NULL )
686 return NULL;
687
688/* -------------------------------------------------------------------- */
689/* Form arguments into a full Proj.4 definition string. */
690/* -------------------------------------------------------------------- */
691 for( i = 0; i < projection->numargs; i++ )
692 nLength += strlen(projection->args[i]) + 2;
693
694 pszProj4 = (char *) CPLMalloc(nLength+2);
695 pszProj4[0] = '\0';
696
697 for( i = 0; i < projection->numargs; i++ )
698 {
699 strcat( pszProj4, "+" );
700 strcat( pszProj4, projection->args[i] );
701 strcat( pszProj4, " " );
702 }
703
704/* -------------------------------------------------------------------- */
705/* Ingest the string into OGRSpatialReference. */
706/* -------------------------------------------------------------------- */
707 hSRS = OSRNewSpatialReference( NULL );
708 eErr = OSRImportFromProj4( hSRS, pszProj4 );
709 CPLFree( pszProj4 );
710
711/* -------------------------------------------------------------------- */
712/* Export as a WKT string. */
713/* -------------------------------------------------------------------- */
714 if( eErr == OGRERR_NONE )
715 eErr = OSRExportToWkt( hSRS, &pszWKT );
716
717 OSRDestroySpatialReference( hSRS );
718
719 if( pszWKT )
720 {
721 char *pszWKT2 = msStrdup(pszWKT);
722 CPLFree( pszWKT );
723
724 return pszWKT2;
725 }

Callers 2

msSaveImageGDALFunction · 0.85
msOGRWriteFromQueryFunction · 0.85

Calls 2

msSetErrorFunction · 0.85
msStrdupFunction · 0.85

Tested by

no test coverage detected