2016-06-10 2 views
-1

R을 사용하여 래스터 파일의 각 셀 내에있는 셰이프 파일에서 포인트 수를 계산할 수 있습니까? enter image description here래스터 셀 내 shapefile의 카운트 포인트

아이디어는 래스터 셀의 원래 값을 유지하면서 래스터의 각 셀에 대해 하나의 행과 해당 셀 내에있는 점 수의 열을 포함하는 데이터 프레임을 검색하는 것입니다.

+0

에 오신 것을 환영합니다 "어떻게 각 셀 내의 모양 파일에서 점의 수를 계산하는 방법"을 참조하십시오. 이 사이트의 일반적인 형식은 코드를 처음부터 작성하도록 요청하기보다는 시도한 내용과 실패한 방법을 보여주기위한 것입니다. 도움말 페이지를 읽으려면 잠시 시간을 내야합니다. 특히 "여기에 대해 내가 무엇에 관해 물을 수 있습니까?"] (http://stackoverflow.com/help/on-topic) 및 [어떤 유형의 질문을하지 않아야합니까? "] (http://stackoverflow.com/help/dont-ask). [Minimal, Complete, Verifiable Examples] (http://stackoverflow.com/help/mcve)에 대해서도 배워야합니다. – dww

답변

0

이 제목에 질문에 대한 답에 StackOverflow에

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 
0
library(raster) 
# example raster and points data 
r <- raster(ncols=10, nrows=5) 
n <- 100 
x <- runif(n) * 360 - 180 
y <- runif(n) * 180 - 90 
xy <- cbind(x, y) 

rp <- rasterize(xy, r, fun=function(x,...)length(x)) 
as.data.frame(rp)