1

I am having troubles with the encoding of the osm data in R. Here is a reproducible example using the osmar package:

osmData <- osmar::get_osm(osmar::center_bbox(23.334360, 42.693180, 100, 100))
osmData$nodes$tags[80:100, ] #the output is not UTF-8

I have also downloaded a planet file from https://download.geofabrik.de/europe/. The filename is "bulgaria-latest.osm.bz2".

After unzipping it, installing osmosis, and reading the file with osmar::get_osm(source = osmsource_osmosis(fileName)) I still have the same issue. The cyrilics letters are not readable.

I am using a 64bit Windows 10 with R version 3.3.3. My default encoding is Bulgarian, but I have also tried English encoding in R with no help.

Any ideas how can I counter this?

6
  • For OSM data, you need utf-8 encoding.
    – AndreJ
    Commented Jul 21, 2017 at 9:52
  • Cyrillic letters look perfectly good to me. Encoding(.) reports them as UTF-8.
    – Spacedman
    Commented Jul 21, 2017 at 10:41
  • @Spacedman Did you use osmar package? What is your locale? On mine, in order to see Encoding I have to write Encoding(as.character(osmData$nodes$tags[80:100, "v"])) and the results is "unknown"
    – deann
    Commented Jul 21, 2017 at 11:04
  • 1
    Ok, I tried this in Linux and it works. Apparently, it is connected to Windows locale. Have not found how to fix this in Windows yet.
    – deann
    Commented Jul 21, 2017 at 12:06

1 Answer 1

3

Ok, Answering my own question:

I ran the above code in linux and understood that the issue was with the windows locale. The workaround I found was to use iconv with from and to parameters set to "UTF-8".

iconv(osmData$nodes$tags[80:100,3][11], from="UTF-8", to="UTF-8") 

This works and could be applied to all columns.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.