从栅格单元格中的shapefile计算点数

时间:2016-06-10 20:11:27

标签: r raster

是否可以使用R来计算rasterfile的每个单元格中shapefile的点数?enter image description here

想法是检索包含栅格中每个单元格的一行的数据帧和一个包含该单元格内的点数的列,同时保留栅格单元格中的原始值。

2 个答案:

答案 0 :(得分:0)

这回答标题中的问题"如何计算每个单元格中shapefile的点数"

library(rgdal)           # this package to read and manipulate shapefiles
library(raster)          # this package for rasters
shp <- readOGR("my_shape_file.shp")        # read in your points from the shape file
ras <- raster("my_raster_file")            # read in your raster
shp <- spTransform(shp, projection(ras))   # make sure that the two spatial objects share the same coordinate system
cells <- cellFromXY(ras,shp)     # find which cells the points are in
table(cells)                     # and make a table of number of occurences in each cell

答案 1 :(得分:0)

mem