Skip to content

Instantly share code, notes, and snippets.

""" Minimal MapProxy Middleware demonstrating wrapping MapProxy and working
with the query string
To run:
1. Install MapProxy in a virtual enviroment together with Gunicorn
2. Create a basic MapProxy config and copy this file into the same directory as mapproxy.yaml
2. Activate virtual environment
3. Change to the directory containing this file
4. Run:
gunicorn -k eventlet --workers=1 --log-file=- mapproxy_filter:application
@walkermatt
walkermatt / pyqgis_filter_vector_features.py
Created March 17, 2017 16:31
For use in the QGIS Python console
# Just the selected features
layer = iface.activeLayer()
for feature in layer.selectedFeatures():
print feature['name']
# Filter by current extent of the map
extent = iface.mapCanvas().extent()
request = QgsFeatureRequest()
request.setFilterRect(extent)
layer = iface.activeLayer()
import itertools
import qgis
from qgis.gui import QgsMessageBar
from qgis.core import QgsMapLayer
def layer_info(layer):
print "Layer name: %s" % layer.name()
print "CRS: %s" % layer.crs().authid()
print "Extent: %s" % layer.extent().asWktCoordinates()

Python psycopg2 & PostGIS

Load some data into the database

From the OSGeo4W Shell

ogr2ogr -f PostgreSQL PG:"dbname=postgis host=localhost user=postgres password=postgres" -a_srs "EPSG:27700" county_region.shp -nlt MULTIPOLYGON

Use psycopg2 in the Python Interpreter

@walkermatt
walkermatt / Rock, paper, scissors.py
Created December 17, 2016 09:21
Rock, paper, scissors created by walkermatt - https://repl.it/EsHd/15
# Rock, paper, scissors
def beats(thing1, thing2):
""" Determine who wins rock, paper, scissors
by passing each players choice """
if thing1 == thing2:
# Draw, both players chose the same thing
return None
# Determine which thing beats thing2
victors = {
@walkermatt
walkermatt / mapproxy_decorate.py
Last active March 22, 2024 16:48
Minimal MapProxy Middleware demonstrating the decorate_img API
""" Minimal MapProxy Middleware demonstrating the decorate_img API
To run:
1. Install MapProxy in a virtual enviroment together with Gunicorn
2. Create a basic MapProxy config and copy this file into the same directory as mapproxy.yaml
2. Activate virtual environment
3. Change to the directory containing this file
4. Run:
gunicorn -k eventlet --workers=1 --log-file=- mapproxy_decorate:application
@walkermatt
walkermatt / map.html
Created September 16, 2016 17:47
OpenLayers 3 LayerSwitcher and Popup together
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>OpenLayers 3 - LayerSwitcher &amp; Popup</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.17.1/ol.css" />
<link rel="stylesheet" href="https://rawgit.com/walkermatt/ol3-layerswitcher/master/src/ol3-layerswitcher.css" />
<link rel="stylesheet" href="https://rawgit.com/walkermatt/ol3-layerswitcher/master/examples/layerswitcher.css" />
<link rel="stylesheet" href="https://rawgit.com/walkermatt/ol3-popup/master/src/ol3-popup.css" />
@walkermatt
walkermatt / scratch.js
Last active January 16, 2018 09:07
Ramda stuff
var R = require('ramda');
var states = [
{symbol: 'CT', name: 'Connecticut', pop: 3574097},
{symbol: 'ME', name: 'Maine', pop: 1328361},
{symbol: 'MA', name: 'Massachusetts', pop: 6547629},
{symbol: 'NH', name: 'New Hampshire', pop: 1316470},
{symbol: 'RI', name: 'Rhode Island', pop: 1052567},
{symbol: 'VT', name: 'Vermont', pop: 623741},
];
# taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/
# generate server.pem with the following command:
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
# change to the directory you want to serve and run as follows:
# python simple-https-server.py
# then in your browser, visit:
# https://localhost:4443
# to add the certificate to Chrome see:
# http://stackoverflow.com/a/15076602/526860
import BaseHTTPServer
@walkermatt
walkermatt / mario.clj
Created October 17, 2015 19:08
Mario style pyramids!
; Inspired by
; http://entxtech.blogspot.co.uk/2015/10/how-to-write-more-functional-and.html
; "create a program where you can enter a height in blocks for a mario-like
; pyramid (like the one Mario runs up to reach the flag-pole). Once the height
; is specified, you then build the pyramid using hashes and spaces."
; ## [0,2]
; ## [1,2]
; ### [0,3]