R:裁剪网格时“下标超出范围”

时间:2019-05-21 15:32:48

标签: r grid geospatial crop kriging

我将使用kriging方法对数据进行空间插值。要继续,我需要在法国地图上使用网格模型。

为此,我正在遵循本课程的第4章:https://www.datacamp.com/courses/spatial-statistics-in-r

不幸的是,当我想将网格裁剪到学习区域时,出现此错误: "Error in x@coords[i, , drop = FALSE] : subscript out of bounds".

即使我制作了更大或更小的网格,该错误仍然会出现。

这是我的R代码:

#Read the France map (spatial polygon dataframe)
communes <- readOGR(dsn=paste("donnees/GEOFLA_2-2_COMMUNE_SHP_LAMB93_FXX_2016-06-28/GEOFLA/1_DONNEES_LIVRAISON_2016-06-00236/GEOFLA_2-2_SHP_LAMB93_FR-ED161/COMMUNE", sep = ""), layer="COMMUNE")

# Find the corners of the boundary
bbox(communes)
        min     max
x   99217.1 1242417
y 6049646.3 7110480

# Define a 10km square grid over the polygon extent. The first parameter is the bottom left corner.
grid <- GridTopology(c(99216,6049645), c(10000, 10000), c(120, 120))

# Create points with the same coordinate system as the boundary
gridpoints <- SpatialPoints(grid, proj4string = CRS(projection(communes)))

# Crop out the points outside the boundary
cropped_gridpoints <- crop(gridpoints, communes)

Error in x@coords[i, , drop = FALSE] : subscript out of bounds

在最后一行,网格应该与地图的边缘匹配,但是会出现错误。这是dl shapefile的链接:https://www.dropbox.com/sh/g2gm30zxpdgr0ok/AABrGMDrA3KX8LSWLzBmFDb7a?dl=0

0 个答案:

没有答案