Encoding of German umlauts when using readOGR

2019-04-21 07:20发布

I'm trying to read an OGR vector map using the readOGR function provided by the rgdal package, but I'm having a little trouble with the German umlauts. I've provided a little example of what the data looks like, umlauts like ö are replaced with \303\266.

map <-readOGR("/path/to/data.gdb", layer = "layer")
map@data$name
# [1] L\303\266rrach
# [2] Karlsruhe
# [3] B\303\266blingen
# [4] ...

I've tried to specify an encoding in the readOGR function (readOGR(dsn = "/path/to/data.gdb", layer = "layer", encoding = "UTF-8" or readOGR(dsn = "/path/to/data.gdb", layer = "layer", encoding = "LATIN-1"), but it looks like it is ignoring the encoding parameter completely, since I'm getting the same result for each encoding I've tried. Does anybody know how I can get the readOGR function or R to display the correct German umlauts?

标签: r encoding rgdal
3条回答
Fickle 薄情
2楼-- · 2019-04-21 07:34

Julian is right.

file_name <- "../gis_data/bw/AX_KommunalesGebiet.shp"
shape_kommunal <- readOGR(file_name, layer = "AX_KommunalesGebiet", use_iconv = TRUE, encoding = "UTF-8")
data_kommunal <- shape_kommunal@data
head(data_kommunal)

returns the string correctly:

  GKZ                NAME
0 08236074           Kämpfelbach
1 08425052           Grundsheim
2 08435067           Deggenhausertal
查看更多
forever°为你锁心
3楼-- · 2019-04-21 07:35

I'm not quite sure what encoding = "UTF-8/LATIN-1/..." might do. I would have expected that you would choose one and only one encoding scheme. On my machine I do see the translation of that octal character to the o-umlaut:

> 'B\303\266blingen'
[1] "Böblingen"
> 'L\303\266rrach'
[1] "Lörrach"

To see the various conventions for R characters, type:

?Quotes

Besides encodings, there is also the need to have characters in the font being used. The font used in your console display doesn't seem to have the proper mappings for o-umlaut. My default font is Courier. You should also check your locale settings. ?Sys.getlocale

查看更多
男人必须洒脱
4楼-- · 2019-04-21 07:36

The encoding-parameter is ignored, if iconv is not set to TRUE.

查看更多
登录 后发表回答