sp :: over()用于多边形分析中的点

问题描述 投票:25回答:4

我有一个名为“ind_adm”的shapefile和一个名为“pnts”的SpatialPointsDataFrame。 “pnts”包含随机生成的点,并且一些点与多边形重叠。见下图。

现在,我想在多边形分析中做一点,即我想找出哪些点位于代表印度边界的灰色多边形内。为此我在sp库中使用over()函数。

pt.in.poly <- sp::over(ind_adm, pnts, fn = mean) #do the join

但是,我得到的输出是

    >pt.in.poly
    values
    0 6.019467

我应该得到多边形“在”中的点的索引。

我哪里错了?

r gis polygon shapefile
4个回答
21
投票

你不应该提供一个功能。您将在多边形的几何图形上聚合点的属性值(即返回的数字是落在多边形内的点的属性的mean)。另外,你有你的xy错误的方式你想做什么。应该...

over( pnts , ind_adm , fn = NULL) 

19
投票

找到这种简洁直观的语法:

   pnts[ind_adm,] 

来自this介绍文件


7
投票

你可以使用point.in.poly fom spatialEco包。它“与点和面要素类相交,并将多边形属性添加到点”。

library(spatialEco)

new_shape <- point.in.poly(pnts, ind_adm)

0
投票

您还可以使用st_intersection包中的sf函数:

Load the library

library(sf)

Create a simple feature geometry (polygon) from your polygon

ind_adm <- st_as_sf(ind_adm)

Create a simple feature geometry (point) from your points of interest

(24047是印度的EPSG代码)

pnts <- st_as_sf(pnts) %>% st_set_crs(., 24047)

Keep only the points inside the polygon

kept_points <- st_intersection(ind_adm, pnts)

© www.soinside.com 2019 - 2024. All rights reserved.