Skip to content

Instantly share code, notes, and snippets.

View glenrobertson's full-sized avatar
💭
Taking the specifications from the customer to the Software Engineers

Glen Robertson glenrobertson

💭
Taking the specifications from the customer to the Software Engineers
View GitHub Profile
#!/bin/bash
# run with path to postgis share dir
# e.g. ./postgis_template.sh /usr/local/Cellar/postgis/2.0.1/share/postgis
POSTGIS_TEMPLATE_PATH=$1;
# Creating the template spatial database
createdb -E UTF8 -T template0 template_postgis
# Loading the PostGIS SQL routines.
@glenrobertson
glenrobertson / osmosis_polygon_to_django_multipolygon.py
Created August 6, 2012 00:02
osmosis_polygon_to_django_multipolygon
from django.contrib.gis.geos import MultiPolygon, Polygon, LinearRing
def to_mpoly(osmosis_file):
""" Parse an Osmosis polygon filter file
Accept a sequence of lines from a polygon file,
return a django.contrib.gis.MultiPolygon object.
http://wiki.openstreetmap.org/wiki/Osmosis/Polygon_Filter_File_Format
@glenrobertson
glenrobertson / L.Icon.Hover.js
Created August 19, 2012 23:06
leaflet icon hover class
L.Icon.Hover = L.Icon.extend({
options: {
iconSize: new L.Point(25, 41),
iconAnchor: new L.Point(13, 41),
popupAnchor: new L.Point(1, -34),
shadowSize: new L.Point(41, 41)
},
@glenrobertson
glenrobertson / fadeColour.js
Created August 25, 2012 07:37
animate colour change with a callback in javascript
// create div and call animate on it, from start to end colour for the duration
// for each step of the colour change, invoke the callback
function fadeColour(start_colour, end_colour, duration, callback) {
var ele = $('<div></div>');
$(ele).css('color', start_colour);
$(ele).animate({
color: end_colour
}, {
duration: duration,
@glenrobertson
glenrobertson / TileLayer.GeoJSON.js
Created September 15, 2012 00:02
GeoJSON Leaflet Tile Layer
/*
GeoJSON layer with mouse hover events to properties for each feature
Requires JQuery to handle the AJAX requests
Currently only supports FeatureCollections
Features must have ID's, so they can be deduplicated across tiles (not rendered twice).
*/
/*
Control that shows HTML content for a point on hover
*/
@glenrobertson
glenrobertson / image_gradient_view.py
Created September 15, 2012 00:36
Image gradient Django view
"""
Django view to generate a gradient image.
Inputs:
* colour_model: "rgb" or "hsl"
* direction: "horizontal" or "vertical"
* start_rgb: hex colour string, e.g: #BADA55
* end_rgb: hex colour string, e.g: #BEEFED
* width: image pixel height
* height: image pixel width
@glenrobertson
glenrobertson / geo_hstore_manager.py
Created October 4, 2012 21:35
Combine Django GeoManager with HStoreManager
# pip install django-orm-extensions
from django.contrib.gis.db.models.query import GeoQuerySet
from django.contrib.gis.db.models import GeoManager
from django_orm.postgresql.hstore.queryset import HStoreQuerySet
from django_orm.postgresql.hstore.manager import HStoreManager
class GeoHStoreQuerySet(GeoQuerySet, HStoreQuerySet):
pass
@glenrobertson
glenrobertson / index.html
Created October 10, 2012 21:41
Leaflet Map with a marker
<!DOCTYPE html>
<html>
<head>
<title>Leaflet Markers</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.4.3/leaflet.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.4.3/leaflet.ie.css" />
<![endif]-->
<script src="http://cdn.leafletjs.com/leaflet-0.4.3/leaflet.js"></script>
<style type="text/css">
@glenrobertson
glenrobertson / nested_map.py
Created November 12, 2012 09:56
Apply function to items in nested list/tuple
def nested_map(self, collection, func):
if type(collection) == list:
return [nested_map(i, func) for i in collection]
elif type(collection) == tuple:
return tuple([nested_map(i, func) for i in collection])
else:
return func(collection)
@glenrobertson
glenrobertson / leaflet-geojson-gpolydecode.js
Created November 13, 2012 03:11
Handling for Google encoded polygons inside GeoJSON in Leaflet
// extend GeoJSON to handle google-encoded linestrings
// assumes that any array of coordinates that make up a linestring are replaced with the google encoded line string
L.extend(L.GeoJSON, {
// This function is from Google's polyline utility.
// Borrowed from: http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/decode.js
// Changed to return lng/lats instead of lat/lngs
decodeLine: function (encoded) {
var len = encoded.length;
var index = 0;
var array = [];