Skip to content

Bookshelf plugin for parsing & serializing PostGIS geography/geometry columns

License

Notifications You must be signed in to change notification settings

joshswan/bookshelf-postgis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bookshelf-postgis

NPM Version Build Status Dependency Status Dev Dependency Status

Bookshelf plugin for PostGIS to automatically parse and serialize geometry/geography columns on fetch and save, respectively. Geography columns are parsed to specified attributes (e.g. [lon, lat] results in a lon and a lat attribute on the model), and geometry columns are parsed to GeoJSON.

NOTE: Geography columns must already be WGS 84 lon lat (SRID:4326)!

Installation

npm install bookshelf-postgis --save

Usage

Apply the plugin:

const postgis = require('bookshelf-postgis');

bookshelf.plugin(postgis);

And add geography or geometry columns to your model:

const User = bookshelf.Model.extend({
  tableName: 'users',
  geography: {
    location: ['lon', 'lat'],
    // Use dot notation to specify deeper nesting
    geo: ['address.lon', 'address.lat'],
    geo2: ['location[0]', 'location[1]'],
  },
  geometry: ['geometry']
});