Skip to content

Instantly share code, notes, and snippets.

@walkermatt
walkermatt / gist:1383021
Created November 21, 2011 15:50 — forked from eriwen/gist:187610
Pythonic site monitor
#!/usr/bin/env python
# sample usage: checksites.py eriwen.com nixtutor.com yoursite.org
import pickle, os, sys, logging
from httplib import HTTPConnection, socket
from smtplib import SMTP
def email_alert(message, status):
fromaddr = 'you@gmail.com'
@walkermatt
walkermatt / disaggregate_postgis_complex_contents.sql
Created November 25, 2011 09:19
Disaggregate MultiLineStrings using ST_Dump PostGIS
SELECT *, ST_GeometryType(geom) as geom_type, ST_AsEWKT(geom) as geom_wkt from complex;
@walkermatt
walkermatt / loader.config
Created June 4, 2012 13:30
Loader config for AddressBase Plus on Windows into PostgreSQL
src_dir=C:\GML_Loader\data\import
out_dir=C:\loader_data\export
tmp_dir=C:\loader_data\temp
ogr_cmd=ogr2ogr -append -skipfailures -f PostgreSQL PG:'dbname=test active_schema=public host=localhost port=5432 user=postgres password=******' $file_path
prep_cmd=python prepgml4ogr.py $file_path prep_osgml.prep_addressbase
@walkermatt
walkermatt / debounce.py
Created June 4, 2012 21:44
A debounce function decorator in Python similar to the one in underscore.js, tested with 2.7
from threading import Timer
def debounce(wait):
""" Decorator that will postpone a functions
execution until after wait seconds
have elapsed since the last time it was invoked. """
def decorator(fn):
def debounced(*args, **kwargs):
def call_it():
@walkermatt
walkermatt / osgb_map.js
Created July 2, 2012 18:25
Leaflet Map using Proj4Leaflet to display a projected TMS base map from MapProxy
// Bounding box of our TMS that define our area of interest
var bbox = [-600000, -300000, 1300000, 1600000];
// Resolutions of our TMS that the tiles will be displayed at calculated so
// that at resolution 0 the bounds fit one 256x256 tile: (maxx - minx)/256
var res = [7421.875, 3710.9375, 1855.46875, 927.734375];
// Define the Proj4Leaflet coordinate reference system base on British National Grid
var crs = L.CRS.proj4js(
'EPSG:27700',
@walkermatt
walkermatt / script.js
Created July 5, 2012 19:00 — forked from nextstopsun/script.js
Proj4Leaflet 102012 projection test
var res = [
140000.0000000000,
70000.0000000000,
35000.0000000000,
17500.0000000000,
8750.0000000000,
4375.0000000000,
2187.5000000000,
1093.7500000000,
546.8750000000,
@walkermatt
walkermatt / prep_policekml.py
Created July 29, 2012 20:44
Simple Loader prep class to import KML police.uk neighbourhood boundaries
"""
A class used to manipulate Police KML data, used with prepgml4ogr.py.
"""
import os
from lxml import etree
class prep_kml():
def __init__(self, inputfile):
@walkermatt
walkermatt / wfs2postgis.sh
Created September 26, 2012 20:09
WFS to PostGIS
# Example of downloading all data from a GeoServer WFS server
# and loading it into a PostGIS database. Use with caution
# as you could put a lot of load on someone's server if they
# host a lot of data which might make them sad.
# In response to: http://underdark.wordpress.com/2012/09/26/wfs-to-postgis-in-3-steps/
BASEURL="http://data.wien.gv.at/daten/geoserver/ows?service=WFS&version=1.1.0"
for LAYERNAME in `wget -qO- $BASEURL"&request=GetCapabilities" | xpath -q -e "//FeatureType/Name/text()"` ; do
PARTS=(${LAYERNAME//:/ })
@walkermatt
walkermatt / run_loader.bat
Last active December 10, 2015 21:08
DOS batch file to run Loader (https://github.com/AstunTechnology/Loader) on Windows using GDAL and python provided by OSGeo4W (installation of which is documented on the wiki)
rem DOS batch file to run Loader on Windows using GDAL and python
rem provided by OSGeo4W. As this script requires the OSGeo4W environment
rem to run it must be passed as an argument to OSGeo4W.bat like so:
rem call C:\OSGeo4W\OSGeo4W.bat C:\Temp\Loader\run_loader.bat
rem Change to the folder that this script is in (assumes this script is
rem in the same folder as the Loader readme)
cd /D %~dp0
rem change to the python directory
@walkermatt
walkermatt / Gazetteer.vrt
Created February 6, 2013 08:11
Example AstunTechnology / OpenDataLoader (https://github.com/AstunTechnology/OpenDataLoader) config for OS 50k Gazetteer. OSOpenLoader.config and Table.csv should live in the root of the OpenDataLoader directory. Gazetteer.vrt should go in the source Gazetteer directory.
<OGRVRTDataSource>
<OGRVRTLayer name="50kgaz2012_new">
<SrcDataSource>/home/matt/Downloads/gaz50k_gb/Gazetteer/50kgaz2012_new.csv</SrcDataSource>
<GeometryType>wkbPoint</GeometryType>
<LayerSRS>EPSG:27700</LayerSRS>
<GeometryField encoding="PointFromColumns" x="EAST" y="NORTH"/>
</OGRVRTLayer>
</OGRVRTDataSource>