Skip to content

Instantly share code, notes, and snippets.

Neil Freeman fitnr

Block or report user

Report or block fitnr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View decode_countyparcel.py
import sys
import json
from io import BytesIO
import geomet.wkb
def bytes2dict(x):
'''Decode a dictionary encoded in bytes using the dicAsBytes method.'''
b = BytesIO(x)
count = read_int(b)
result = {}
View downsample-polygonize.sh
#!/bin/bash
set -e
DIR=$1
SHP=$2
TMP=$(mktemp -d)
export DIR
downsample() {
View selected-services.csv
station_id terminal_id route_id agency_name route_long_name
ACB EUS 176599 Serco Caledonian Sleeper CS train service from DEE to EUS
ACB EUS 192409 Virgin Trains VT train service from EUS to WBQ
ACB EUS 214187 Serco Caledonian Sleeper CS train service from ABD to EUS
ACB EUS 214314 Serco Caledonian Sleeper CS train service from EUS to ABD
ACB EUS 24722 Virgin Trains VT train service from LIV to EUS
ACB EUS 24780 Virgin Trains VT train service from BPN to EUS
ACB EUS 24808 Virgin Trains VT train service from EUS to LAN
ACB EUS 24825 Virgin Trains VT train service from EUS to LIV
ACB EUS 24895 Virgin Trains VT train service from GLC to EUS
@fitnr
fitnr / query.sql
Last active Jan 8, 2019
Find the number of rail stations in GB that have direct service to a London terminus
View query.sql
-- Load data from a UK-wide GTFS into postgres using https://github.com/fitnr/gtfs-sql-importer
-- Used this GTFS file:
-- https://transitfeeds.com/p/association-of-train-operating-companies/284
with terminals as ( -- ID codes for London terminal stations
values ('BFR'), ('CST'), ('CHX'), ('CTK'), ('EUS'), ('FST'), ('KGX'), ('LST'), ('LBG'), ('MYB'), ('MOG'), ('OLD'), ('PAD'), ('STP'), ('SPX'), ('VXH'), ('VIC'), ('WAT'), ('WAE')
)
, london_trips as ( -- select trips that include the above codes
select distinct feed_index, route_id, trip_id
from gtfs.stops
View county-nest.csv
statefp countyfp name population
48 179 Gray 23028
39 067 Harrison 15521
1 069 Houston 103891
48 013 Atascosa 47710
17 031 Cook 5227575
1 001 Autauga 55049
38 025 Dunn 4284
17 091 Kankakee 111493
49 001 Beaver 6437
@fitnr
fitnr / hexbin.sql
Last active Nov 28, 2018
create hex bins in postgis
View hexbin.sql
-- adapted from https://medium.com/@goldrydigital/hex-grid-algorithm-for-postgis-4ac45f61d093
-- usage: select * FROM hexbin(numeric, geometry)
-- cover a table with something like:
-- select row_number() over () id, geom
-- from hexbin(5280, st_transform(st_setsrid(st_expand(ST_EstimatedExtent('table', 'geom'), 0.1), 4269), 2255));
CREATE OR REPLACE FUNCTION hexbin (height numeric, minx numeric, miny numeric, maxx numeric, maxy numeric, srid integer)
RETURNS TABLE (geom geometry(polygon))
AS $$
@fitnr
fitnr / s2cover.py
Created Sep 26, 2018
Returns an s2 covering as ndgeojson
View s2cover.py
#!/usr/bin/env python3
import json
import argparse
import s2sphere as s2
def point2coord(point):
return s2.LatLng.longitude(point).degrees, s2.LatLng.latitude(point).degrees
@fitnr
fitnr / 2014-primary-gov.csv
Last active Sep 14, 2018
NYS democratic primary results for nyc
View 2014-primary-gov.csv
electdist county cuomo teachout credico
65001 New York 2 3 0
65002 New York 16 23 0
65003 New York 5 6 0
65004 New York 2 4 0
65005 New York 30 8 3
65006 New York 43 41 5
65007 New York 44 32 2
65008 New York 53 47 5
65009 New York 6 6 0
View mtfcc.csv
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 7.
MTFCC,Feature Class,Superclass,Point,Linear,Areal,Description
C3022,Mountain Peak or Summit,Miscellaneous Topographic Features,Y,N,N,A prominent elevation rising above the surrounding level of the Earth's surface.
C3023,Island,Miscellaneous Topographic Features,Y,Y,Y,"An area of dry or relatively dry land surrounded by water or low wetland. [including archipelago, atoll, cay, hammock, hummock, isla, isle, key, moku and rock]"
C3024,Levee,Miscellaneous Topographic Features,N,Y,Y,An embankment flanking a stream or other flowing water feature to prevent overflow.
C3026,"Quarry (not water-filled), Open Pit Mine or Mine",Miscellaneous Topographic Features,Y,N,Y,An area from which commercial minerals are or were removed from the Earth; not including an oilfield or gas field.
C3027,Dam,Miscellaneous Topographic Features,Y,Y,Y,A barrier built across the course of a stream to impound water and/or control water flow.
C3061,Cul-de-sac,Miscellaneous Topographic Features,Y,N,N,"An expanded paved area at the end of a stree
View Makefile
SHELL = bash
raster = elevation/ned/ned.vrt
vector = water/WBD/WBD.gdb
layer = 10
# ids = $(shell ogrinfo build basins -q -fields=YES -geom=NO | grep HUC$(layer) | cut -d = -f 2 | xargs)
ids = 0202000503 0202000504 0202000505 0202000506 0202000507 0202000601 0202000602 0202000603 0202000604 0202000605 0202000607 0202000608 0202000609 0202000611 0202000703 0202000704 0202000705 0202000706 0202000801 0202000802 0202000803 0202000804 0202000805 0203010101 0203010202 0203020101 0203020102 0203020103 0203020104 0203010405 0203020202 0203020203 0203020204 0203020205 0203020206 0203020207 0203020208 0203020209 0204010101 0204010102 0204010105 0204010201 0204010202 0204010203 0204010204 0204010205 0204010401 0204010402 0205010101 0205010102 0205010103 0205010104 0205010105 0205010106 0205010107 0205010108 0205010109 0205010110 0205010111 0205010112 0205010201 0205010202 0205010203 0205010204 0205010205 0205010206 0205010207 0205010208 0205010301 0205010303 0205010304 0205010305 0205010306 0205010401 0205010402 0205
You can’t perform that action at this time.