【问题标题】:R select spatial polygon with point insideR选择内部点的空间多边形
【发布时间】:2014-01-23 07:30:21
【问题描述】:

我有一个 shapeFile 和一个 spatialPointsDataframe ...我想选择其中有点的所有多边形,并在 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

但在那之后我不知道如何选择多边形。我试过了

vitiWord<-word[tps]

但它不起作用

下载示例 -> link

【问题讨论】:

  • 你能做一个可重现的例子吗?会有很大帮助
  • 我没试过,但也许 word[tps, ] 可以工作
  • 不,它对单词 [tps,] 不起作用。 tps 是一个逻辑向量,我在表中没有变量来执行类似 word[tps==TRUE] 的操作
  • 事实上,我想在 GIS 中为选定的所有存在点 insisde 的多边形访问一个函数
  • 好吧,如果你举一个多边形和一些点的例子(使用来自包或保管箱链接的数据),我保证会处理它(我相信其他人也会有所帮助),否则我不会'现在没有时间创建可重现的示例。如果您需要一些帮助,那么典型的是 StackOverflow,然后通过提供一个我可以在我的计算机上运行的示例来“帮助”那些愿意提供帮助的人。

标签: r spatial


【解决方案1】:

我找到了一些东西... 我真的不知道它是否有效,因为我想在之后使用 ggplot 并且效果不佳,但是

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

您在空间数据帧中拥有所有变量!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-15
    • 2020-04-04
    • 2017-02-18
    • 1970-01-01
    • 2017-09-15
    • 2014-06-16
    • 2016-06-11
    • 2021-05-28
    相关资源
    最近更新 更多