SpatialReference
A helper library for translating between spatial reference systems
Usage
Basic installation: npm install spatialreference
Then to use the module: var SR = require('spatialreference')
With a DB
To use this module with a db that can store or retrieve WKTs, it needs to support (or be wrapped to support) two functions:
Then initialize the SpatialReference object with a db in the options.db key
var SR = var db = // or your db that supports getWKT and insertWKTvar sr = db: db
With a logger
By default SpatialReference will log to the console, but you can optionally pass in a logger in the options key. It needs to support a function like:
{// write a log!}
var SR = var logger = var sr = logger: logger
API
wkidToWkt
This method takes a spatial reference system well-known id and gets the well-known text. If the WKID is an esri code, then it will use the esri-proj-codes library. If the WKID is available in a passed in database it will get it from there. Else it will make a request to http://www.epsg.io, insert the WKT into the database and return it to the client.
Example using koop-pgcache
var SpatialReference =var db =var sr = db: dbsr
esriLookup
This is a pure wrapper around the esri-proj-codes library. It gets the esri format of the well-known text for a projection when given the well-known id.
var SpatialReference = var sr = sr
Acknowledgements
This module leans heavily on the spatial reference information saved in PostGIS and the data available at epsg.io. It would not be possible without those two resources. So thank you to all involved.