我在这里使用R作为GIS来创建地图。这是一个单色(黑/白)网站计划。但是,我想使用these open triangular symbols for coniferous forests来区分森林与其他地区,这在德语世界的制图中很常见。
一些研究让我从my.symbols
包中找到了TeachingDemos
函数。我理解可以在xlim = c(-1,1)
,ylim = c(-1,1)
图中编写绘制所需符号的函数,然后使用TeachingDemos::my.symbols
将此符号与points
函数一起添加到图中。我的计划是给TeachingDemos::my.symbols
森林区域内网格的坐标。
我设法写了一个绘制符号的函数:
nw <- function(){
par(oma = c(0,0,0,0), mar = c(0,0,0,0))
plot(c(-0.84, 0), c(-0.4, 0.67), xlim = c(-1,1), ylim = c(-1,1), type = "l", lwd = 2)
segments(0, 0.67, 0.84, -0.4, lwd = 4)
}
但我没有设法以正确的方式将功能传递给my.symbols
。我也没有设法仅在林多边形中扩展网格,因此将其扩展到多边形图层的整个边界框({{1}}),并仅选择位于林中的点。类似的东西:
bbox
答案 0 :(得分:2)
您可以使用库sp
对特定多边形中的点进行采样。在我的示例中,我根据NAME
选择了一个特定的多边形
然后你可以使用库emojifont
从表情符号或fontawesome中添加一些符号。例如,您可以在列表中找到evergreen_tree
之类的树。或者您可以重复绘制自己的png图像。
因此,首先为特定多边形创建网格:
library(maptools)
library(rgdal)
library(sp)
library(emojifont)
nc1 <- rgdal::readOGR(system.file("shapes/sids.shp", package = "maptools")[1])
# Do a point grid in a specific polygon
grid.pt <- sp::spsample(nc1[which(nc1$NAME == "Alamance"),], n = 20, type = "regular")
然后使用grid.pt
将表情符号绘制为文本:
# plot the entire map with restricted limits
plot(nc1, xlim = c(-79.6, -79.1), ylim = c(35.8, 36.3))
# Highlight the selected polygon
plot(nc1[which(nc1$NAME == "Alamance"),], border = "red", lwd = 3, add = TRUE)
# Normal points
points(grid.pt, pch = 20, col = "blue", cex = 0.1)
# Add emojifont instead of points
text(coordinates(grid.pt)[, 1], coordinates(grid.pt)[, 2],
labels = emoji('evergreen_tree'), cex = 1.5,
col = 'forestgreen', family = 'EmojiOne')
您也可以使用自己的png图像作为点。在此回复中,图像作为可重现的示例下载到网络上:https://gis.stackexchange.com/questions/118286/is-it-possible-to-create-a-scatterplot-with-icons-svg-or-png-instead-of-points
但是,您可以创建和使用自己的png图像。
# Plot with your own image
library(png)
# Image downloaded as an example for reproducibility
iconfile1 <- download.file('http://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/256/Status-weather-clouds-icon.png',
destfile = 'icon1.png', mode = 'wb')
icon1 <- png::readPNG('icon1.png')
# Depending on the desired size of the image
offset <- 0.02
# plot the entire map with restricted limits
plot(nc1, xlim = c(-79.8, -78.9), ylim = c(35.6, 36.5))
# Plot all images at points locations
for (i in 1:length(grid.pt)) {
graphics::rasterImage(
icon1,
coordinates(grid.pt)[i, 1] - offset,
coordinates(grid.pt)[i, 2] - offset,
coordinates(grid.pt)[i, 1] + offset,
coordinates(grid.pt)[i, 2] + offset
)
}