Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addPolygons fails in case the geometry columns has names #595

Closed
lbusett opened this issue Nov 12, 2018 · 1 comment
Closed

addPolygons fails in case the geometry columns has names #595

lbusett opened this issue Nov 12, 2018 · 1 comment
Labels
difficulty: intermediate Enterprising community members could help effort: low < 1 day of work priority: high Must be fixed before next release

Comments

@lbusett
Copy link

lbusett commented Nov 12, 2018

Adding polygons to a leaflet map derived from an sf object currently fails
(i.e., the polygons are not shown) in case the geometry column of the object has names.

So, for example, this fails:

library(shiny)
library(leaflet)
library(sf)
library(rmapshaper)
### Read in shapefiles  ###
polys_sf<-st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE) %>% 
  st_transform(crs="+init=epsg:4326") %>% 
  ms_simplify(.)

ui<- fluidPage(
  leafletOutput("leaf"))
### Server ###
server<- function(input,output,session){
  ### This creates interactive map ###
  output$leaf<- renderLeaflet({
    leaflet(options = leafletOptions(minZoom = 7))%>%
      addPolygons(data= polys_sf)
  })
}

because ms_simplify adds names to the geometry column:

names(st_geometry(polys_sf))
#>   [1] "0"  "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10" "11" "12" "13"
#>  [15] "14" "15" "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27"
#>  [29] "28" "29" "30" "31" "32" "33" "34" "35" "36" "37" "38" "39" "40" "41"
#>  [43] "42" "43" "44" "45" "46" "47" "48" "49" "50" "51" "52" "53" "54" "55"
#>  [57] "56" "57" "58" "59" "60" "61" "62" "63" "64" "65" "66" "67" "68" "69"
#>  [71] "70" "71" "72" "73" "74" "75" "76" "77" "78" "79" "80" "81" "82" "83"
#>  [85] "84" "85" "86" "87" "88" "89" "90" "91" "92" "93" "94" "95" "96" "97"
#>  [99] "98" "99"

If however we remove the names by:

names(st_geometry(polys_sf)) = NULL

everything works ok.

Due to this, a check for existence and removal of names in the geometry column should therefore be implemented, probably in normalize-sf.R

(See also https://stackoverflow.com/questions/53227205/polygons-not-getting-plotted-in-leaflet-r-map-since-update and r-spatial/sf#880 (comment))

@schloerke schloerke added priority: high Must be fixed before next release effort: low < 1 day of work difficulty: intermediate Enterprising community members could help labels Nov 13, 2018
@YsoSirius
Copy link

same goes for addPolylines and Linestrings/Multilinestrings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: intermediate Enterprising community members could help effort: low < 1 day of work priority: high Must be fixed before next release
Projects
None yet
Development

No branches or pull requests

3 participants