Skip to content
Prev 26216 / 29559 Next

+towgs84 in st_write

On Tue, 12 Dec 2017, Edzer Pebesma wrote:

            
I think the "ESRI Shapefile" driver changed - at one stage it was needed 
during writing some time ago, I think. Now the driver simply does it 
itself (line 763 in ogrsf_frmts/ogrshapedatasource.cpp:

* -------------------------------------------------------------------- */
/*      Create the .prj file, if required.                              */
/* -------------------------------------------------------------------- */
     if( poSRS != NULL )
     {
         CPLString osPrjFile =
             CPLFormFilename( NULL, pszFilenameWithoutExt, "prj");

         // The shape layer needs its own copy.
         poSRS = poSRS->Clone();
         poSRS->morphToESRI();

         char *pszWKT = NULL;
         VSILFILE *fp = NULL;
         if( poSRS->exportToWkt( &pszWKT ) == OGRERR_NONE
             && (fp = VSIFOpenL( osPrjFile, "wt" )) != NULL )
         {
             VSIFWriteL( pszWKT, strlen(pszWKT), 1, fp );
             VSIFCloseL( fp );
         }

         CPLFree( pszWKT );

         poSRS->morphFromESRI();
     }

So the driver is doing what it believes ArcGIS would like to read - the 
*.prj file isn't well specified. In https://issues.qgis.org/issues/2154 
Frank Warmerdam wrote eight years ago: "Yes, OGR does strip the towgs84 
parameter when writing the .prj file. TOWGS84 is not a legal construct in 
an ESRI Projection Engine string (for .prj files)."

Sounds like another reason to abandon shapefiles as not fit for purpose.

Roger