Add function to convert gtfs
object to sp
(similar to gtfs2sldf()
)
#24
Comments
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. |
The help would be very much appreciated! My skills are very low.
On Jan 5, 2017 7:18 PM, "Michael Sumner" <notifications@github.com> wrote:
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.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#24 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFaR2Y1OXtGKKr5ES1sIKPmV4TzEYg7zks5rPYhUgaJpZM4KKt16>
.
|
One way is to use the re-compose function 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 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 |
@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. |
Added @tombuckley gtfs routes to |
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. |
Awesome! Thanks! |
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. |
Suggestion: explore options for converting gtfs data classes into spatial objects such as SpatialLinesDataFrame.
Note: stplanr has a basic function for this: gtfs2sldf().
The text was updated successfully, but these errors were encountered: