Skip to content

Instantly share code, notes, and snippets.

View andrewxhill's full-sized avatar

Andrew W. Hill andrewxhill

View GitHub Profile
@andrewxhill
andrewxhill / cartodb_test.html
Created August 21, 2012 15:31 — forked from anonymous/cartodb_test.html
cartodb_test.html
<html><body><h1>Summary</h1> <h3>40 Tests Run with 1 Failures - 2012-08-21 11:30</h3> <table border="1"><tr><th>#</th><th>production</th><th>staging</th><th>sql</th><th>carto</th></tr>
<tr>
<td class="test_count">10</td>
<td class="production_img"><a href='http://examples.cartodb.com/tiles/carto_tests/0/0/0.png?style=%23carto_tests+%7Bmarker-fill%3A%23ff7%3B+marker-max-error%3A0.762117952967%3B+marker-line-opacity%3A0.954313683078%3B+marker-allow-overlap%3Afalse%3B+polygon-fill%3Argba%28255%2C+255%2C+0%2C+1%29%3B+marker-spacing%3A16.0%3B+marker-width%3A4.0%3B+marker-height%3A3.0%3B+marker-opacity%3A0.667163700797%3B+line-color%3Agreen%3B+line-gamma%3A0.524514770107%3B+line-cap%3Around%3B+polygon-opacity%3A0.814145908039%3B+marker-type%3Aarrow%3B+polygon-gamma%3A0.296743932444%3B+line-dasharray%3A2%2C10%3B+line-join%3Amiter%3B+marker-placement%3Aline%3B+line-width%3A12.0%3B+marker-line-color%3Argb%28155%2C+133%2C+0%29%3B+line-opacity%3A0.749564105384%3B+marker-line-width%3A4.0%3
@andrewxhill
andrewxhill / clr2carto.py
Created August 24, 2012 15:43
Python script to covert GeoTiff .CLR file to a Carto style for CartoDB
import sys
args = []
for arg in sys.argv:
args.append(arg)
try:
clr_file = args[1] #'glc2000_v1_1.clr'
except:
print """ You must supply an input .CLR filename.
@andrewxhill
andrewxhill / rasters.sql
Created September 11, 2012 19:36
Rasters to polygons for CartoDB
--Upload your new raster data
--In my case the data goes into a table, night_light
--In some cases, I find it useful to downsample the total number of variables in a band, or in some cases merge data from multiple bands into one.
--Here is an example how one such process would work
UPDATE night_light SET rast = ST_MapAlgebraExpr(rast,'8BUI','CASE WHEN [rast] = 0 THEN 10 WHEN [rast] = 255 THEN 11 ELSE floor([rast]/32)::int END');
--Create a new table, light_polygons
--Add a numeric column called, rast_value
@andrewxhill
andrewxhill / backbone-example.js
Created September 12, 2012 19:28
CartoDB Backbone for data-driven webpages
// Set the CartoDB user account
var CartoDB = Backbone.CartoDB({
user: viz2
});
// Create a model, here directly from SQL
// You can also do it with simply a table name and list of columns
var parksModel = CartoDB.CartoDBCollection.extend({
sql: "SELECT name FROM nyc_parks ORDER BY ST_Area(the_geom) DESC LIMIT 10"
});
@andrewxhill
andrewxhill / sernec.js
Created September 24, 2012 19:09
sernec project data
var projectData = {
category: 'herbarium',
name: 'Southeast Regional Network of Expertise and Collections ',
nameshort: 'SERNEC',
description: 'SERNEC is an organization devoted to making the resources of these nearly 222 regional Herbaria of the Southeast available online, in concurrence with developing global standards, so that all available data can then be studied regionally or globally as one virtual, researchable collection. SERNEC will improve access to specimen data of a richly biodiverse ecological environment, and provide a platform for herbarium curators and plant scientists to exchange ideas, share expertise, and benefit from the value of information shared across institutions. ',
temporalrange: '1800 - present',
geography: 'Southeast, United States',
taxonomycommon: 'plants',
taxonomy: 'Kingdom Plantae',
profileimage: '',
@andrewxhill
andrewxhill / note_ify.py
Created September 26, 2012 16:26
Converts a directory of images into two directories, one large, one small of PNGs
import sys
from os import listdir, path, makedirs
from PIL import Image
from datetime import datetime
try:
import simplejson as json
except:
import json
SUPPORTED_FORMATS = ['.tif','.tiff','.png','.jpg']
@andrewxhill
andrewxhill / gist:3791207
Created September 26, 2012 23:09
Color ramp for a topology
#troparevo_nikulino_1 [layer='points']{
marker-fill:#FF3366;
marker-width:8;
marker-line-color:#000000;
marker-line-width:1;
marker-opacity:1;
marker-line-opacity:1;
marker-placement:point;
marker-type:ellipse;
marker-allow-overlap:true;
@andrewxhill
andrewxhill / gist:3791208
Created September 26, 2012 23:09
SQL for building a dynamic topo
WITH
setup AS (
SELECT
ST_Transform(ST_Buffer(the_geom::geography,n*100)::geometry,3857) the_geom_webmercator,
(cars*(10.0 - n)/10.0) as cars
FROM troparevo_nikulino_1, generate_series(1,9) n
),
maxcars AS (
SELECT max(cars)::float as mostcars FROM setup
)
@andrewxhill
andrewxhill / example.sql
Created October 9, 2012 15:17
Create an equal area grid over a buffer of points
-- 1) Create the desired buffer of 50km around your points, buffs
-- 2) Create a reprojected envelope around your buffs, area
-- 3) Create a rectangular grid inside the envelope, grid
-- 4) Select the centroid of each gridcell and reproject it as a a WGS84 point
-- The equal area Lambert projection for North America is documented here,
-- http://spatialreference.org/ref/sr-org/7314/
-- and is stored in your spatial ref system as, 97314
WITH buffs AS ( --creates a resource called 'area' that will act like any existing table