Skip to content

Instantly share code, notes, and snippets.

@migurski
migurski / Grid.min.js
Created February 9, 2013 02:38
I Miss GetLatLon.com
var require=function(b,j){var d=require.resolve(b,j||"/"),e=require.modules[d];if(!e)throw Error("Failed to resolve module "+b+", tried "+d);return(d=require.cache[d])?d.exports:e()};require.paths=[];require.modules={};require.cache={};require.extensions=[".js",".coffee",".json"];require._core={assert:!0,events:!0,fs:!0,path:!0,vm:!0};
require.resolve=function(){return function(b,j){function d(a){a=g.normalize(a);if(require.modules[a])return a;for(var c=0;c<require.extensions.length;c++){var b=require.extensions[c];if(require.modules[a+b])return a+b}}function e(a){a=a.replace(/\/+$/,"");var c=g.normalize(a+"/package.json");if(require.modules[c]){var c=require.modules[c](),b=c.browserify;if("object"===typeof b&&b.main){if(c=d(g.resolve(a,b.main)))return c}else if("string"===typeof b){if(c=d(g.resolve(a,b)))return c}else if(c.main&&
(c=d(g.resolve(a,c.main))))return c}return d(a+"/index")}j||(j="/");if(require._core[b])return b;var g=require.modules.path(),c=(j=g.resolve("/",j))||"/";if(b.match(/^(?:\.\.?\/|\/)
var require = function (file, cwd) {
var resolved = require.resolve(file, cwd || '/');
var mod = require.modules[resolved];
if (!mod) throw new Error(
'Failed to resolve module ' + file + ', tried ' + resolved
);
var cached = require.cache[resolved];
var res = cached? cached.exports : mod();
return res;
};
var require = function (file, cwd) {
var resolved = require.resolve(file, cwd || '/');
var mod = require.modules[resolved];
if (!mod) throw new Error(
'Failed to resolve module ' + file + ', tried ' + resolved
);
var cached = require.cache[resolved];
var res = cached? cached.exports : mod();
return res;
};
var require = function (file, cwd) {
var resolved = require.resolve(file, cwd || '/');
var mod = require.modules[resolved];
if (!mod) throw new Error(
'Failed to resolve module ' + file + ', tried ' + resolved
);
var cached = require.cache[resolved];
var res = cached? cached.exports : mod();
return res;
};
@migurski
migurski / dissolver.py
Created January 31, 2013 16:32
Dissolve small & residential roads into urban areas.
from sys import stderr
from osgeo import ogr
from time import time
from math import sqrt
def not_big(feature):
highway = feature.GetFieldAsString(feature.GetFieldIndex('type'))
return highway in ('residential', 'unclassified', 'road', 'minor')
@migurski
migurski / index.html
Created January 23, 2013 01:46
Small example showing D3 data with and without a key function. D3 takes a second argument to the data() method, a function that returns a join key for each data element passed in. Without this, it assumes that the array index and not the array element are important. I had been passing in three-element arrays, and D3 assumed that I was updating a…
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Joinery</title>
<script src="http://d3js.org/d3.v3.min.js" type="application/javascript"></script>
<style title="text/css">
<!--
div { margin: 5px; padding: 5px 10px; color: white; float: left }
from itertools import product
radius = 20037508.343
mins = [2 * radius * n/8. - radius for n in range(0, 8)]
maxs = [2 * radius * n/8. - radius for n in range(1, 9)]
edges = zip(mins, maxs)
for (index, ((xmin, xmax), (ymin, ymax))) in enumerate(product(edges, edges)):
#!/usr/bin/env python
''' Convert binary data to UTF8.
If you want binary data in Javascript over XMLHttpRequest but don't
have ArrayBuffer available, one option is to read strings of text and
use xhr.responseText.charCodeAt() to read them. Because this expects to
work with text, it will return the unicode of the character at that
position. This script converts raw binary bytes to unicode text that
evaluates to the same 8-bit unsigned int at each position. The overall
length will increase slightly.
@migurski
migurski / rasterize.py
Created December 15, 2012 05:51
Script to generate CONUS raster of various OSM metrics connected to TIGER extent. Counties2012 table is in spherical Albers projection: `+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +nadgrids=@null +units=m +no_defs`
from itertools import product
from multiprocessing import Pool
from numpy import zeros, ubyte
from psycopg2 import connect
from osgeo import gdal, osr
from PIL import Image
def measure_quad(x, y, cellsize):
'''
@migurski
migurski / RemoteGeoJSON.py
Created December 14, 2012 06:03
Sample datasource for remote tiled data in Mapnik.
''' Sample datasource for remote tiled data in Mapnik.
See also https://github.com/mapnik/mapnik/wiki/Python-Plugin
Use in Mapnik:
<Datasource>
<Parameter name="type">python</Parameter>
<Parameter name="factory">RemoteGeoJSON:Datasource</Parameter>