Skip to content

Instantly share code, notes, and snippets.


Thomas Gratier ThomasG77

View GitHub Profile
ThomasG77 /
Created Jan 25, 2012 — forked from andrewharvey/
Given a WGS84 bounding box and an OSM tile zoom range calculates a total number of tiles.
# This script should be considered CC0 licensed
# the deg2num function is from
import math
def deg2num(lat_deg, lon_deg, zoom):
lat_rad = math.radians(lat_deg)
n = 2.0 ** zoom
xtile = int((lon_deg + 180.0) / 360.0 * n)
ThomasG77 / postgis_geojson.php
Created Sep 21, 2012 — forked from bmcbride/postgis_geojson.php
View postgis_geojson.php
header('Content-Type: application/json; charset=UTF-8');
* PostGIS to GeoJSON
* Query a PostGIS table or view and return the results in GeoJSON format, suitable for use in OpenLayers, Leaflet, etc.
* @param string $geotable The PostGIS layer name *REQUIRED*
* @param string $geomfield The PostGIS geometry field *REQUIRED*
* @param string $srid The SRID of the returned GeoJSON *OPTIONAL (If omitted, EPSG: 4326 will be used)*
* @param string $fields Fields to be returned *OPTIONAL (If omitted, all fields will be returned)* NOTE- Uppercase field names should be wrapped in double quotes
View shapely_benchmarks.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View iPython_svg_example.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
IPython magics for displaying source code files with syntax highlighting.
This uses the Pygments library:
To make it works, you need to cute and paste this file into
If you use custom profile, replace profile_default with your own path
Two magics are available:
View wrapper-usage.js
], function (superModule, wrapper) {
// Let's wrap it, aspect style
wrapper(superModule, 'superModule');
// Tada, all superModule methods will now log
View index.html
<!doctype html>
<html lang="en">
<link rel="stylesheet" href="" type="text/css">
body {
margin: 0;
padding: 0;
.map {
from __future__ import with_statement
from fabric.api import local, settings, abort, run, cd, env
from fabric.contrib.console import confirm
from fabric.contrib.files import exists, contains
# We reuse config from $HOME/.ssh/config
# Try
# fab --hosts=alwaysdata -f deploy_python
# or to set a specific version
# fab --hosts=alwaysdata -f deploy_python:version=2.7.5

A Leaflet.js map created with Folium and a custom D3 threshold scale, with data bound between the Pandas DataFrame and the TopoJSON. See the Gist for the python code to generate the dataframe. The map was generated with the following Python code:

map_3 = folium.Map(location=[40, -99], zoom_start=4)
map_3.geo_json(geo_path=county_geo, data_out='data3.json', data=df,
               columns=['GEO_ID', 'Median_Household_Income_2011'],
               fill_color='PuRd', line_opacity=0.3,
               legend_name='Median Household Income 2011 ($)',
View OpenLayers.D3.js
OpenLayers.Layer.D3 = OpenLayers.Class(OpenLayers.Layer.Vector, {
var self = this;