简体   繁体   中英

R select spatial polygon with point inside

I have a shapeFile and a spatialPointsDataframe ... I would like to select all polygon where there is point(s) inside, and merge points information in shp@data

word<-readOGR(dsn="data/world/ne_110m_admin_0_countries.shp", layer="ne_110m_admin_0_countries")
xy<-cbind(geoloc$longitude,geoloc$latitude)
spxy<-SpatialPoints(xy)
spdfxy<-SpatialPointsDataFrame(spxy,geoloc)
spdfxy@data<-merge(spdfxy@data,data2000geo)

tps<-!is.na(over(spdfxy,word)) ##retourne the indexe of atribut of y renvois les atribut de word

But after that I don't know how select polygones. i have tried

vitiWord<-word[tps]

but it's doesn't work

for download exemple -> link

I 'have find some thing... I don't realy know if it work because I would like to use ggplot after and it doesn't work well, but whit

jointure<-over(word,spdfxy) #over from sp library
word@data<-cbind(word@data,jointure)

You have all variable from point in the spatialDataFrame !!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM