mhe*_*ans 1 r openstreetmap leaflet r-sf
sf我正在尝试使用和在 R 中显示(断开连接的)线串的简单特征集合leaflet。数据是从 openstreetmap 获取的osmdata。
使用基本的plot()函数,tmap, 或mapview,我可以直接在静态和交互式地图上显示线串。但是,这在使用时不起作用leaflet。Leaflet 正确地将地图居中,但不显示线串。在 addPolyLines() 中摆弄颜色、重量等参数似乎没有帮助。
雷普莱克斯
\n\nlibrary(osmdata)\nlibrary(leaflet)\nlibrary(sf)\nlibrary(tmap)\n\nosm <- opq(bbox = c(-0.27, 51.47, -0.20, 51.50)) %>%\n add_osm_feature(key = \'name\', value = "Thames", value_exact = FALSE) %>%\n osmdata_sf()\n\nosm$osm_lines\n\nSimple feature collection with 2085 features and 178 fields\ngeometry type: LINESTRING\ndimension: XY\nbbox: xmin: -2.029917 ymin: 51.37841 xmax: 0.6778926 ymax: 51.79032\nepsg (SRID): 4326\nproj4string: +proj=longlat +datum=WGS84 +no_defs\nFirst 10 features:\n...\n\nplot(osm$osm_lines, max.plot = 1) # OK\nqtm(osm$osm_lines) + tm_lines() # OK\nmapview(osm$osm_lines) # OK\n\nleaflet(osm$osm_lines) %>% # not OK (grey)\n addPolylines()\nRun Code Online (Sandbox Code Playgroud)\n\n会话信息
\n\n> library(sf)\nLinking to GEOS 3.6.1, GDAL 2.2.3, proj.4 4.9.3\nWarning message:\n package \xe2\x80\x98sf\xe2\x80\x99 was built under R version 3.4.4 \n\n> sessionInfo()\nR version 3.4.3 (2017-11-30)\nPlatform: x86_64-w64-mingw32/x64 (64-bit)\nRunning under: Windows >= 8 x64 (build 9200)\n\nMatrix products: default\n\nlocale:\n [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C \n[5] LC_TIME=English_United States.1252 \n\nattached base packages:\n [1] stats graphics grDevices utils datasets methods base \n\nother attached packages:\n [1] tmap_1.11-2 sf_0.6-3 leaflet_2.0.1 osmdata_0.0.7\n\nloaded via a namespace (and not attached):\n [1] httr_1.3.1 viridisLite_0.3.0 jsonlite_1.5 splines_3.4.3 geojsonlint_0.2.0 foreach_1.4.4 R.utils_2.6.0 gtools_3.5.0 \n[9] shiny_1.1.0 expm_0.999-2 sp_1.3-1 stats4_3.4.3 yaml_2.1.19 LearnBayes_2.15.1 lattice_0.20-35 digest_0.6.15 \n[17] RColorBrewer_1.1-2 promises_1.0.1 rvest_0.3.2 colorspace_1.3-2 plyr_1.8.4 htmltools_0.3.6 httpuv_1.4.3 Matrix_1.2-12 \n[25] R.oo_1.22.0 XML_3.98-1.11 rmapshaper_0.4.0 raster_2.6-7 gmodels_2.16.2 xtable_1.8-2 webshot_0.5.0 scales_0.5.0 \n[33] gdata_2.18.0 satellite_1.0.1 later_0.7.3 gdalUtils_2.0.1.14 mapview_2.4.0 magrittr_1.5 mime_0.5 deldir_0.1-15 \n[41] R.methodsS3_1.7.1 nlme_3.1-131 MASS_7.3-47 xml2_1.2.0 class_7.3-14 tools_3.4.3 geosphere_1.5-7 stringr_1.3.1 \n[49] V8_1.5 munsell_0.5.0 compiler_3.4.3 e1071_1.6-8 classInt_0.2-3 units_0.6-0 grid_3.4.3 tmaptools_1.2-4 \n[57] RCurl_1.95-4.10 dichromat_2.0-0 iterators_1.0.9 htmlwidgets_1.2 crosstalk_1.0.0 bitops_1.0-6 base64enc_0.1-3 boot_1.3-20 \n[65] codetools_0.2-15 DBI_1.0.0 jsonvalidate_1.0.0 curl_3.2 R6_2.2.2 lubridate_1.7.4 rgdal_1.3-2 rgeos_0.3-28 \n[73] spdep_0.7-7 KernSmooth_2.23-15 stringi_1.1.7 osmar_1.1-7 Rcpp_0.12.17 png_0.1-7 spData_0.2.8.3 coda_0.19-1 \nRun Code Online (Sandbox Code Playgroud)\n
osmdata 具有命名功能,传单无法读取。请参阅https://github.com/ropensci/osmdata/issues/100
作为一种 hack,你可以将名称设置为 NULL:
osm_lines <- osm$osm_lines
names(osm_lines$geometry) <- NULL
leaflet(osm_lines) %>%
addPolylines()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
847 次 |
| 最近记录: |