Skip to content

Instantly share code, notes, and snippets.

@mtravis
mtravis / ogr2vrt_27700.py
Last active September 7, 2017 15:46
Adapted the original ogr2vrt.py script to create a OSGB ready vrt file that references a tab file for use in QGIS - no more having to change the CRS!
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################
# $Id$
#
# Project: OGR Python samples
# Purpose: Create OGR VRT from source datasource
# Author: Frank Warmerdam, warmerdam@pobox.com
#
###############################################################################
@mtravis
mtravis / total_area_layer.sql
Created November 17, 2016 14:50
Creates a SQL statement that will output the total area of each layer in a PostGIS database
Select 'Select ''' || quote_ident(f_table_name) || ''' as name, Sum((ST_Area(' || quote_ident(f_geometry_column) || ')) from '
|| quote_ident(f_table_schema) || '.' || quote_ident(f_table_name) || ' UNION'
FROM geometry_columns
order by f_table_name
@mtravis
mtravis / L.Control.MousePosition27700.js
Last active April 27, 2023 07:53
Leaflet mouse position plugin adapted for BNG (EPSG:27700)
//Adpated by mtravis from https://github.com/ardhi/Leaflet.MousePosition/ for use with BNG co-ords. Inspired by http://ghost.mixedbredie.net/reprojecting-leaflet-coordinates/
//You will still need Leaflet.MousePosition/src/L.Control.MousePosition.css from the original repo for this to work
//Also include a link to https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.10/proj4.js
//Finally add L.control.mousePosition().addTo(map); to the your script
L.Control.MousePosition = L.Control.extend({
options: {
position: 'bottomleft',
separator: ' : ',
emptyString: 'Unavailable',
@mtravis
mtravis / snapping.py
Last active October 17, 2015 15:59
turn snapping on/off in QGIS
from qgis.core import *
from qgis.utils import iface
from PyQt4.QtCore import *
from PyQt4.QtGui import *
def snapping_toggle():
layer = QgsMapLayerRegistry.instance().mapLayersByName("topographicline")[0]
#layer = iface.activeLayer()
_, enabled, _, _, _, _ = QgsProject.instance().snapSettingsForLayer(layer.id())
QgsProject.instance().setSnapSettingsForLayer(layer.id(), not enabled, 0, 1, 10, True)
@mtravis
mtravis / mapCenter
Created June 27, 2015 09:43
QGIS Python Function to get map canvas center
from qgis.core import *
from qgis.gui import *
from qgis.utils import iface
@qgsfunction(args=0, group='Custom')
def mapCenter(value1,feature, parent):
x = str(int(iface.mapCanvas().extent().center().x()))
y = str(int(iface.mapCanvas().extent().center().y()))
point = x + ',' + y
return point
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix sr: <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/>
prefix lrhpi: <http://landregistry.data.gov.uk/def/hpi/>
prefix lrppi: <http://landregistry.data.gov.uk/def/ppi/>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix lrcommon: <http://landregistry.data.gov.uk/def/common/>
@mtravis
mtravis / Loader_Linux
Created April 8, 2013 17:34
Loader config for Linux
# Note: Environment variables can be used with any of
# the options by using a token of the form:
# $HOME, ${HOME} or %TEMP% (Windows only)
# The directory containing your source files.
# All supported files in the specified directory and
# it's descendants will be loaded.
src_dir=/home/matt/loader/data/import/
# The directory used to store the translated data
L.Draw.Circle = L.Draw.SimpleShape.extend({
statics: {
TYPE: 'circle'
},
options: {
shapeOptions: {
stroke: true,
color: '#f06eaa',
weight: 4,
<OGRVRTDataSource>
<OGRVRTLayer name="50kgaz2012_new">
<SrcDataSource>C:\OSOpenData\Data\Gazetteer\50kgaz2012_new.csv</SrcDataSource>
<GeometryType>wkbPoint</GeometryType>
<LayerSRS>EPSG:27700</LayerSRS>
<GeometryField encoding="PointFromColumns" x="EAST" y="NORTH"/>
</OGRVRTLayer>
</OGRVRTDataSource>
# The directory containing your source OS Open Data
# files. All files in the specified directory and it's decendents will be loaded.
src_dir=C:\OSOpenWorkingArea\Data\
# The .csv file containing parameters for each dataset
csv_table=C:\OSOpenWorkingArea\Table.csv
# Database the datasets will be loaded into
database=dbname='OSOpenData' user='postgres' host='localhost' password='postgres'