Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to assign to external road network to generate LINESTRINGS #162

Open
ibarraespinosa opened this issue Oct 14, 2020 · 0 comments

Comments

@ibarraespinosa
Copy link

Hello guys,

I was using your package I found usefull to read generate points for one hour and then assign each point to a OSM road network that I already have to aggregate traffic flow on each street. I'm assigning the points creating a buffer and then intersecting the buffer with the streets. But I'm sure that it gotta be a better/faster way. I was thinking in something like

gps_as_sflinestring(net = net)

with net your own road network as sf LINESTRING, for instance

This is what I am doing

library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(gtfs2emis)
library(magrittr)
library(data.table)
# 0 MASP ####
osm <- st_read("/media/sergio/0A9AD66165F337621/MEGA/PhDgrive/Dados/shapefiles/MASP_OSM_OK.gpkg")
#> Reading layer `MASP_OSM_OK' from data source `/media/sergio/0A9AD66165F337621/MEGA/PhDgrive/Dados/shapefiles/MASP_OSM_OK.gpkg' using driver `GPKG'
#> Simple feature collection with 168079 features and 10 fields
#> geometry type:  MULTILINESTRING
#> dimension:      XY
#> bbox:           xmin: -47.19998 ymin: -24.00792 xmax: -45.70046 ymax: -23.2246
#> geographic CRS: WGS 84
osm <- st_transform(osm, 31983)
# 1 ####
p1 <- "/media/sergio/0A9AD66165F337621/MEGA/PhDgrive/Dados/GTFS/sptrans.zip"
x <- gtfs2gps::read_gtfs(p1) %>%
  gtfs2gps::filter_day_period(period_start = "08:00", period_end = "09:00") %>%
  gtfs2gps::gtfs2gps(parallel = T)
#> Reading 'agency.txt'
#> Reading 'routes.txt'
#> Reading 'stops.txt'
#> Reading 'stop_times.txt'
#> Reading 'shapes.txt'
#> Reading 'trips.txt'
#> Reading 'calendar.txt'
#> Reading 'frequencies.txt'
#> Converting shapes to sf objects
#> Using 11 CPU cores
#> Warning: [ONE-TIME WARNING] Forked processing ('multicore') is disabled
#> in future (>= 1.13.0) when running R from RStudio, because it is
#> considered unstable. Because of this, plan("multicore") will fall
#> back to plan("sequential"), and plan("multiprocess") will fall back to
#> plan("multisession") - not plan("multicore") as in the past. For more details,
#> how to control forked processing or not, and how to silence this warning in
#> future R sessions, see ?future::supportsMulticore
#> Processing the data
#> Warning: `future_options()` is deprecated as of furrr 0.2.0.
#> Please use `furrr_options()` instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_warnings()` to see where this warning was generated.
#> Warning: Shape '47703' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '47737' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '52842' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '52935' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '53190' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '53385' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '53746' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '53811' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '54016' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '54513' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '54775' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '54843' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '55567' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '56484' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '56544' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '56696' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '56995' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '57437' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '57505' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '57986' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '58371' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '58409' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '58422' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '58662' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '58700' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '59662' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '60038' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '60289' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '60536' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '60590' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '60893' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '60899' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '60905' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '61016' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '61099' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '61158' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '61174' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '61283' has less than two stop_sequences after conversion.
#> Ignoring it.
#> Warning: Shape '61357' has less than two stop_sequences after conversion.
#> Ignoring it.
#> 227 out of 266 shapes (85.34%) were properly processed.
#> 227 out of 266 trips (85.34%) were properly processed.
#> Some 'speed' values are NA in the returned data
sx <- st_as_sf(x, 
               coords = c("shape_pt_lon", "shape_pt_lat"),
               crs = 4326)

bx <- st_buffer(st_transform(sx, 31983), 10) #10mts 
bx$ID <- 1
sp <- st_intersection(osm, bx)
#> Warning: attribute variables are assumed to be spatially constant throughout all
#> geometries

spt <- as.data.table(st_set_geometry(sp, NULL))
dt <- spt[, sum(ID), by = osm_id]
sptrans <- merge(osm, dt, by = "osm_id")
plot(sptrans["V1"], axes = T, pal = cptcity::cpt(colorRampPalette = T, rev = T))

Created on 2020-10-13 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant