2

I am trying to use multiple sources of German/Swiss data with umlauts in it. When trying to merge, I realized that the umlauts do not display correctly in R and the same names were rendered differently in different files.

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

Along with several other posts, I read Encoding of German umlauts when using readOGR because one of my data sources is a shp file I read in with readOGR.

Appending use_iconv = TRUE, encoding = "UTF-8") to the end of readOGR did not help. And the problem exists outside of the use of redOGR. I saw that using Sys.setlocale() and a locale which supports UTF-8 worked for that poster, but I don't know what that means after looking at the ?Sys.setlocale information.

How do I correctly read in German data in R on a Mac using English? Sys.getlocale reports C.

ke.re
  • 53
  • 1
  • 7

1 Answers1

2

Could you somehow include an exemplary .gdb-file?

What happens, if you try encoding="latin1"?

Maybe the gdb-data was saved in a wrong encoding? Are you creating it yourself, or you downloaded it from somewhere?

You could also check the information of the gdb-file with this command:

ogrinfo -al "/path/to/data.gdb"
SeGa
  • 9,454
  • 3
  • 31
  • 70
  • Adding encoding="latin1" worked. Thanks! For the other half of the problem (the non-map data) I used Jan's answer in https://stackoverflow.com/questions/34024654/reading-rdata-file-with-different-encoding. Both data sources used latin1. Could I set my work environment to use latin1 instead of converting all the data after the fact? – ke.re May 04 '18 at 14:45
  • Also, I use RStudio. I tried the ogrinfo in the Console and got: `Error: unexpected string constant` and in the Terminal: `bash: ogrinfo: command not found` – ke.re May 04 '18 at 14:57
  • You should use the ogrinfo command in a command-line. In RStudio it wont work. If it worked, I would appreciate if you check the answer or even upvote it :) – SeGa May 04 '18 at 15:05
  • In the command line I get the error that the command ogrinfo is not found. I upvoted, but you +15 reputation for it to show. I am sadly at 1. – ke.re May 04 '18 at 15:53
  • Then you are probably missing GDAL (http://www.gdal.org/). When installed, ogrinfo should work in the command line. – SeGa May 07 '18 at 07:37
  • 1
    Correction: This solution worked in combination with `Sys.setlocale("LC_ALL", "de_DE.UTF-8")` – ke.re May 28 '18 at 08:21