Jump to Content
geekswithlatitudeGuides
GuidesDiscussions
v1.0

Guidesgeekswithlatitude
Guides
v1.0GuidesDiscussions

Introduction

  • Introduction
  • Frequently Asked Questions

Tutorials

  • Astun Loader
  • Getting Started with Node
  • PostGIS and QGIS: Powerful Partners

PostGIS SQL Snippets

  • ST_Intersects and &&
  • Finding Distinct Features Closest to a Point
  • Get Extent of Table
  • Change projection of data
  • Count number of columns in table
  • Copy from CSV with delimiter and quotes
  • Size of Database
  • Size of schema
  • Concatenate attributes
  • Find duplicates
  • Select by date
  • Find Invalid Geometries
  • KNN Function
  • Size of Database Table
  • Deleting duplicates from a table
  • Insert data into particular rows/columns
  • Update SET

Python Code Snippets

  • Using PyInstaller to create exe
  • CPU Count
  • CSV to SQLite
  • Create exe with data files
  • wxPython Splash Screen
  • Read data from ZipFile
  • Find and List Files
  • Getting part of a string
  • Replacing %s with variables
  • Get list of subdirectories
  • Get last folder of a path
  • Number of CPUs
  • Get filename from path without extension

GeoWebCache

  • Tilenaming

Command Prompt Code Snippets

  • Time a command

GDAL and OGR2OGR

  • PostGIS to SQLite
  • Promote to MULTI

1:50k Gazetteer

  • Header line for 1:50k Gazetteer
  • Create attribute index for 1:50k Gazetteer
  • Create Full Text Search (FTS)
  • Create schema and table
  • Create spatial index

AddressBase

  • Create schema and table
  • Create spatial index
  • Create attribute indexes
  • Create Postal Addresses View

AddressBase Plus

  • Create Geographic Addresses View
  • Create Postal Addresses View
  • Create schema and table
  • Create spatial index
  • Create attribute indexes

AddressBase Premium

  • AddressBase Premium Classification Codes
  • Create schema and tables
  • Create Postal Addresses View
  • Postcode and PostcodeLocator difference

BoundaryLine

  • Create attribute indexes for BoundaryLine
  • Create schema
  • Loading code for BoundaryLine to PostGIS

CodePoint Open

  • CodePoint Open Admin Lookup List
  • Create Full Text Search (FTS)
  • Single space for Postcode
  • Python Script to ESRI Shapefile
  • Create Lookup table

CodePoint with Polygons

  • Create schema and tables
  • Create seperate tables for CodePoint with Polygons

Meridian2

  • Create Meridian2 Attribute Indexes

OS Locator

  • Header line for OS Locator
  • Create attribute indexes for OS Locator

OSMM ITN

  • Create schema and tables
  • Create attribute indexes for OSMM ITN
  • Create spatial indexes for OSMM ITN
  • Create ITN Lookup table

OSMM Topography Layer

  • Applying COU
  • Adding Building Heights to Topo
  • QGIS CartographicText

OSMM Sites Layer

  • Create spatial index for OSMM Sites Layer
  • Create tables for OSMM Sites Layer

OS VectorMap District

  • Change projection to EPSG:3857

OS VectorMap Local

  • Create schema and tables
  • Change projection to EPSG:3857

Strategi

  • Create attribute indexes for Strategi
  • Change projection to EPSG:3857

Bash

  • Writing Bash scripts on windows

Temporary Code

  • Topo COU Post Processing
  • OSMM MapBox Post Processing
  • OSMM MapBox Studio SQL
  • Core table COU columns
  • COU indexes

Leaflet

  • Leaflet Map with GeoJSON popups

JMeter

  • Using JMeter to test PostGIS
Powered by 

KNN Function

Suggest Edits
CREATE TABLE building_height AS 
SELECT b.ogc_fid, geom, id, featcode,  
(SELECT h.prop_value FROM terrain h 
  ORDER BY b.geom <-> h.geom LIMIT 1)
FROM building b;

Useful blog posts

http://geeohspatial.blogspot.co.uk/2013/05/k-nearest-neighbor-search-in-postgis.html

http://boundlessgeo.com/2011/09/indexed-nearest-neighbour-search-in-postgis/

Updated less than a minute ago