Skip to content

Instantly share code, notes, and snippets.

View schoenobates's full-sized avatar

Alex Davies-Moore schoenobates

View GitHub Profile
@schoenobates
schoenobates / OSGB.java
Created August 28, 2012 12:03
WGS-84 to OSGB36 Coords Conversion
/**
* Java based conversion of Chris Veness' scripts for Lat/Lon WG84 to OSGB36 coords
*
* http://www.movable-type.co.uk/scripts/latlong-convert-coords.html
* (c) Chris Veness 2005-2010 Released under an LGPL license
* http://www.fsf.org/licensing/licenses/lgpl.html
*
*/
public class OSGB {
@schoenobates
schoenobates / monos.js
Created October 3, 2012 14:16
MongoDB scripts for WGS84 -> OSGB conversions on the server side
/*
--------------------------------------------------------------------------------------------------------------------
EXTENSIONS
--------------------------------------------------------------------------------------------------------------------
*/
/** Converts numeric degrees to radians */
if (typeof Number.prototype.toRad == 'undefined') {
Number.prototype.toRad = function () {
return this * Math.PI / 180;
@schoenobates
schoenobates / DroidFileIdentifier.java
Created November 29, 2012 12:41
National Archives DROID embed
import uk.gov.nationalarchives.droid.core.BinarySignatureIdentifier;
import uk.gov.nationalarchives.droid.core.SignatureParseException;
import uk.gov.nationalarchives.droid.core.interfaces.IdentificationRequest;
import uk.gov.nationalarchives.droid.core.interfaces.IdentificationResult;
import uk.gov.nationalarchives.droid.core.interfaces.IdentificationResultCollection;
import uk.gov.nationalarchives.droid.core.interfaces.RequestIdentifier;
import uk.gov.nationalarchives.droid.core.interfaces.resource.FileSystemIdentificationRequest;
import uk.gov.nationalarchives.droid.core.interfaces.resource.RequestMetaData;
import java.io.File;
@schoenobates
schoenobates / epsg.27701.sql
Created November 5, 2015 11:31
Add NAD Grid for EPSG 27700
INSERT into
spatial_ref_sys (srid, auth_name, auth_srid, proj4text, srtext)
values (
27701, 'custom', 27701,
'+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs +nadgrids=/usr/local/share/osgb/OSTN02_NTv2.gsb',
'PROJCS["OSGB 1936 / British National Grid NAD Grid Extension",GEOGCS["OSGB 1936",DATUM["OSGB_1936",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]],TOWGS84[446.448,-125.157,542.06,0.15,0.247,0.842,-20.489],EXTENSION["PROJ4_GRIDS","/usr/local/share/osgb/OSTN02_NTv2.gsb"],AUTHORITY["EPSG","6277"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4277"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",49],PARAMETER["central_meridian",-2],PARAMETER["scale_factor",0.9996012717],PARAMETER["false_easting",400000],PARAMETER["false_northing",-100000],UNIT["Meter",1]]'
);
@schoenobates
schoenobates / ogr.go
Last active January 17, 2016 18:56
Example of using OGR APIs from Go
package main
/*
#include <stdio.h>
#include <stdlib.h>
#include "gdal_version.h"
#include "ogr_api.h"
#cgo darwin pkg-config: gdal
#cgo linux pkg-config: gdal
@schoenobates
schoenobates / Poly.java
Created April 22, 2016 12:51
WKT Polygon Regex Validator: Whitespace and First/Last point validation in linear ring... needs to check for more than one two points per linear ring
POLYGON\s*\(\s*(\(\s*(?<X>\-?\d+(:?\.\d+)?)\s+(?<Y>\-?\d+(:?\.\d+)?)(?:\s*,\s*\-?\d+(:?\.\d+)?\s+\-?\d+(:?\.\d+)?)*\s*,\s*\k<X>\s+\k<Y>\s*\))(\s*,\s*\(\s*(?<XH>\-?\d+(:?\.\d+)?)\s+(?<YH>\-?\d+(:?\.\d+)?)(?:\s*,\s*\-?\d+(:?\.\d+)?\s+\-?\d+(:?\.\d+)?)*\s*,\s*\k<XH>\s+\k<YH>\s*\))*\s*\)
@schoenobates
schoenobates / mbtile-extractor.py
Created August 3, 2012 09:43
Extracts a pyramid of image tiles from a MBTile file
#!/usr/bin/env python
import sqlite3 as sqlite
import os
import sys
import time
# Extracts an mbtiles database into a pyramid structure
if len(sys.argv) != 2:
@schoenobates
schoenobates / main.go
Created October 5, 2019 11:49
Convert an ASCII DEM File to RAW or PNG for import into other apps (e.g. Unity)
package main
import (
"bufio"
"encoding/binary"
"flag"
"fmt"
"image"
"image/color"
"image/png"
@schoenobates
schoenobates / osgb.go
Created May 15, 2015 15:17
Using Golang with Proj4 to convert between OSGB and WGS84 (both to and from)
package main
/*
#cgo LDFLAGS: -lproj
#include <string.h>
#include <proj_api.h>
*/
import "C"
import (
"fmt"
@schoenobates
schoenobates / jooq.gradle
Created June 19, 2014 10:32
JOOQ Generator Gradle
import org.jooq.util.jaxb.*
import org.jooq.util.*
ext.db = [
url: 'jdbc:postgresql://host/db',
user: 'user',
password: 'user',
schema: 'schema'
]