sp::over() for point in polygon analysis

自古美人都是妖i 提交于 2019-11-28 05:20:33

You should not supply a function. You are aggregating the attribute values of your points over the geometry of the polygon, (i.e. the number returned is the mean of the attribute of the points that fall within the polygon). In addition you have your x and y the wrong way round for what you want to do. Should be...

over( pnts , ind_adm , fn = NULL) 

Found this concise and intuitive syntax for over:

   pnts[ind_adm,] 

from this Intro document

You can use point.in.poly fom spatialEco package. It "intersects point and polygon feature classes and adds polygon attributes to points".

library(spatialEco)

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

You could also use the st_intersection function from the sf package:

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 is the EPSG code for India)

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

Keep only the points inside the polygon

kept_points <- st_intersection(ind_adm, pnts)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!