[R-sig-Geo] +towgs84 in st_write

manuel.schneider at agroscope.admin.ch manuel.schneider at agroscope.admin.ch
Wed Dec 13 15:09:45 CET 2017


Dear Roger and Edzer

Many thanks for looking into this. Projection is perfectly transferred from R to QGIS when using a geopackage, so this is definitively a shapefile issue. It's absolutely time to change ... and since st_write to GPKG works perfectly now (thanks to your efforts) there is no obstacle to do so.
All best wishes
Manuel

-----Ursprüngliche Nachricht-----
Von: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] Im Auftrag von Roger Bivand
Gesendet: Mittwoch, 13. Dezember 2017 07:09
An: Edzer Pebesma <edzer.pebesma at uni-muenster.de>
Cc: r-sig-geo at r-project.org
Betreff: Re: [R-sig-Geo] +towgs84 in st_write

On Tue, 12 Dec 2017, Edzer Pebesma wrote:

>
>
> On 12/12/2017 11:27 PM, Roger Bivand wrote:
>> Does sf use morphToESRI()?
>
> No.
>

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

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: Roger.Bivand at nhh.no
Editor-in-Chief of The R Journal, https://journal.r-project.org/index.html
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list