导入非英语形状文件

发布于 2025-01-01 05:18:15 字数 461 浏览 3 评论 0原文

我正在尝试导入这样的形状文件:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

厌味 2025-01-08 05:18:15

解决方案是通过在终端窗口中写入“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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文