3

I'm trying to modify a raster through an R script but I find an error when I try to save in the ".tif" format, while in the ".asc" format I do not find any problem. The script I use is as follows:

library(raster)

path <- "/path/to/input/file.tif"
path2 <- "/path/to/output/file.tif"
open_file <- raster(path)
rasterzero <- open_file * 0
writeRaster(rasterzero, filename=path2, overwrite=TRUE)

The error I get is the following:

 *** caught segfault ***
address 0x565300000009, cause 'memory not mapped'

Traceback:
 1: .Call("RGDAL_SetProject", object, proj4string, PACKAGE = "rgdal")
 2: .gd_SetProject(object, ...)
 3: rgdal::GDALcall(transient, "SetProject", as.character(projection(r)))
 4: .getGDALtransient(x, filename = filename, options = options,     ...)
 5: .startGDALwriting(y, filename, options, setStatistics = setStatistics,     ...)
 6: .writeGDALall(x, filename = filename, format = filetype, ...)
 7: .local(x, filename, ...)
 8: writeRaster(rasterzero, filename = path2, overwrite = TRUE)
 9: writeRaster(rasterzero, filename = path2, overwrite = TRUE)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

Any suggestions on the possible cause? The same script on different computers runs without errors and the installation procedures of R and its packages are always the same.

Domenico Fuoco
  • 287
  • 3
  • 16
  • Can only suggest you reinstall R (you don't say which version you are on) and all the packages. Also, the versions of GDAL etc reported if you install sf and do library(sf) might help. – Spacedman Nov 15 '18 at 21:21
  • @Spacedman my R version is 3.4.4 e GDAL version is 2.2.2 – Domenico Fuoco Nov 15 '18 at 22:30
  • sf may not report the right version (except by luck) but library(rgdal) will. I'd try different path names, and particularly not an overwrite - but upgrading might be the easiest way out. I can't reproduce – mdsumner Nov 15 '18 at 23:31

1 Answers1

0

As was specified by @Pavel V. in this comment: I solved the problem by setting the environment variable:

export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib

it was a problem related to GDAL and PYPROJ.4

Domenico Fuoco
  • 287
  • 3
  • 16