I am trying to use the rgdal package to open multiple Sentinel-2 data of JPEG2000 format.
The issue I am running into is:
Error in .local(.Object, ...) :
d:/data/T35SMD_20161227T091402_B01.jp2' not recognised as a supported file format.
Although, I have updated my installation of the rgdal package and use updated gdal binaries that support JPEG2000, which had support introduced in v1.9.0.
rgdal: version: 1.2-5, (SVN revision 648)
Loaded GDAL runtime: GDAL 2.0.1, released 2015/09/15
When I perform gdalDrivers() command, the entry for JPG2000 is not listed there among other drivers.
Can anyone please tell me how could I solve this problem? I have plenty of S-2 data and converting them to tiff in QGIS or any similar program is no option for me.
I have also found few similar questions on this theme (c.f. open jpeg2000 sentinel 2 in r), however it seems there is no straight answer yet.
Use the command-line utility gdal_translate, as documented here: http://www.gdal.org/frmt_sentinel2.html. You will have a lot more flexibility, and likely better speed and memory handling. Example that is given there is:
gdal_translate SENTINEL2_L1C:S2A_OPER_MTD_SAFL1C_PDMC_20150818T101440_R022_V20150813T102406_20150813T102406.xml:10m:EPSG_32632 10m.tif -co TILED=YES --config GDAL_CACHEMAX 1000 --config GDAL_NUM_THREADS 2
There's not really a solid argument for doing that much heavy lifting in R, especially through something that is essentially a wrapper.
Related
I have some C++ code that I intend to export into my r package using Rcpp. However, this code links to fftw3 via
#include <fftw3.h>
at the top of the file. When I try to compile this code, I unsurprisingly get the error
fatal error: 'fftw3.h' file not found
What is the proper way to link to this file so that it will be available upon compilation of my package? I know that a Makevars file can generally be used to link to system libraries but since this library is external I'm not sure what to do.
Thanks,
Eric.
Please see the Rcpp vignette Rcpp libraries -- which is also this arXiv paper.
There are many examples among the 2400+ CRAN packages using Rcpp. My hunch would probably be to look at what I contributed to the nloptr package -- even though that is a more complicated scheme where we allow use either a system library if present (could be the case with fftw3 too) or downloand and build.
Rcpp has been used a lot to build such glue. The most common, and simplest , approach is to look for pkg-config and query it for headers and libraries. Please give that a shot (with some looking around CRAN or GitHub for examples).
Edit: There is also an (old) fftw3 package by Gabor at his previous employer's GitHub org as well as another CRAN package fftwtools (which, if memory served, I helped once too but I don't recall now what for).
I have some C++ code that I intend to export into my r package using Rcpp. However, this code links to fftw3 via
#include <fftw3.h>
at the top of the file. When I try to compile this code, I unsurprisingly get the error
fatal error: 'fftw3.h' file not found
What is the proper way to link to this file so that it will be available upon compilation of my package? I know that a Makevars file can generally be used to link to system libraries but since this library is external I'm not sure what to do.
Thanks,
Eric.
Please see the Rcpp vignette Rcpp libraries -- which is also this arXiv paper.
There are many examples among the 2400+ CRAN packages using Rcpp. My hunch would probably be to look at what I contributed to the nloptr package -- even though that is a more complicated scheme where we allow use either a system library if present (could be the case with fftw3 too) or downloand and build.
Rcpp has been used a lot to build such glue. The most common, and simplest , approach is to look for pkg-config and query it for headers and libraries. Please give that a shot (with some looking around CRAN or GitHub for examples).
Edit: There is also an (old) fftw3 package by Gabor at his previous employer's GitHub org as well as another CRAN package fftwtools (which, if memory served, I helped once too but I don't recall now what for).
I am on MacOSX 11.4 Big Sur.
I have just installed on my computer https://postgresapp.com, which bundles PostgreSQL together with the needed libraries for PostGIS (proj, geos, and gdal).
I am able to use command line functions like ogr2ogr, gdalinfo etc. from my terminal, indicating that gdal is successfully installed.
I now want to install the "sf" package for R version 4.1.0. I am able to successfully install "sf", but the PostgreSQL driver is missing when I use the native installation
install.packages("sf")
According to the sf documentation and things I have read elsewhere on stack, this is a known issue for MacOSx, and the recommended workaround for this problem is to separately install gdal using homebrew or the kyngchaos binaries. However, I would like to use the gdal installation used by the postgresapp binary mentioned earlier so that there is only one installation on my computer..
According to the postgresapp installation documentation (https://postgresapp.com/documentation/install.html), the relevant paths are:
Binaries: /Applications/Postgres.app/Contents/Versions/latest/bin
Headers: /Applications/Postgres.app/Contents/Versions/latest/include
Libraries: /Applications/Postgres.app/Contents/Versions/latest/lib
Therefore, when combined with the "sf" documentation my assumption is that the following should work.
install.packages("sf", configure.args = "--with-gdal-lib=/Applications/Postgres.app/Contents/Versions/latest/lib/"
Although I receive no errors or warnings, this does not fix the problem for me as sf::st_drivers() still does not list the PostgreSQL driver as an option. Can someone please help me figure out what additional configuration arguments, if any, are needed to get sf to recognise the Postgres driver?
I would like to be able to call R (2.15.3) from within R (3.0.2). In order to use a package (windows binary, not on cran) that is available in only the older version of R. Is this possible?
This is R. There is no if, only how
said Simon Blomberg.
You could call an older version of R using system() and the appropriate hacks in your OS. Which is something odd to do, and opens tons of possibilities for serious damage to your computer when you hit it in frustration.
Or you could download the source of the package and rebuild it in R 3.0. There's been some rather drastic internal changes in the way packages are built and used in R (the most obvious being the removal of support for packages without a namespace).
Hence :
if the package does not have a namespace: download the source (.tar.gz), read the manual "Writing R extensions" if you didn't before, and add a namespace file with the usual exports. As explained in Writing R extensions, this can be as simple as adding a single line
exportPattern("^[^\\.]")
if the package has a namespace, build from source on your machine and you should be good to go. This is simply done by using:
install.packages("path/to/package.tar.gz",type="source")
Note that if you want to install from source on a Windows machine, you'll need a compatible version of Rtools : http://cran.r-project.org/bin/windows/Rtools/
If you don't want to be bothered with it, mail the author/maintainer of the package and kindly ask if they'd like to rebuild it for you.
Does anyone know of a method to get (raster) data out of an ESRI v10 File Geodatabase in R?
ESRI offers a C++ API (for Linux and Windows), so I guess in principle it should be possible for an R package to retrieve (and write) data to a Geodatabase. I could not find any packages capable of doing this though.
Apparently rgdal now supports file geodatabase read access:
library(rgdal)
subset(ogrDrivers(), grepl("GDB", name))
ogrListLayers("/path/to/folder.gdb")
Worked for me on Windows, R v3.2.0, rgdal v0.9-3.
A quick google led me to the following page:
http://www.gdal.org/ogr/drv_filegdb.html
Which suggest gdal supports file geodatabase. Probably, R then also supports the format through a properly built rgdalpackage. In essence, if the standalone gdal has support, the rgdal package built against that should also read the file geodatabase.
GDAL does not have the ability to read a raster from a File GeoDatabase.
http://erouault.blogspot.fi/2014/01/ogr-openfilegdb-driver.html
https://gis.stackexchange.com/questions/62030/use-gdal-python-to-add-rasters-tiff-to-an-esri-file-geodatabase
Working with rasters in file geodatabase (.gdb) with GDAL
It can read vector feature classes, however. This makes me confident that rgdal also does not support reading raster layers. In fact, ESRI's own FileGDB API does not have raster support.
Unfortunately, this means that you will need to use ESRI tools to export your raster layers to a format that you can use in R. Hopefully there will soon be an open source solution for accessing ESRI GDBs.