Ubuntu系统下R语言terra包project函数核心转储问题求助
terra包
project()函数崩溃问题排查建议 问题描述
在R 4.3.0版本中使用terra v1.7-29的project()函数时,终端与RStudio均出现程序崩溃,terra包安装过程无报错。执行投影转换操作时,触发以下内存错误:
free(): double free detected in tcache 2 Aborted (core dumped)
可复现代码
library(terra) # 定义投影 pt.proj <- " +proj=longlat +datum=WGS84" calc.proj <- " +proj=aea + lat_1=14.5 + lat_2=32.5 + lat_0=24.0 + lon_0=-105 +x_0=0 +y_0=0 + ellps =GRS80 +datum=NAD83 + units=m +no_defs" # 创建空间矢量对象 ids <- c("id00041130", "id00043728", "id00032757", "id00035604") spp <- rep("Quercus_aerea", 4) lats <- c(27.4, 25.1, 26.9, 28.2) longs <- c(-108, -106, -107, -107) spat_points <- cbind.data.frame(ids, spp, lats, longs) spat_vect <- vect(spat_points, geom=c("longs", "lats"), crs=pt.proj, keepgeom=FALSE) # 触发崩溃的投影操作 spat_vect.calc <- project(spat_vect, calc.proj)
环境信息
R会话信息
> sessionInfo() R version 4.3.0 (2023-04-21) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04.6 LTS Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3 LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3; LAPACK version 3.7.1
系统依赖版本
> sf::sf_extSoftVersion() GEOS GDAL proj.4 "3.6.2" "2.2.3" "4.9.3" GDAL_with_GEOS USE_PROJ_H PROJ "true" "false" "4.9.3"
排查方向与诊断建议
- 修正投影字符串格式:proj4字符串要求参数与值之间无空格,参数前的
+号后也不能有空格。将calc.proj中的错误格式(如+ ellps =GRS80)修正为+ellps=GRS80,去除所有多余空格后重新测试。 - 升级系统依赖库:当前proj 4.9.3、GDAL 2.2.3版本较老旧,内存管理逻辑存在缺陷的概率较高。建议升级proj至6.x及以上版本、GDAL至3.x版本,再重新安装terra包。
- 调整terra包版本:尝试降级至terra v1.7-28或升级至最新稳定版,排查是否为特定版本的已知bug。
- 测试简化用例:使用单个点或内置空间对象(如
vect(cbind(0,0), crs=pt.proj))测试project(),排除数据格式或内容导致的问题。 - 更换线性代数库:当前使用的atlas库可能与R 4.3.0或terra存在兼容性问题,尝试切换为openblas库并重新启动R测试。
- 从源码编译terra:通过源码编译terra包,确保编译过程链接的是本地升级后的proj、GDAL等依赖库,而非预编译包中的旧版本依赖。
内容的提问来源于stack exchange,提问作者akoontz11
相关产品推荐
相关产品推荐

