[gdal-dev] Abou R sf library and GDAL

Roger Bivand Roger.Bivand at nhh.no
Tue Oct 29 04:33:25 PDT 2024


Abel:

You write:

>I am working on a Windows 10 or 11 system (though I 
> believe this detail is not particularly relevant). I am looking
> for the simplest method to install GDAL, as RStudio 
> requires it as a dependency for the "sf" package.

Windows (or macOS) as compared to all other systems matters crucially, as R packages like sf are static linked on Windows and macOS but dynamic linked for others.

> The question arises from a plain user (not developer) who
> works with R (I still need to confirm if they are using
> RStudio specifically) and wants to read MiraMon vector
> files directly, then save them back in the same format.

Since the user platform is Windows, sf is currently static linked to GDAL 3.8.3. Until the central R build train for all 22000 packages (and many others for bioinformatic) is next upgraded, asking for a one-off upgrade for an unbroken external library is possible but not probable. We'll try, but GDAL 3.9 needs to be more stable than 4 3.9 releases in five months suggests for it to be easy to ask for.

While it is not impossible for advanced developers to create custom MXE builds of GDAL versions, locally modifying the R Windows build train, it is not advisable unless really essential, and demands substantial insight and resources.

> Since this driver was added recently, I would like to 
> understand how R users can employ "sf" to work with this
> format. Any guidance on making this setup accessible 
> within the R environment would be greatly appreciated.

Until the R build train is upgraded to GDAL 3.9.*, the only viable option which I have tried is by using ogr2ogr from OSGeo4W https://download.osgeo.org/osgeo4w/v2/osgeo4w-setup.exe and custom installing GDAL command line tools for GDAL >= 3.9. Then convert a MiraMonVector layer to a format current sf can read, such as GPKG, and read that. For writing to MiraMonVector, write first a GPKG then use ogr2ogr. 

While this works, the OSGeo4W shell within which ogr2ogr operates, sets necessary environment variables, so either the GPKG files must be created before starting R (or RStudio), or R (or RStudio) must be started from the OSGeo4W shell, so that the GPKG files can be created using the R system() command to invoke ogr2org from within the R session. 

Hope this clarifies, 

Roger

--
Roger Bivand
Emeritus Professor
Norwegian School of Economics
Postboks 3490 Ytre Sandviken, 5045 Bergen, Norway
Roger.Bivand at nhh.no


More information about the gdal-dev mailing list