Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@irees
irees / README.md
Last active December 10, 2020 11:50

Transitland Frequency Visualization

Accompanies blog post: Transit dimensions: Transitland Schedule API

The frequency.py script:

  • Fetches all trips on a given date, between a start time and end time, inside of a bounding box
  • Calculates the number of connections between every stop
  • Uses a colormap and line width to show more frequent service
  • Outputs a GeoJSON map as output.geojson
id | route_short_name | route_long_name | headway_mins
---------+------------------+----------------------------------+--------------
1128053 | | Red Line | 5
1127999 | 79 | 79th | 5
1127997 | 77 | Belmont | 6
1128049 | 172 | U. of Chicago/Kenwood | 6
1127945 | 20 | Madison | 6
1128034 | 134 | Stockton/LaSalle Express | 6
1128037 | 143 | Stockton/Michigan Express | 7
1128056 | | Blue Line | 7
#!/usr/bin/env python
import sys
import os
import json
import random
MIN_DISTANCE = 0.0
MAX_DISTANCE = 1000000.0
MAX_SAMPLE = 1000000
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"agency.txt": {
"agency_name": {
"total": 1,
"unique": 1,
"min": "Caltrain",
"max": "Caltrain"
},
"agency_url": {
"total": 1,
@irees
irees / distance_point_segment.py
Created August 11, 2014 00:36
Find the minimum distance between a point and a line segment
# Find the minimum distance between a point and a line segment.
# Ported from C/JavaScript implementation by Grumdrig
# http://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
import math
class Point(object):
def __init__(self, x, y):
self.x = float(x)
self.y = float(y)
@irees
irees / colors.js
Last active March 17, 2016 18:14
transitland crayons
// Inspired by https://github.com/cooperhewitt/py-cooperhewitt-swatchbook
RGBColor = function(r, g, b, name) {
this.r = r;
this.g = g;
this.b = b;
this.name = name;
};
RGBColor.from_hex = function (hex, name) {
hex = hex.replace('#','');
return new RGBColor(
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.