Skip to content

A script to convert Ordnance Survey Open Names CSV files into a JSON array of WGS84 Features

License

Notifications You must be signed in to change notification settings

abiddiscombe/opennames-to-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OS OpenNames to JSON

🚀 Refactored from Deno to Go as part of my ongoing learning!
This version can process more of the dataset in less time (Apple M1: Deno - 98 sec, Go - 34 sec).

Ordnance Survey (OS) Open Names is a comprehensive dataset of place names, roads numbers and postcodes for Great Britain. It's an OGL dataset provided in the British National Grid EPSG:27700 CRS.

This code converts the OS Open Names CSV dataset into a JSON array consisting of multiple GeoJSON Features. It's designed for bulk importing into MongoDB using MongoDB Compass. The bulk importer expects a JSON array of features, not a GeoJSON object - and therefore this script won't create a valid GeoJSON file.

The following metadata is included by default: id, type, localType, name1, name1Lang, name2, name2Lang, geomX, geomY. Geometry is converted to lat-lon values, and the name2 and name2Lang are often empty strings.

Running

I'm not creating prebuilt binaries for this script at this time.

  1. Install Go on your machine. I do this via Homebrew on MacOS.

  2. Copy the /Data directory from OS Open Names into the root of this repository. This directory contains ~819 CSV files each representing a distinct region.

  3. Run the script with go run main.go. The output is stored in a newly created output.json file.

If you choose to host this dataset with MongoDB you must create a 2dsphere index to handle geospatial queries. I also strongly advise creating indexes for any other columns you plan to query against.

Credits

MIT License. Feel free to refactor to suit your needs.

This script relies on the awesome wroge/wgs84 and paulmach/orb packages for coordinate transformation and GeoJSON parsing.

About

A script to convert Ordnance Survey Open Names CSV files into a JSON array of WGS84 Features

Topics

Resources

License

Stars

Watchers

Forks

Languages