Cran Contributed Packages
library(maptools)
library(rgdal)
library(sp)
library(sf)
library(tigris)
library(hrbrthemes)
library(tidyverse)
require(spatialEco)
library(maptools)
###library(GISTools)
library(rgdal)
## March Crash
setwd("D:/From Syncplicity/Bulk_Papers/03142019/covid/NY_TrafficCrash/covid-19-data-master")
march <- read.csv("NY_March_CrashesLL02.csv")
dim(march)
## [1] 117817 6
## [1] "ID" "lat" "long"
## [4] "ON.STREET.NAME" "CROSS.STREET.NAME" "OFF.STREET.NAME"
coordinates(march)=~long+lat
proj4string(march)<- CRS("+proj=longlat +datum=WGS84")
march1 <-spTransform(march,CRS("+proj=longlat"))
### NY TaxiZone
st_read("D:/From Syncplicity/Bulk_Papers/03142019/covid/NY_TrafficCrash/zones.geojson") %>%
st_set_crs(4326) %>%
st_transform("+proj=longlat +datum=WGS84 +no_defs") -> ny
## Reading layer `zones' from data source `D:\From Syncplicity\Bulk_Papers\03142019\covid\NY_TrafficCrash\zones.geojson' using driver `GeoJSON'
## Simple feature collection with 263 features and 6 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: -74.25559 ymin: 40.49612 xmax: -73.70001 ymax: 40.91553
## epsg (SRID): 4326
## proj4string: +proj=longlat +datum=WGS84 +no_defs

pts_sf = st_as_sf(march1)
p_sf = st_as_sf(ny)
st_crs(p_sf)
## Coordinate Reference System:
## EPSG: 4326
## proj4string: "+proj=longlat +datum=WGS84 +no_defs"
p_sf1= st_transform(p_sf, st_crs(pts_sf))
##https://mgimond.github.io/Spatial/index.html
## https://cengel.github.io/R-spatial/spatialops.html
nn= p_sf1 %>%
st_join(pts_sf) %>%
group_by(zone) %>%
summarize(count = n())
nn
## Simple feature collection with 260 features and 2 fields
## geometry type: GEOMETRY
## dimension: XY
## bbox: xmin: -74.25559 ymin: 40.49612 xmax: -73.70001 ymax: 40.91553
## epsg (SRID): 4326
## proj4string: +proj=longlat +ellps=WGS84 +no_defs
## # A tibble: 260 x 3
## zone count geometry
## * <fct> <int> <POLYGON [°]>
## 1 Allerton/Pelham~ 280 ((-73.84793 40.87134, -73.84725 40.87099, -73.84699 4~
## 2 Alphabet City 188 ((-73.97177 40.72582, -73.97179 40.72581, -73.97182 4~
## 3 Arden Heights 122 ((-74.17422 40.56257, -74.17349 40.56227, -74.17226 4~
## 4 Arrochar/Fort W~ 268 ((-74.06367 40.6022, -74.06351 40.60215, -74.06383 40~
## 5 Astoria 872 ((-73.90414 40.76752, -73.90325 40.7675, -73.90301 40~
## 6 Astoria Park 11 ((-73.92334 40.77513, -73.92398 40.77462, -73.92523 4~
## 7 Auburndale 313 ((-73.78502 40.76104, -73.78486 40.76064, -73.78468 4~
## 8 Baisley Park 536 ((-73.78327 40.68999, -73.78234 40.68841, -73.78149 4~
## 9 Bath Beach 336 ((-74.0011 40.60303, -74.00032 40.60262, -74.00002 40~
## 10 Battery Park 21 ((-74.01566 40.70483, -74.0154 40.7048, -74.01527 40.~
## # ... with 250 more rows
