Skip to content

Instantly share code, notes, and snippets.

@anisotropi4
Last active May 7, 2017 19:36
Show Gist options
  • Save anisotropi4/b7fe3aea8809124619b0753558b5c27a to your computer and use it in GitHub Desktop.
Save anisotropi4/b7fe3aea8809124619b0753558b5c27a to your computer and use it in GitHub Desktop.
Travel Time from York by Rail
Released license:gpl-3.0
height:960
border:no
Contains Ordnance Survey data © Crown copyright and database right 2012
Contains National Statistics data © Crown copyright and database right 2012
Travel time and geographic data is under Open Government License v3.0 http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/
<!DOCTYPE html>
<img src="topo.svg" width="640" height="960">
sed 's/"//g' | jq --slurp --raw-input --raw-output -c 'split("\n") | map(split(",")) | .[] | select(.[0] != null) | {CRS: .[3], (.[0]): .[1]}'
Display the source blob
Display the rendered blob
Raw
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="640" height="960" viewBox="0 0 640 960" fill="none" stroke="black">
<g transform="translate(8,32)" fill="none" font-size="10" font-family="sans-serif" text-anchor="middle">
<rect height="10" x="0" width="36" fill="#9e0142"></rect>
<rect height="10" x="36" width="36" fill="#d53e4f"></rect>
<rect height="10" x="72" width="36" fill="#f46d43"></rect>
<rect height="10" x="108" width="36" fill="#fdae61"></rect>
<rect height="10" x="144" width="36" fill="#fee08b"></rect>
<rect height="10" x="180" width="36" fill="#ffffbf"></rect>
<rect height="10" x="216" width="36" fill="#e6f598"></rect>
<rect height="10" x="252" width="36" fill="#abdda4"></rect>
<rect height="10" x="288" width="36" fill="#66c2a5"></rect>
<rect height="10" x="324" width="36" fill="#3288bd"></rect>
<rect height="10" x="360" width="36" fill="#5e4fa2"></rect>
<g class="tick" opacity="1" transform="translate(36,0)">
<line stroke="#000" y2="13" x1="0.5" x2="0.5"></line>
<text fill="#000" y="16" x="0.5" dy="0.71em">0.5</text>
</g>
<g class="tick" opacity="1" transform="translate(72,0)">
<line stroke="#000" y2="13" x1="0.5" x2="0.5"></line>
<text fill="#000" y="16" x="0.5" dy="0.71em">1.0</text>
</g>
<g class="tick" opacity="1"
transform="translate(108,0)">
<line stroke="#000" y2="13" x1="0.5" x2="0.5"></line>
<text fill="#000" y="16" x="0.5" dy="0.71em">1.5</text>
</g>
<g class="tick" opacity="1" transform="translate(144,0)">
<line stroke="#000" y2="13" x1="0.5" x2="0.5"></line>
<text fill="#000" y="16" x="0.5" dy="0.71em">2.0</text>
</g>
<g class="tick" opacity="1" transform="translate(180,0)">
<line stroke="#000" y2="13" x1="0.5" x2="0.5"></line>
<text fill="#000" y="16" x="0.5" dy="0.71em">2.5</text>
</g>
<g class="tick" opacity="1"
transform="translate(216,0)">
<line stroke="#000" y2="13" x1="0.5" x2="0.5"></line>
<text fill="#000" y="16" x="0.5" dy="0.71em">3.0</text>
</g>
<g class="tick" opacity="1" transform="translate(252,0)">
<line stroke="#000" y2="13" x1="0.5" x2="0.5"></line>
<text fill="#000" y="16" x="0.5" dy="0.71em">3.5</text>
</g>
<g class="tick" opacity="1" transform="translate(288,0)">
<line stroke="#000" y2="13" x1="0.5" x2="0.5"></line>
<text fill="#000" y="16" x="0.5" dy="0.71em">4.0</text>
</g>
<g class="tick" opacity="1" transform="translate(324,0)">
<line stroke="#000" y2="13" x1="0.5" x2="0.5"></line>
<text fill="#000" y="16" x="0.5" dy="0.71em">4.5</text>
</g>
<g class="tick" opacity="1" transform="translate(360,0)">
<line stroke="#000" y2="13" x1="0.5" x2="0.5"></line>
<text fill="#000" y="16" x="0.5" dy="0.71em">5+</text>
</g>
<text fill="#000" font-size="20px" font-weight="bold"
text-anchor="start" y="-6">Travel Time (hours)</text>
</g>
</svg>
Released license:gpl-3.0
height:780
border:no
Postal Boundaries © GeoLytix copyright and database right 2012
Contains Ordnance Survey data © Crown copyright and database right 2012
Contains Royal Mail data © Royal Mail copyright and database right 2012
Contains National Statistics data © Crown copyright and database right 2012
Census data Open Government License v3.0 http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/
#!/bin/bash
#Station CRS code
CRS="YRK"
HEIGHT=960
WIDTH=640
PROJECTION='d3.geoConicEqualArea().parallels([49, 61]).fitSize(['${WIDTH}','${HEIGHT}'], d)'
SCALE="d3.bisect([30, 60, 90, 120, 150, 180, 210, 240, 270, 300],d.properties.time)"
FILL="d3.schemeSpectral[11][d.properties.scale]"
if [ ! -f Rail-stations-travel-times.zip ]
then
wget http://data.dft.gov.uk.s3.amazonaws.com/connectivity-data/Rail-stations-travel-times.zip
fi
if [ ! -f Stations_HW_AM.csv ]
then
unzip Rail-stations-travel-times.zip Stations_HW_AM.csv
fi
if [ ! -f Stations_HW_AM.ndjson ]
then
tail -n +2 Stations_HW_AM.csv | \
split -l 262144 --filter=./jq-script.sh | \
sort | \
split -l 8192 --filter="jq -c -s 'group_by(.CRS) | .[] | add'" | \
jq -c -s 'group_by(.CRS) | .[] | add' > Stations_HW_AM.ndjson
fi
if [ ! -f 90e15daaaeef4baa877f4bffe01ebef0_2.zip ]
then
wget http://geoportal.statistics.gov.uk/datasets/90e15daaaeef4baa877f4bffe01ebef0_2.zip
fi
if [ ! -s LLSOA-2001-England-and-Wales.ndjson ]
then
unzip 90e15daaaeef4baa877f4bffe01ebef0_2.zip
for i in *2001*.shp
do
ogr2ogr -t_srs EPSG:4326 -f GeoJSON /vsistdout/ ${i} | \
jq -c '.features[] | ({ id: .properties.lsoa01cd} + . )' | \
geo2topo -n tracts=- | toposimplify -s 2.5E-10 -F | \
topo2geo -n tracts=-
done > LLSOA-2001-England-and-Wales.ndjson
fi
if [ ! -s topo.json ]
then
geo2topo -n tracts=<(ndjson-join 'd.id' \
<(jq -c 'select(.CRS=="'${CRS}'") | del(.CRS) | to_entries | map({id: .key, time: .value})[]' Stations_HW_AM.ndjson) \
<(jq -s -c '{"type": "FeatureCollection", "features": .}' LLSOA-2001-England-and-Wales.ndjson | \
geoproject "${PROJECTION}" | \
jq -c '.features[]') | \
ndjson-map -r d3 '{type: d[1].type, properties: {title: d[0].id, time: d[0].time}, geometry: d[1].geometry}') | \
toposimplify -p 1 -f | \
topoquantize 1E6 > topo.json
fi
< topo.json topo2geo -n tracts=- | \
ndjson-map -r d3=d3 '(d.properties.scale='"${SCALE}"',d)' | \
ndjson-map -r d3=d3-scale-chromatic '(d.properties.fill='"${FILL}"', d)' | \
geo2svg --stroke=none -n -p 1 -w ${WIDTH} -h ${HEIGHT} | \
sed '$d' > topo.svg
# Insert the legend.
tail -n +4 \
< legend.svg \
>> topo.svg
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment