2017-04-07 85 views
0

我試圖用疊加功能和代碼繼承的方法如下:錯誤(函數(類,FDEF,mtable):無法找到函數「覆蓋」

usa <- map('state',boundary = FALSE, lty=2,plot=FALSE,fill=TRUE) 
usa_SP <- map2SpatialPolygons(usa, IDs=usa$names, proj4string = CRS("+proj=longlat")) 

comB.dat <- read.csv("agbregion.csv",header=TRUE) 
names(comB.dat) <- c("Lon","Lat","harvDB") 
names(AGByr)<- c("Lon","Lat","harvDB") 
names(AGBdiff) <- c("Lon","Lat","harvDB") 

pts <- SpatialPoints(cbind(comB.dat$Lon,comB.dat$Lat)) 
ptsyr <- SpatialPoints(cbind(AGByr$Lon,AGByr$Lat)) 
ptsdiff <- SpatialPoints(cbind(AGBdiff$Lon,AGBdiff$Lat)) 

o <- overlay(pts, usa_SP) 

但我得到以下錯誤: (函數(類,fdef,mtable)中的錯誤:找不到函數'overlay'進行簽名''SpatialPoints','SpatialPolygons''的繼承方法'

我不知道發生了什麼有人可以爲我解釋嗎?非常感謝。

回答

0

查看?raster::overlay的幫助。注意前幾行。

## S4 method for signature 'Raster,Raster' 
overlay(x, y, ..., fun, filename="", recycle=TRUE, forcefun=FALSE) 

## S4 method for signature 'Raster,missing' 
overlay(x, y, ..., fun, filename="", unstack=TRUE, forcefun=FALSE) 

這告訴你,這種方法只適用於Raster對象,如RasterLayerRasterStack等。

考慮使用sp::over,這是宣佈

consistent spatial overlay for points, grids and polygons: at the spatial locations of object x retrieves the indexes or attributes from spatial object y

+0

謝謝你的解釋。我跟着你的建議使用over函數和代碼是:o < - over(pts,usa_SP,returnList = TRUE),但得到了另一個錯誤:錯誤:並非所有identicalCRS(x,y)都爲TRUE。有什麼問題,我該如何解決? – pandaJ

+0

@pandaJ你有沒有試過在網上找這個錯誤? –

+0

LuštrikYeah,我做了一些搜索,沒有相對的答案。但我已經解決了這個問題,並再次感謝你。 – pandaJ