Skip to content

Instantly share code, notes, and snippets.

@tjmgis
tjmgis / New TopographicLine SQL
Created April 30, 2015 15:51
New TopographicLine SQL
ALTER TABLE osmm_topo.topographicline ADD COLUMN style_description VARCHAR;
COMMIT;
ALTER TABLE osmm_topo.topographicline ADD COLUMN style_code INTEGER;
COMMIT;
CREATE INDEX fc_topoline_idx ON osmm_topo.topographicline(featurecode);
COMMIT;
UPDATE osmm_topo.topographicline SET (style_description, style_code) = ('Building Overhead Line', 10) WHERE style_code IS NULL AND featurecode = '10019' AND physicalpresence = 'Overhead'; --Must appear above Building Outline
COMMIT;
@tjmgis
tjmgis / New Topographic Point SQL
Last active August 29, 2015 14:20
New Topographic Point SQL
ALTER TABLE osmm_topo.topographicpoint ADD COLUMN style_description VARCHAR;
COMMIT;
ALTER TABLE osmm_topo.topographicpoint ADD COLUMN style_code INTEGER;
COMMIT;
UPDATE osmm_topo.topographicpoint SET (style_description, style_code) = ('Triangulation Point Or Pillar', 11) WHERE style_code IS NULL AND descriptiveterm = '{"Triangulation Point Or Pillar"}'; --Must appear above Structure, 5 because it has the same featurecode
COMMIT;
UPDATE osmm_topo.topographicpoint SET (style_description, style_code) = ('Spot Height', 1) WHERE style_code IS NULL AND featurecode = '10197';
COMMIT;
UPDATE osmm_topo.topographicpoint SET (style_description, style_code) = ('Culvert', 2) WHERE style_code IS NULL AND featurecode = '10085';
@tjmgis
tjmgis / New Cartographic Symbol SQL
Created April 30, 2015 10:31
New Cartographic Symbol SQL
ALTER TABLE osmm_topo.cartographicsymbol ADD COLUMN style_description VARCHAR;
COMMIT;
ALTER TABLE osmm_topo.cartographicsymbol ADD COLUMN style_code INTEGER;
COMMIT;
UPDATE osmm_topo.cartographicsymbol SET (style_description, style_code) = ('Culvert', 1) WHERE style_code IS NULL AND featurecode = '10091';
COMMIT;
UPDATE osmm_topo.cartographicsymbol SET (style_description, style_code) = ('Direction Of Flow', 2) WHERE style_code IS NULL AND featurecode = '10082';
COMMIT;
UPDATE osmm_topo.cartographicsymbol SET (style_description, style_code) = ('Boundary Half Mereing', 3) WHERE style_code IS NULL AND featurecode = '10130';
@tjmgis
tjmgis / New BoundaryLine Styling SQL
Last active August 29, 2015 14:20
New BoundaryLine Styling SQL
COPY (SELECT count(*) as total_count, featurecode, descriptiveterm FROM osmm_topo.boundaryline GROUP BY featurecode, descriptiveterm ORDER BY total_count DESC) TO 'C:/temp/boundaryline.csv' WITH CSV HEADER;
ALTER TABLE osmm_topo.boundaryline ADD COLUMN style_description VARCHAR;
COMMIT;
ALTER TABLE osmm_topo.boundaryline ADD COLUMN style_code INTEGER;
COMMIT;
UPDATE osmm_topo.boundaryline SET (style_description, style_code) = ('Parish Boundary', 1) WHERE style_code IS NULL AND featurecode = '10136';
COMMIT;
UPDATE osmm_topo.boundaryline SET (style_description, style_code) = ('District Boundary', 2) WHERE style_code IS NULL AND featurecode = '10131';
@tjmgis
tjmgis / gist:c6031cf11fa6ddda8755
Created April 9, 2015 19:16
openmap local sql create tables
CREATE SCHEMA openmaplocal;
COMMIT;
CREATE TABLE openmaplocal.building
(
ogc_fid serial NOT NULL,
wkb_geometry geometry(MultiPolygon,27700),
id character varying,
featcode double precision,
CONSTRAINT building_pkey PRIMARY KEY (ogc_fid)
@tjmgis
tjmgis / SQL query for finding Parent_Child_Grandchild records from OS AddressBase Premium
Created October 15, 2013 11:45
SQL query for finding Parent_Child_Grandchild records from OS AddressBase Premium
SELECT parent_uprn FROM addressbasepremium.delivery_geo_plus WHERE parent_uprn IS NOT NULL and multi_occ > 0 and geo_uprn IN
(SELECT parent_uprn FROM addressbasepremium.delivery_geo_plus where parent_uprn IS NOT NULL and multi_occ > 0 and geo_uprn IN
(SELECT parent_uprn FROM addressbasepremium.delivery_geo_plus WHERE parent_uprn IS NOT NULL and multi_occ = 0)));
@tjmgis
tjmgis / PostGIS SQL command for creating the OS_Cat column
Created August 8, 2013 13:00
PostGIS SQL command for creating the OS_Cat column for styling OS MaterMap layers to use with the released SLDs by Ordnance Survey
ALTER TABLE osmm.boundaryline ADD COLUMN os_cat VARCHAR;
UPDATE osmm.boundaryline
SET os_cat = (CASE
WHEN (descriptivegroup ='{"Political Or Administrative"}' and descriptiveterm ='{County}' and physicalpresence ='Boundary') then 'boundaryCounty'
WHEN (descriptivegroup ='{"Political Or Administrative"}' and descriptiveterm ='{District}' and physicalpresence ='Boundary') then 'boundaryDistrict'
WHEN (descriptivegroup ='{"Political Or Administrative"}' and descriptiveterm ='{Electoral}' and physicalpresence ='Boundary') then 'boundaryElectoral'
WHEN (descriptivegroup ='{"Political Or Administrative"}' and descriptiveterm ='{Parish}' and physicalpresence ='Boundary') then 'boundaryParish'
WHEN (descriptivegroup ='{"Political Or Administrative"}' and descriptiveterm ='{Parliamentary}' and physicalpresence ='Boundary') then 'boundaryParliamentary'
ELSE 'boundaryUnknown'
END)
@tjmgis
tjmgis / OS AddressBase Premium CSV Splitter
Created July 31, 2013 15:36
Python script for splitting OS AddressBase Premium CSV files by Record Indentifier
#-------------------------------------------------------------------------------
# Name: `OS AddressBase Premium Splitter v0.1
# Purpose: `This Python script is used to read OS AddressBase Premium CSV
# files and split them by record identifier type.
#
# Author: `Tim Martin, GIS Consultant, Pre and Post Sale Support
#
# Created: `31/07/2013
# Copyright: `(c) Ordnance Survey 2013
# Licence: `THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@tjmgis
tjmgis / OS VectorMap District Cartographic Rendering
Created June 24, 2013 16:48
OS VectorMap District guide for cartographic rendering
Background
OS VectorMap District is made up of 23 layers of data ranging from woodland to tidal water to POI features.
Ordnance Survey released a number of Style Layer Descriptors (SLDs). These SLDs although they can be imported and used to style the data within QGIS several of the SLDs need editing. There also needs to be some post processing applied to the data in order to render as a cartographic product.
Firstly, I want to use the Dft NUmber and the Road name as a label so I added a new column and created a concatenated string using the SQL commands below.
ALTER TABLE vmd.road ADD COLUMN roadinfo VARCHAR;
COMMIT;
@tjmgis
tjmgis / OS VectorMap Local QGIS Text Recipe
Last active December 18, 2015 21:38
OS VectorMap Local QGIS Text Recipe - guide to how to post process OS VectorMap Local so that you can use QGIS data driven styling to create cartographic text styling.
The following is a guide for post processing OS VectorMap Local so that it can be rendered within QGIS.
We need X Y coordinates so we can use the anchor position
ALTER TABLE vml.text ADD COLUMN x_coordinate NUMERIC;
COMMIT;
update vml.text set x_coordinate = ST_X(wkb_geometry);
COMMIT;
ALTER TABLE vml.text ADD COLUMN y_coordinate NUMERIC;