首页 > 解决方案 > 使用命令 over() 时收到错误消息

问题描述

我有两个形状文件,shp1shp2. 在计算了前者的质心后,我想看看质心在后者的位置。

我的设置是:

shp1@data$centroid <- gCentroid(shp1, byid = TRUE)
foo <- over(shp1$centroid, shp2)

执行第二行后,我收到以下错误消息:

Error in xj[i] : NAs not permitted in row index

知道我应该寻找什么来避免这个错误吗?(注意:grep("NA", row.names(shp1))返回integer(0),也适用于其他形状文件。)

标签: rshapefilecentroidrgeo-shapefile

解决方案


刚刚弄清楚为什么会发生此错误:

除此之外shp1@data$centroid <- gCentroid(shp1, byid = TRUE),我shp2@data$centroid <- gCentroid(shp2, byid = TRUE)在调用之前也做过foo <- over(shp1$centroid, shp2),这显然导致了错误。


推荐阅读