You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Instantly share code, notes, and snippets.
Rafael H M Pereira
rafapereirabr
Researcher on Cities, Transport Policy, R, Spatial Analysis, Equity, Demography
Here are some things you can do with Gists in GistBox.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How to efficiently calculate distance between pair of coordinates using data.table :=
This is the fastest way I've found so far to calculate the distances between pairs of lat long coordinates. The method takes advantage of distGeo{geosphere} and the crazy fast := operator of data.table.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Simple code to create a world map of cities with population > than 40K in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Interactive map or large spatial data sets (demo geobr)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Creating an animated gif of public transport networks using GTFS data
Creating an animated gif of public transport networks using GTFS data and the gtfs2gps package
In this gist we show with a reproducible example how to create an animation of public transport networks using GTFS data in R. We use a few packages to do this. One of the core packages here is the new gtfs2gps. The gtfs2gps package converts public transport data in GTFS format to GPS-like records in a data.frame/data.table, which we will be using to create a .gif with the gganimate package.
Step 1 - Convert GTFS to GPS-like records
The first step is to process a GTFS.zip file. The function gtfs2gps{gtfs2gps} interpolates the space-time position of each vehicle in each trip considering the network distance and average speed between stops. The output is a data.table where each row represents the timestamp of each vehicle at a given spatial resolution. In this example, we use a sample of the public transport network of Sao Paulo (Brazil) mapped e