Skip to content

Instantly share code, notes, and snippets.

View ThomasG77's full-sized avatar

Thomas Gratier ThomasG77

View GitHub Profile
"""
IPython magics for displaying source code files with syntax highlighting.
This uses the Pygments library: http://pygments.org.
To make it works, you need to cute and paste this file into
~/.ipython/profile_default/startup/
If you use custom profile, replace profile_default with your own path
Two magics are available:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ThomasG77
ThomasG77 / postgis_geojson.php
Created September 21, 2012 20:25 — forked from bmcbride/postgis_geojson.php
PHP PostGIS to 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
@ThomasG77
ThomasG77 / countTiles.py
Created January 25, 2012 17:20 — forked from andrewharvey/countTiles.py
Given a WGS84 bounding box and an OSM tile zoom range calculates a total number of tiles.
#!/usr/bin/python
# This script should be considered CC0 licensed
# the deg2num function is from http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#lon.2Flat_to_tile_numbers_2
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)