mapview icon indicating copy to clipboard operation
mapview copied to clipboard

mapview crashes with sf objects with empty geometries

Open sylvaine31 opened this issue 9 months ago • 10 comments

No problem for visualizing breweries dataset :

data(breweries, package = "mapview")
mapview::mapview(breweries)

but if there is an empty geometry, it crashes :

empty_geometry <- sf::st_sfc(sf::st_polygon())
breweries$geometry[1] <- empty_geometry

mapview::mapview(breweries)

Image

What is very funny (?), is that if I use an empty geometrycollection instead of an empty polygon, it doesn't crash and works properly...

empty_geometry <- sf::st_sfc(sf::st_geometrycollection())
breweries$geometry[1] <- empty_geometry

mapview::mapview(breweries)

I have no clue what update or change might have caused this issue, but everything was working fine two weeks ago.

Environment:

Windows Version: Windows 10 x64 (build 19045) RStudio Version: 2024.9.0.375 R Version: R version 4.3.3 (2024-02-29 ucrt) sf Package Version: 1.0.20 mapview Package Version: 2.11.2

sylvaine31 avatar Apr 23 '25 14:04 sylvaine31

Hi, I come back to see if anyone else has the same problem ?

sylvaine31 avatar May 12 '25 06:05 sylvaine31

What do you expect should happen when you assign an empty polygon to a point data set?

tim-salabim avatar May 12 '25 07:05 tim-salabim

I can't reproduce the problem (I see no problem) but that is on Ubuntu, not Windows. Have you tried updating R and sf to released versions?

edzer avatar May 12 '25 07:05 edzer

I can reproduce on ubuntu.

Image

sessionInfo()
R version 4.4.3 (2025-02-28)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Berlin
tzcode source: system (glibc)

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

other attached packages:
[1] mapview_2.11.2

loaded via a namespace (and not attached):
 [1] terra_1.7-83       cli_3.6.3          rlang_1.1.4        leaflet_2.2.2     
 [5] KernSmooth_2.23-26 DBI_1.2.3          png_0.1-8          sf_1.0-19         
 [9] glue_1.8.0         colorspace_2.1-1   satellite_1.0.5    e1071_1.7-16      
[13] htmltools_0.5.8.1  leafem_0.2.3.9014  stats4_4.4.3       sp_2.1-4          
[17] scales_1.3.0       grid_4.4.3         classInt_0.4-10    crosstalk_1.2.1   
[21] munsell_0.5.1      fastmap_1.2.0      base64enc_0.1-3    lifecycle_1.0.4   
[25] compiler_4.4.3     codetools_0.2-20   htmlwidgets_1.6.4  Rcpp_1.0.13-1     
[29] lattice_0.22-6     digest_0.6.37      R6_2.5.1           class_7.3-23      
[33] magrittr_2.0.3     tools_4.4.3        proxy_0.4-27       raster_3.6-30     
[37] units_0.8-5       

tim-salabim avatar May 12 '25 07:05 tim-salabim

I can't reproduce the problem

Are you by any chance setting mapviewOptions(fgb = FALSE) somewhere (.Rprofile etc)?

tim-salabim avatar May 12 '25 07:05 tim-salabim

I can reproduce on ubuntu.

also wit sf 1.0-20? What is sf::sf_extSoftVersion()?

edzer avatar May 12 '25 07:05 edzer

With 1.0-20 I don't get a crash, but no layer is displayed. I'll look into the JS side

sf::sf_extSoftVersion()
          GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H           PROJ 
      "3.12.2"       "3.10.3"        "9.4.1"         "true"         "true"        "9.4.1" 

tim-salabim avatar May 12 '25 09:05 tim-salabim

Hi,

Are you by any chance setting mapviewOptions(fgb = FALSE) somewhere (.Rprofile etc)? I tried both options, it didn't changed nothing.

also wit sf 1.0-20? What is sf::sf_extSoftVersion()?

sf::sf_extSoftVersion() GEOS GDAL proj.4 GDAL_with_GEOS USE_PROJ_H PROJ "3.11.2" "3.8.2" "9.3.1" "true" "true" "9.3.1"

What do you expect should happen when you assign an empty polygon to a point data set?

And sorry, it was not a sf::st_polygon() but obviously a sf::st_point()...A little mistake when I built the reprex...

This morning I switch towards RStudio 2025.05.0 and the bug seems to disappear.

sylvaine31 avatar May 14 '25 06:05 sylvaine31

Thanks for the info. I'll leave this open because this will bite again with fgb based rendering.... It's an issue of file naming when writing the file for transfer to the browser.

tim-salabim avatar May 14 '25 08:05 tim-salabim

Well, with the new Rstudio version, I finally have the same problem : crash when trying to mapview sf objects with empty geometries.

sylvaine31 avatar May 20 '25 13:05 sylvaine31