r-tmap/tmaptools

smooth_map fails when converting spatial points

Closed this issue · 3 comments

I'm trying to create a map with isolines usingsmooth_map on a sf object with spatial points, but on some datasets the functions fails with the following error message:

> dens <- smooth_map(sf_obj, bandwidth = 1)
  |=============================================================================================          |  90%
Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, unaryUnion_if_byid_false,  : 
  trying to get slot "proj4string" from an object (class "sf") that is not an S4 object 

I've created an minimal example that fails with the same error message:

n_coord <- floor(rnorm(800, 80000, 40000)) + 6700000
e_coord <- floor(rnorm(800, 40000, 20000)) + 200000
xt <- st_sfc(lapply(1:800, function(i) st_point(c(e_coord[i], n_coord[i]), dim = 'XY')))
xt <- st_set_crs(xt, 32633)
sf_obj <- st_sf(id = 1:800, n = rep(1, 800), geometry = xt)
dens <- smooth_map(sf_obj, bandwidth = 1)

Edit:

Here is the relevant session info:

R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Norwegian Bokmål_Norway.1252  LC_CTYPE=Norwegian Bokmål_Norway.1252   
[3] LC_MONETARY=Norwegian Bokmål_Norway.1252 LC_NUMERIC=C                            
[5] LC_TIME=Norwegian Bokmål_Norway.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] readxl_1.1.0         magrittr_1.5         tmaptools_2.0-1      tmap_2.1-1           sf_0.6-3            
[6] sp_1.3-1             RevoUtils_11.0.1     RevoUtilsMath_11.0.0

I'm also getting the same error message when running metro_smap <- smooth_map(metro, threshold = 1e-10)

I stumbled upon a fix to my problem. If the cover argument is specified, the function will run as expected.

Should be fixed now, also without specifying the cover argument

I still get the same error as ohjakobsen above when running his example.
Session info:

R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] tmaptools_2.0-1 tmap_2.2 sf_0.7-2

loaded via a namespace (and not attached):
[1] Rcpp_1.0.0 compiler_3.5.0 later_0.7.2 RColorBrewer_1.1-2
[5] R.methodsS3_1.7.1 R.utils_2.6.0 iterators_1.0.9 base64enc_0.1-3
[9] class_7.3-14 tools_3.5.0 gdalUtils_2.0.1.14 digest_0.6.15
[13] satellite_1.0.1 lattice_0.20-35 viridisLite_0.3.0 png_0.1-7
[17] foreach_1.4.4 shiny_1.0.5 DBI_1.0.0 crosstalk_1.0.0
[21] RPostgreSQL_0.6-2 yaml_2.2.0 rgdal_1.2-20 spData_0.2.8.3
[25] e1071_1.6-8 raster_2.8-4 htmlwidgets_1.2 rgeos_0.3-26
[29] webshot_0.5.0 stats4_3.5.0 classInt_0.2-3 leaflet_2.0.2
[33] grid_3.5.0 R6_2.2.2 XML_3.98-1.11 sp_1.2-7
[37] magrittr_1.5 scales_1.0.0 promises_1.0.1 codetools_0.2-15
[41] htmltools_0.3.6 units_0.6-2 dichromat_2.0-0 colorspace_1.3-2
[45] mime_0.5 xtable_1.8-2 httpuv_1.4.3 mapview_2.4.0
[49] KernSmooth_2.23-15 munsell_0.5.0 lwgeom_0.1-5 R.oo_1.22.0