Giter Site home page Giter Site logo

Comments (8)

mdsumner avatar mdsumner commented on June 15, 2024 2

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.

mdsumner avatar mdsumner commented on June 15, 2024 1

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.

dantonnoriega avatar dantonnoriega commented on June 15, 2024

from gtfsr.

mdsumner avatar mdsumner commented on June 15, 2024

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.

tbuckl avatar tbuckl commented on June 15, 2024

@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.

dantonnoriega avatar dantonnoriega commented on June 15, 2024

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.

mdsumner avatar mdsumner commented on June 15, 2024

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.

dantonnoriega avatar dantonnoriega commented on June 15, 2024

Awesome! Thanks!

from gtfsr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.