gpt4 book ai didi

python - 在 R 传单 map 上叠加图像

转载 作者:行者123 更新时间:2023-11-28 18:18:03 25 4
gpt4 key购买 nike

我有一个 .PNG 图像,它基本上表示是光栅,但不是光栅格式。这些是提供给我的,否则我会自己将它们生成为栅格并避免这个问题。

我想在 R 中将图像覆盖在传单 basemap 上。图像覆盖仅为用户提供引用,以在区域周围绘制边界框,并查询数据库以获取生成光栅的原始数据那个地区。

在 Python 的 leaflet 实现中,可以通过这种方式实现图像叠加

center = [0,0]
zoom = 2

m = Map(center=center, zoom=zoom)
layer = ImageOverlay(url="filename.png", bounds=(( min_lat, min_lon),
(max_lat, max_lon)))
m.add_layer(layer)
return m

到目前为止,它看起来像是在 R 中执行此操作,我需要一个光栅对象,然后使用 addRasterImage(),它似乎将光栅转换为 RGB 图像,然后将其覆盖在传单上 map 。我最初有一个图像,只是想将其添加为图层而不是需要光栅格式。谢谢。

最佳答案

如果您需要附加图像而不是之后更改它(bbox 或源),那么您应该能够使用 htmlwidgets 访问原生 leaflet.js 来做到这一点:

The htmlwidget::onRender function can be used to add custom behavior to the leaflet map using native Javascript. This is a some what advanced use case and requires you to know Javascript. Using onRender you can customize your map’s behavior using any of the APIs as defined in the Leaflet.js documentation. (from leaflet r documentation)

这通过显示更广泛的 native 功能为您提供了更多的灵 active 。添加图像覆盖非常简单 (example) 并且类似于 python 实现。从 r 和 js 文档版本中采用的一个简单示例可能如下所示:

library(leaflet)

m <- leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addMarkers(lng=-74.22655, lat=40.712216, popup="Bottom Right Corner") %>%
htmlwidgets::onRender("
function(el, x) {
console.log(this);
var myMap = this;
var imageUrl = 'http://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg';
var imageBounds = [[40.712216, -74.22655], [40.773941, -74.12544]];

L.imageOverlay(imageUrl, imageBounds).addTo(myMap);
}
")
m # Print the map

关于python - 在 R 传单 map 上叠加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47170828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com