Skip to content

Instantly share code, notes, and snippets.

@nrabinowitz
nrabinowitz / quantize.js
Created July 25, 2011 17:19
Javascript module for color quantization, based on Leptonica
/*!
* quantize.js Copyright 2008 Nick Rabinowitz.
* Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
*/
// fill out a couple protovis dependencies
/*!
* Block below copied from Protovis: http://mbostock.github.com/protovis/
* Copyright 2010 Stanford Visualization Group
* Licensed under the BSD License: http://www.opensource.org/licenses/bsd-license.php
id LastSeen_A hex7 Lat Lon PM2_5Value_A AirQualityIndex AirQualityIndex_Description
95 2020-11-07 00:00 871259724ffffff 52.11083221435547 -106.66564178466797 33.879999999999995 96.5 Moderate
130 2020-11-07 00:00 8712c0702ffffff 51.29340744018555 -116.96610260009766 12.18 51 Moderate
131 2020-11-07 00:00 8712c1014ffffff 51.090633392333984 -115.33135223388672 3.86 16 Good
132 2020-11-07 00:00 8712c1016ffffff 51.08929443359375 -115.34068298339844 2.58 11 Good
133 2020-11-07 00:00 8712c1b2bffffff 51.32834243774414 -114.59577178955078 10.09 42 Good
134 2020-11-07 00:00 8712c2185ffffff 51.00360870361328 -118.210693359375 2 8 Good
135 2020-11-07 00:00 8712c8295ffffff 49.199100494384766 -113.3031005859375 7.75 32 Good
136 2020-11-07 00:00 8712ca099ffffff 48.85100173950195 -114.93699645996094 4.42 18 Good
137 2020-11-07 00:00 8712cb598ffffff 48.443748474121094 -114.10562133789062 0.22 1 Good
{
UNITS: h3v4.UNITS,
h3IndexToSplitLong: h3v4.h3IndexToSplitLong,
splitLongToH3Index: h3v4.splitLongToH3Index,
h3IsValid: h3v4.isValidCell,
h3IsPentagon: h3v4.isPentagon,
h3IsResClassIII: h3v4.isResClassIII,
h3GetBaseCell: h3v4.getBaseCellNumber,
h3GetFaces: h3v4.getIcosahedronFaces,
h3GetResolution: h3v4.getResolution,
@nrabinowitz
nrabinowitz / README.md
Last active February 8, 2021 17:38
Images and Data for H3 Tutorials

Images and data for H3 tutorials

@nrabinowitz
nrabinowitz / icosahedron.json
Created July 12, 2019 22:09
Icosahedron geojson (great arcs)
{
"type": "MultiLineString",
"coordinates": [
[
[-176.51528829392126, 56.22382026488319],
[-177.666887558162, 56.2558355327094],
[-178.82009217995488, 56.27714350189036],
[-179.97425867250774, 56.287723610665964],
[-180, 56.28772008819492],
[-179.97425867250772, 56.287723610665964],
["832003fffffffff","832002fffffffff","83201cfffffffff","83201dfffffffff","83200efffffffff","832001fffffffff","832000fffffffff","832006fffffffff","832015fffffffff","832011fffffffff","83201efffffffff","832018fffffffff","832019fffffffff","83200afffffffff","832008fffffffff","83200cfffffffff","83202afffffffff","832005fffffffff","832004fffffffff","832031fffffffff","832033fffffffff","832014fffffffff","832010fffffffff","832013fffffffff","8320adfffffffff","83201afffffffff","83201bfffffffff","8320e6fffffffff","8320e4fffffffff","83200bfffffffff","832009fffffffff","83200dfffffffff","83202bfffffffff","832028fffffffff","83202efffffffff","832023fffffffff","832022fffffffff","832035fffffffff","832030fffffffff","832032fffffffff","832189fffffffff","832016fffffffff","832012fffffffff","8320acfffffffff","8320a8fffffffff","8320a9fffffffff","8320f4fffffffff","8320f5fffffffff","8320e2fffffffff","8320e0fffffffff","8320e5fffffffff","832056fffffffff","832054fffffffff","832072fffffffff","832076fffffffff","832029fffffffff","83202dffffffff
@nrabinowitz
nrabinowitz / fitProjection.js
Created February 7, 2012 00:46
D3 function for fitting a projection to geodata
function fitProjection(projection, data, box, center) {
// get the bounding box for the data - might be more efficient approaches
var left = Infinity,
bottom = -Infinity,
right = -Infinity,
top = Infinity;
// reset projection
projection
.scale(1)
.translate([0, 0]);
<html></html>
@nrabinowitz
nrabinowitz / README.md
Created December 9, 2012 20:51
Raster geocoding with D3.js

This demonstrates raster-based reverse geocoding using canvas and D3.js. Geocoding is based on the color of the pixel at a given projected position. Note that the canvas is only shown here for the sake of explanation and debugging - this would in fact probably work faster if the canvas was not attached to the document at all.

The biggest remaining issue here is precision, which depends on:

  • the size of the canvas, and
  • the projection used.

Determining the optimum size based on the accuracy of your data is left as an exercise for the reader. Edge cases will also fail here, generally returning null - one option might be to stroke neighborhoods in a color, and then return an "uncertain" value for any non-grayscale pixel.

@nrabinowitz
nrabinowitz / index.html
Created September 7, 2012 16:22 — forked from stepheneb/index.html
D3 Example: zoom, pan, and axis rescale
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>One Graph</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.v2.js"></script>
<script type="text/javascript" src="simple-graph.js"></script>
<style type="text/css">
body { font: 13px sans-serif; }
rect { fill: #fff; }