SymbolixAU / geojsonsf

Conversion between sf and geojson
Other
82 stars 7 forks source link

Dealing with non ASCII characters #59

Closed RobertMyles closed 5 years ago

RobertMyles commented 5 years ago

Hi,

Great package, thanks a lot! Just saved me a whole load of work. However, there is one thing catching me: latin characters in the json. (See here for the original file).

Here's what I'm getting (geometry excluded). I've tried to correct this using stringi::stri_trans_general(), but to no avail. Is it possible to include it in the parsing of the original file?

head(geojsonsf::geojson_sf("https://raw.githubusercontent.com/tbrugz/geodata-br/master/geojson/geojs-35-mun.json"))
#> Warning in readLines(con): incomplete final line found on 'https://
#> raw.githubusercontent.com/tbrugz/geodata-br/master/geojson/geojs-35-
#> mun.json'
#>        id                         name                  description
#> 1 3500105                   Adamantina                   Adamantina
#> 2 3500204                       Adolfo                       Adolfo
#> 3 3500303                     Agua\xed                     Agua\xed
#> 4 3500402            \xc1guas da Prata            \xc1guas da Prata
#> 5 3500501       \xc1guas de Lind\xf3ia       \xc1guas de Lind\xf3ia
#> 6 3500550 \xc1guas de Santa B\xe1rbara \xc1guas de Santa B\xe1rbara
#> 
SymbolixAU commented 5 years ago

At the R level, is this what you're after

Encoding(sf$name) <- 'latin1'
Encoding(sf$description) <- 'latin1'
RobertMyles commented 5 years ago

Lovely, should have remembered Encoding()! Thanks for the quick response.

SymbolixAU commented 5 years ago

I think for now I'm leaving this as an R-solution, rather than adding to the underlying C++ code. But, I may re-visit in a few months after I've updated all my other libraries.

Thanks for reporting/suggesting.