问题描述
我正在使用R,我想将一些栅格数据(例如模型中的温度图)覆盖在允许平移和缩放的交互式地图上.理想情况下,我想覆盖Google Maps或OpenStreetMaps.输入数据可以在shapefile,KML,raster
数据或方便的任何内容中.
I'm using R, and I want to overlay some raster data (e.g. a temperature map from a model) over an interactive map which allows panning and zooming. Ideally, I'd like to overlay over Google Maps or OpenStreetMaps. The input data can be in shapefiles, KML, raster
data or whatever comes in handy.
-
我知道我可以使用
googleVis
,ggmap
或RgoogleMaps
轻松地非交互地执行此操作.但是我不想使用图块,我想互动!直接从浏览器进行缩放,平移等.
I know I can easily do this non-interactively using either
googleVis
,ggmap
orRgoogleMaps
. But I do not want to use tiles, I want interaction! Zooming, panning etc., directly from the browser.
googleVis
只能以交互方式显示点或地址,而不能显示区域.
googleVis
, as far as I know, unfortunately only allows to show interactively points or addresses, not areas.
此问题是非常相似的,但是我绝对想尝试使用R做到这一点.我可以从R创建KML或geoJSON,但是如何直接从R覆盖它呢?
This question is very similar but I definitely want to try to do this using R. I can create the KML or geoJSON from R, but how do I overlay it from R directly?
OpenStreetMaps也很好,但是尽管OSM似乎具有一个非常简单的API .
OpenStreetMaps is also fine, however I've not found any reference on how to overlay data over it from R, despite the fact that OSM seems to have a pretty straightforward API.
推荐答案
您可能会对leaflet
软件包感兴趣.您可以轻松添加raster
对象.从文档
The leaflet
package may be of interest for you. You can easily add a raster
object. From the documentation
这也是文档中的示例:
And here is an example also from the documentation:
library(leaflet)
library(raster)
r <- raster("nc/oisst-sst.nc")
pal <- colorNumeric(c("#0C2C84", "#41B6C4", "#FFFFCC"), values(r),
na.color = "transparent")
leaflet() %>% addTiles() %>%
addRasterImage(r, colors = pal, opacity = 0.8) %>%
addLegend(pal = pal, values = values(r),
title = "Surface temp")
这篇关于在交互式地图上覆盖shapefile或栅格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!