Comments (8)
sf will be a better target now, sp has a subset of what sf can store. I'm happy to explore this, I've got my sf skillz pretty well sorted.
from gtfsr.
It definitely looks fine to me, @mpadge will have stronger insights about the best ways to manage the conversions, but I'd say that can be put off.
These functions (in convert_gtfs.R) definitely need examples and stronger title and description slots. They could be bundled together in one Rd.
from gtfsr.
from gtfsr.
One way is to use the re-compose function spbabel::sp
, which is looking for the generic names "object_", "branch_", "order_", "x_", "y_" which correspond to your shape_id (one branch per object), shape_pt_sequence, shape_pt_lon and shape_pt_lat.
library(spbabel)
sp_line <- sp(transmute(NYC$shapes_df, object_ = shape_id, branch_ = shape_id, order_ = shape_pt_sequence, x_ = shape_pt_lon, y_ = shape_pt_lat), crs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
sp_line$shape_id <- unique(NYC$shapes_df$shape_id)
sp_line$rownumber_ <- NULL
That can be converted to sf
using sf::st_as_sf
, and more directly the dev version of spbabel has stubs for the sf()
function, that I haven't implemented :)
But, for that shapes_df it's more or less like this:
library(sf)
library(dplyr)
sf_line <- distinct(NYC$shapes_df, shape_id)
sf_line[["geometry"]] <- st_sfc(lapply(split(NYC$shapes_df, NYC$shapes_df$shape_id), function(x) st_linestring(as.matrix(x[order(x$shape_pt_sequence), c("shape_pt_lon", "shape_pt_lat")]))), crs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
sf_line <- st_as_sf(sf_line)
## make shape_id a factor so plot works (but watch out for ggplot2::geom_sf coming soon)
sf_line$shape_id <- factor(sf_line$shape_id)
I hope that helps, I'm happy to go deeper if you need, but I kind of need to hear what work flows you'll want. I am interested, I've been watching the progress being made a Sydney Transit recently!
You can't really have a line with properties on the vertices or on the segments, though you can have Z and M but they have to be floating point (same as x, y) so you can't store arbitrary stuff there. In the past I've used the trip package as a really primitive way of doing that, and recently I've worked on more abstract forms in spbabel and rangl, but I can't quite pin it down yet.
You can easily break these lines into vertices and segments and store them right in a dataframe, and grouping and recombining them in sf
world is pretty good. Feel free to ping me with your ideas about what would be really helpful and I'll try to do it. It's reasonably easy to merge in elevation and time and plot these things in 3- and 4-D and I'm very interested to start doing that with examples like this.
from gtfsr.
@mdsumner thanks for those snippets! @dantonnoriega thanks for this excellent package! as you can see above, i'm poking around with questions like this. let me know if you have any questions.
from gtfsr.
Added @tombuckley gtfs routes to sf
function. @mdsumner, once the release is live, would you mind checking out the results? I'm not familiar enough with sf
data to understand the benefit.
from gtfsr.
I can do that. One thing I learnt just now is to ensure lower level classes in sp don't have named lists which is a side effect of some approaches I have used. Fwiw running mapview on a sprint object is a good way to visualize it, check for basic sense.
from gtfsr.
Awesome! Thanks!
from gtfsr.
Related Issues (20)
- Add package level manual
- read_gtfs will delete invalid gtfs zip files. HOT 1
- Add more examples throughout package
- New format maybe worth knowing HOT 1
- Added overlays for stops and routes HOT 1
- add docs for os-specific setup? HOT 4
- Calculating distance of each trip_id and shape_id HOT 24
- Dealing with irregular, unrecognised GTFS files HOT 4
- GTFS Realtime HOT 4
- summarise_each deprecated HOT 1
- Update for newer version of R HOT 2
- Can't build vignettes HOT 11
- cran release HOT 5
- separate validation, joining, and mapping? HOT 4
- Add names of recent contributors to description HOT 3
- consider breaking off pieces of the package that make maintenance and CRAN submission harder HOT 7
- trouble installing on windows and rstudio.cloud HOT 1
- API key HOT 2
- Is this package still maintained? HOT 3
- New Maintainer Wanted :-) HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gtfsr.