Closed andysouth closed 3 years ago
Reading from the shapefile also causes the error.
filename <- system.file("extdata","africountries.shp", package="afrilearndata", mustWork=TRUE)
africountries2 <- sf::read_sf(filename)
tm_shape(africountries2)+tmap::tm_borders()
Error: Shape contains invalid polygons. Please fix it or set tmap_options(check.and.fix = TRUE) and rerun the plot
seemingly occurs on sf version 1.0.0 and not on sf 0.9.8
packageVersion('sf')
sudan <- africountries[africountries$name=='Sudan',]
mapview(sudan)
There are two dodgy looking parts of the boundary with South Sudan :
Those extra lower lines are not in the original rnaturalearth data that africountries was derived from.
library(rnaturalearth)
nessd <- ne_countries(country='sudan')
mapview(nessd)
... and previous is the case when done on RStudio cloud too.
So it seems that the weird lines were introduced when africountries was created in https://github.com/afrimapr/afrilearndata/blob/master/data-raw/afrilearndata-data-creation.R
Perhaps a problem with sf then & changing CRS specifications.
Try rerunning creation of africountries.
Seems to be OK now (e.g. after installing afrilearndata_0.0.0.9003 from github to RStudio cloud)
@AnneMTreasure can you check if this now works for you ?
Hi @andysouth,
Thank you so much for fixing this!
I reinstalled afrilearndata
using:
remotes::install_github("afrimapr/afrilearndata")
packageVersion('afrilearndata')
0.0.0.9003
This code,
tmap::tm_shape(africountries)+tmap::tm_borders()
as well as reading from the shapefile:
filename <- system.file("extdata","africountries.shp", package="afrilearndata", mustWork=TRUE)
africountries2 <- sf::read_sf(filename)
tm_shape(africountries2)+tmap::tm_borders()
now works:
and Sudan looks good:
sudan <- africountries[africountries$name=='Sudan',]
mapview(sudan)
This worked for packageVersion('sf')
- 1.0.0
as well as 0.9.8
packageVersion('tmap')
3.3.1
packageVersion('afrilearndata')
0.0.0.9003
Great, thanks so much Andy!
tmap::tm_shape(africountries)+tmap::tm_borders()
gives : Error: Shape contains invalid polygons. Please fix it or set tmap_options(check.and.fix = TRUE) and rerun the plot
but only on RStudio cloud & seemingly with the book : https://github.com/afrimapr/afrimapr-book/issues/30
The error where it occurs seems to be caused by a problem with Sudan boundaries.
sf::st_is_valid(africountries)
[1] TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [14] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [27] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [40] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE[1] "Sudan"
Note also that even on systems where there is an error mapview(africountries) runs without error