基本上,我正在尝试将sf对象转换为光栅文件,以便使用leaflet进行绘图。sf对象如下所示:
Simple feature collection with 33901 features and 1 field
geometry type: POINT
dimension: XY
bbox: xmin: 63.42624931 ymin: -18.21972306 xmax: 175.2237467 ymax: 58.60000076
geographic CRS: WGS 84
First 10 features:
df$prhmax geometry
1 24.46245324 POINT (77.57315415 -17.2288...
2 24.48866948 POINT (77.97969243 -17.1712...
3 24.51029786 POINT (78.38618742 -17.1142...
4 24.51992770 POINT (78.79264389 -17.0577...
5 24.52394288 POINT (79.199056 -17.00185241)
6 24.53245239 POINT (79.60542849 -16.9464...
7 24.56160049 POINT (80.01176604 -16.8915...
8 24.60146712 POINT (80.41806278 -16.8372...
9 24.62994385 POINT (80.82432335 -16.783531)
10 24.65465755 POINT (81.23055239 -16.7303...我一直在努力解决这个问题。如果我只是做绘图(sf.object),它工作得很好,但我不能制作栅格。
发布于 2020-11-17 02:27:25
生成栅格层并栅格化其上的点。
# Load packages
packs <- list("tidyverse", "raster", "sf")
lapply(packs, require, character.only = T)
# Convert points to sp (assumes that the sf object is called example_points)
example_points <- as(example_points, "Spatial")
# Generate empty raster layer and rasterize points
example_raster <- raster(crs = crs(example_points), vals = 0, resolution = c(0.5, 0.5), ext = extent(c(-180, 180, -90, 90))) %>%
rasterize(example_points, .)假设这些点是经纬度投影的,代码将生成分辨率为30 x 30角分的全局栅格图层,并将像元值设置为零。然后,rasterize将点转换为基于样例光栅图层的光栅图层。您可能希望设置rasterize函数的field和fun参数,这两个参数控制这些点如何确定单元格值。使用前者,您可以控制哪个变量设置单元格值。后者定义了计算单元格值的函数-例如,计算与像素相交的点或计算所有交叉点的值的平均值。
https://stackoverflow.com/questions/64806684
复制相似问题