如何用外部图像填充地图边界? [英] How to fill map boundaries with external images?
问题描述
我正在创建一个带有州边界的巴西地图,可以直接使用 ggplot2
和 geom_sf
来实现.
但是,这次,我不想用数据填充每个州的颜色,而是要使用外部图像(png)填充每个州的边界,类似于
我尝试了 geom_image
甚至 geom_flag
的一些设置都没有用(因此为什么我不在这里发布任何代码).
关于如何解决此问题,有什么建议吗?
您可以尝试 cartography :: getPngLayer/pngLayer
.这两个函数将png作为输入,对其进行地理标记并将其裁剪为给定多边形的形状,并创建一个您可以操作和绘制的 rasterbrick
对象(作为图块):
https://dieghernan.github.io/cartographyvignette#png-layer
I am creating a map of Brazil with its state boundaries, which is straight forward to achieve using ggplot2
and geom_sf
.
However, this time around, instead of color filling each state with data, I want to fill each state's boundaries with an external image (png), similar to this example of the largest employer in each state.
I have tried a few settings of geom_image
and even geom_flag
to no avail (hence why I am not posting any code here).
Are there any suggestions on how to approach this problem?
You can try cartography::getPngLayer/pngLayer
. These two functions takes a png as input, geotag and crop it to the shape of a given polygon and creates a rasterbrick
object (as a tile) that you can manipulate and plot:
https://dieghernan.github.io/cartographyvignette#png-layer
这篇关于如何用外部图像填充地图边界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!