导入非英语形状文件
我正在尝试导入这样的形状文件:
fn <- "Proj1"
my_shp <- readShapeSpatial(fn)
在 Windows 计算机(32 位)上它工作正常,但是当我在 Ubuntu 计算机(64 位,英语操作系统,R2.14.0)上执行相同操作时,我收到“make.names(onames, unique = TRUE) 中的错误:无效的多字节字符串 9”。
我怀疑这是因为 shapefile 起源于西班牙,即其中的多边形名称带有重音符号,如“México”(而不是“Mexico”)。
作为一个快速修复,我在 Windows 中进行了导入,另存为 .rda 并将其加载到 Ubuntu 中,但随后我得到了例如“M\xfexico”作为多边形名称。
我对 Linux 没有那么丰富的经验,所以我不知道修复是在 R 还是在 Ubuntu 中。非常感谢您的帮助。
I'm trying to import a shape-file like this:
fn <- "Proj1"
my_shp <- readShapeSpatial(fn)
On a windows-computer (32-bit) it works ok, but when I do the same from a Ubuntu-machine (64-bit, English OS, R2.14.0), I get "Error in make.names(onames, unique = TRUE) : invalid multibyte string 9".
I suspect it is because the shapefile has Spanish origins, i.e. the names of polygons in it have accents like in "México" (not "Mexico").
As a quick fix, I did the import in windows, saved as .rda and loaded it in Ubuntu, but then I get for example "M\xfexico" as polygon name.
I'm not so experienced in Linux so I don't know if the fix is in R or in Ubuntu. Your help is highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案是通过在终端窗口中写入“LC_ALL=CR”来在 Ubuntu 计算机上启动 R。感谢 Oscar Perpiñán 提供的解决方案。
更新:我使用 RStudio,据我所知,不可能使用命令行参数启动 R,但这可以在 RStudio 内部工作:
Sys.setlocale(category = "LC_ALL", locale = "C")
/Chris
The solution is to start R on the Ubuntu-computer by writing "LC_ALL=C R" in a terminal window. Thanks to Oscar Perpiñán for the solution.
Update: I use RStudio, where as far as I know it is not possible to start R with command-line parameters, but this works from inside RStudio:
Sys.setlocale(category = "LC_ALL", locale = "C")
/Chris