[英]find out how many of points in my dataframe are overlapping an area shapefile
I have a dataframe containing list of all accidents and their locations (about 10,000 location coordinates) that took place in a city in a month. 我有一个数据框,其中包含一个月内某个城市发生的所有事故及其位置(约10,000个位置坐标)的列表。
Accident ID Name latitudes longitudes Intensity time
1 citycentre -25.5567 +54.00087 minor morning
2
3
4
I need to find how many of those accidents took place between a given set of longitudes and latitudes.(eg between latitudes 25'S and 27'S, lontitudes 54 E and 55 E) 我需要找出在给定的一组经度和纬度之间(例如在25'S和27'S纬度,54 E和55 E纬度之间)发生了哪些事故。
Is there a way to do such a thing on RI am new to R so any help will be much appreciated.I have to do the same process with data from a large number of months and between different pairs of coordinates.So running a loop and using a counter variable will be very time consuming. 有没有办法在RI上对RI来说是陌生的,所以任何帮助将不胜感激。我必须对来自大量月份且在不同坐标对之间的数据执行相同的处理。使用计数器变量将非常耗时。
Is there a functional available that will tell me the number of accidents if I make my study area into a polygon shape file 如果我将学习区域制成多边形形状文件,是否有可用的功能可以告诉我发生事故的次数
I'm sure there are many ways to do it. 我敢肯定有很多方法可以做到。 Here's just one using non-equi joins:
这只是使用非等额联接的一种:
library(data.table)
points <- fread("Accident_ID Name latitudes longitudes Intensity time
1 citycentre -28.5567 +54.50087 minor morning
2 citycentre -28.5567 +54.50087 minor morning
3 citycentre 0 0 minor morning
4 citycentre 100 100 minor morning")
extents <- data.table(
extent_id=1:3,
x1=c(-30, -20, 1000),
x2=c(-27, 20, 1100),
y1=c(54, -54, 100),
y2=c(55, 55, 100)
)
points[extents, on=.(latitudes>=x1, latitudes<=x2, longitudes>=y1, longitudes<=y2)][
,.(N=sum(!is.na(Accident_ID))), by=extent_id]
# extent_id N
# 1: 1 2
# 2: 2 1
# 3: 3 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.