Issue with st_read sf with Encoding for MapInfo file (Frisian municipality name)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue with st_read sf with Encoding for MapInfo file (Frisian municipality name)

Egge-Jan Pollé
Hello,

Would someone know a solution for this issue:

When I load a MapInfo file with st_read (sf) I have an issue with the
Frisian municipality name 'Súdwest-Fryslân'; it shows as
'S<fa>dwest-Frysl<e2>n' :-( Some issue with the encoding...

Below you will find a reproducible example, which will also download the
data set used.

If I load the same data with readOGR, everything is fine.

And if I load a comparable data set in ESRI SHP file format with st_read
(sf) there is no issue either.

So it really has something to do with the MapInfo driver. I did not find a
solution yet, so any help would be appreciated.

Cheers,

Egge-Jan Pollé


REPRODUCIBLE EXAMPLE:
# Download and read the data
#
# Make sure you have your Working Directory properly set, e.g.:
# setwd("C:/RMOOC")
#
# Download
URL <- "http://www.twiav.nl/files/NL_Municipalities2017.zip"
datafile <- file.path(basename(URL))
dir.create("./Data", showWarnings = FALSE)
workingdirectory <- getwd()
setwd("./Data")
download.file(URL, destfile = datafile, mode = "wb")
unzip(datafile)
unlink(datafile)
rm(URL, datafile)
setwd(workingdirectory)
rm(workingdirectory)

# Read
# Make sure the package "sf" is properly installed:
# install.packages("sf")
library(sf)
NL_Municipalities2017 <-
st_read("Data/NL_Municipalities2017/NL_Municipalities2017.TAB")
View(NL_Municipalities2017)
plot(st_geometry(NL_Municipalities2017),col = "darkgreen", border =
"lightgray")
View(NL_Municipalities2017) # issue with 'Súdwest-Fryslân'; it shows as
'S<fa>dwest-Frysl<e2>n'

# Using rgdal everything is fine...
library(rgdal)
nl2 <- readOGR(dsn = "Data/NL_Municipalities2017", layer =
"NL_Municipalities2017")
View(as.data.frame(nl2))
library(mapview)
mapview(nl2)

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Issue with st_read sf with Encoding for MapInfo file (Frisian municipality name)

peter van horssen-2
try here:
https://github.com/r-spatial/sf/issues/5
a similar issue with a solution ...

greetings , Peter




Op 23-1-2018 om 21:49 schreef Egge-Jan Pollé:

> Hello,
>
> Would someone know a solution for this issue:
>
> When I load a MapInfo file with st_read (sf) I have an issue with the
> Frisian municipality name 'Súdwest-Fryslân'; it shows as
> 'S<fa>dwest-Frysl<e2>n' :-( Some issue with the encoding...
>
> Below you will find a reproducible example, which will also download the
> data set used.
>
> If I load the same data with readOGR, everything is fine.
>
> And if I load a comparable data set in ESRI SHP file format with st_read
> (sf) there is no issue either.
>
> So it really has something to do with the MapInfo driver. I did not find a
> solution yet, so any help would be appreciated.
>
> Cheers,
>
> Egge-Jan Pollé
>
>
> REPRODUCIBLE EXAMPLE:
> # Download and read the data
> #
> # Make sure you have your Working Directory properly set, e.g.:
> # setwd("C:/RMOOC")
> #
> # Download
> URL <- "http://www.twiav.nl/files/NL_Municipalities2017.zip"
> datafile <- file.path(basename(URL))
> dir.create("./Data", showWarnings = FALSE)
> workingdirectory <- getwd()
> setwd("./Data")
> download.file(URL, destfile = datafile, mode = "wb")
> unzip(datafile)
> unlink(datafile)
> rm(URL, datafile)
> setwd(workingdirectory)
> rm(workingdirectory)
>
> # Read
> # Make sure the package "sf" is properly installed:
> # install.packages("sf")
> library(sf)
> NL_Municipalities2017 <-
> st_read("Data/NL_Municipalities2017/NL_Municipalities2017.TAB")
> View(NL_Municipalities2017)
> plot(st_geometry(NL_Municipalities2017),col = "darkgreen", border =
> "lightgray")
> View(NL_Municipalities2017) # issue with 'Súdwest-Fryslân'; it shows as
> 'S<fa>dwest-Frysl<e2>n'
>
> # Using rgdal everything is fine...
> library(rgdal)
> nl2 <- readOGR(dsn = "Data/NL_Municipalities2017", layer =
> "NL_Municipalities2017")
> View(as.data.frame(nl2))
> library(mapview)
> mapview(nl2)
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Issue with st_read sf with Encoding for MapInfo file (Frisian municipality name)

Egge-Jan Pollé
Hi Peter,

Thanks for your swift reaction. I followed the link you suggested and tried
to extent my st_read statement with an encoding parameter, but
unfortunately to no avail...

The issue has been solved, though, by following Edzer's suggestion to
abandon the shapefile (or - in my case - the MapInfo file) and to look for
an alternative. I have asked FME to output my sample data set to a GeoJSON
file, and now everything works fine in R :-)

Tnx again,

Egge-Jan

2018-01-23 22:20 GMT+01:00 Peter van Horssen <[hidden email]>:

> try here:
> https://github.com/r-spatial/sf/issues/5
> a similar issue with a solution ...
>
> greetings , Peter
>
>
>
>
> Op 23-1-2018 om 21:49 schreef Egge-Jan Pollé:
>
>> Hello,
>>
>> Would someone know a solution for this issue:
>>
>> When I load a MapInfo file with st_read (sf) I have an issue with the
>> Frisian municipality name 'Súdwest-Fryslân'; it shows as
>> 'S<fa>dwest-Frysl<e2>n' :-( Some issue with the encoding...
>>
>> Below you will find a reproducible example, which will also download the
>> data set used.
>>
>> If I load the same data with readOGR, everything is fine.
>>
>> And if I load a comparable data set in ESRI SHP file format with st_read
>> (sf) there is no issue either.
>>
>> So it really has something to do with the MapInfo driver. I did not find a
>> solution yet, so any help would be appreciated.
>>
>> Cheers,
>>
>> Egge-Jan Pollé
>>
>>
>> REPRODUCIBLE EXAMPLE:
>> # Download and read the data
>> #
>> # Make sure you have your Working Directory properly set, e.g.:
>> # setwd("C:/RMOOC")
>> #
>> # Download
>> URL <- "http://www.twiav.nl/files/NL_Municipalities2017.zip"
>> datafile <- file.path(basename(URL))
>> dir.create("./Data", showWarnings = FALSE)
>> workingdirectory <- getwd()
>> setwd("./Data")
>> download.file(URL, destfile = datafile, mode = "wb")
>> unzip(datafile)
>> unlink(datafile)
>> rm(URL, datafile)
>> setwd(workingdirectory)
>> rm(workingdirectory)
>>
>> # Read
>> # Make sure the package "sf" is properly installed:
>> # install.packages("sf")
>> library(sf)
>> NL_Municipalities2017 <-
>> st_read("Data/NL_Municipalities2017/NL_Municipalities2017.TAB")
>> View(NL_Municipalities2017)
>> plot(st_geometry(NL_Municipalities2017),col = "darkgreen", border =
>> "lightgray")
>> View(NL_Municipalities2017) # issue with 'Súdwest-Fryslân'; it shows as
>> 'S<fa>dwest-Frysl<e2>n'
>>
>> # Using rgdal everything is fine...
>> library(rgdal)
>> nl2 <- readOGR(dsn = "Data/NL_Municipalities2017", layer =
>> "NL_Municipalities2017")
>> View(as.data.frame(nl2))
>> library(mapview)
>> mapview(nl2)
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo