Skip to content

Instantly share code, notes, and snippets.

if (data[0] >= 1) {
context.fillStyle = '#45bae8';
}
@aaronpdennis
aaronpdennis / write-canvas-to-png.js
Created October 12, 2017 15:04
Writing node-canvas to png
canvas
.pngStream()
.pipe(fs.createWriteStream('map_' + name + '.png'));
@aaronpdennis
aaronpdennis / auto-map-projection.js
Created October 4, 2017 17:07
Automatically define an Albers D3.js projection for a GeoJSON feature.
function framedProjection(feature, mapWidth, mapHeight) {
var projection = d3.geoAlbers();
var centroid = d3.geoCentroid(feature);
projection.rotate([-1 * centroid[0]]).scale(1).translate([0, 0]);
var path = d3.geoPath().projection(projection);
var bounds = path.bounds(feature);
@aaronpdennis
aaronpdennis / .block
Last active April 3, 2017 01:48 — forked from mbostock/.block
Project to Bounding Box
license: gpl-3.0
@aaronpdennis
aaronpdennis / convert.sh
Last active February 24, 2017 03:08
script for converting NAD83 shapefiles in subdirectories to WGS84 GeoJSON
function shp2geojson() {
ogr2ogr -f GeoJSON -s_srs EPSG:4269 -t_srs EPSG:4326 "../../$1.geojson" "$1.shp"
}
for i in ./*/*.zip; do
directory=${i%*.zip}
mkdir "$directory"
cd "$directory"
filename=${directory##*/}
unzip "../${filename}.zip"
@aaronpdennis
aaronpdennis / general_election_2016_votes.geojson
Created January 24, 2017 23:49
Votes by precinct for each Centre County 2016 general election candidate
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Name FIPS Abbr
Alabama 01 AL
Alaska 02 AK
Arizona 04 AZ
Arkansas 05 AR
California 06 CA
Colorado 08 CO
Connecticut 09 CT
Delaware 10 DE
District of Columbia 11 DC

Legislative Districts

Section 16.

The Commonwealth shall be divided into fifty senatorial and two hundred three representative districts, which shall be composed of compact and contiguous territory as nearly equal in population as practicable. Each senatorial district shall elect one Senator, and each representative district one Representative. Unless absolutely necessary no county, city, incorporated town, borough, township or ward shall be divided in forming either a senatorial or representative district.

Extract data from ESRI REST endpoint to GeoJSON (on Windows)

  1. Find ESRI FeatureServer or MapServer
#!/bin/sh
image=0
number_of_images=23
until [ $image -gt $number_of_images ]
do
echo $image
convert $image.png -crop 1008x1003+775+297 $image.cropped.png
a=`expr $a + 1`