首页 > 解决方案 > 如何将韩文脚本 shapefile 读入 R/sf

问题描述

shapefiles 中的韩文(韩文)脚本在读入 R 的过程中被破坏。

从此网站下载首尔、仁川、京畿道地区 shapefile (韩文)。我附上这些文件,因为它们在韩国以外无法访问。

我在英文版的 Windows 10 上使用 RStudio。以防万一,将 RStudio 默认文本编码设置为“UTF-8”并将语言环境设置为韩语:

Sys.setlocale(category="LC_ALL", locale = "Korean")

使用包将 shapefile 读入 R sf

library(sf)

#Read, name and combine regions
sca_nsdi <- rbind(cbind(st_read("LARD_ADM_SECT_SGG_11.shp"), Name="Seoul"), 
                  cbind(st_read("LARD_ADM_SECT_SGG_28.shp"), Name="Incheon"), 
                  cbind(st_read("LARD_ADM_SECT_SGG_41.shp"), Name="Gyeonggi-do"))

#View result
View(sca_nsdi)

在此处输入图像描述

列中的韩文SGG_NM是不可读的,以及通过控制台:

sca_nsdi$SGG_NM[1]

[1] ������

标签: rcharacter-encodingcjksf

解决方案


我终于想通了:

Sys.setlocale(category="LC_ALL", locale = "Korean")
sca_nsdi <- rbind(cbind(st_read("LARD_ADM_SECT_SGG_11.shp", options="ENCODING=EUC-KR"), Name="Seoul"), 
                  cbind(st_read("LARD_ADM_SECT_SGG_28.shp", options="ENCODING=EUC-KR"), Name="Incheon"), 
                  cbind(st_read("LARD_ADM_SECT_SGG_41.shp", options="ENCODING=EUC-KR"), Name="Gyeonggi-do"))

推荐阅读