Bookshelf plugin for parsing & serializing PostGIS columns
npm install bookshelf-postgisBookshelf 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)!
``javascript`
npm install bookshelf-postgis --save
Apply the plugin:
`javascript
const postgis = require('bookshelf-postgis');
bookshelf.plugin(postgis);
`
And add geography or geometry columns to your model:`javascript``
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']
});
[build-url]: https://travis-ci.org/joshswan/bookshelf-postgis
[build-image]: https://travis-ci.org/joshswan/bookshelf-postgis.svg?branch=master
[depstat-url]: https://david-dm.org/joshswan/bookshelf-postgis
[depstat-image]: https://david-dm.org/joshswan/bookshelf-postgis.svg
[devdepstat-url]: https://david-dm.org/joshswan/bookshelf-postgis#info=devDependencies
[devdepstat-image]: https://david-dm.org/joshswan/bookshelf-postgis/dev-status.svg
[npm-url]: https://www.npmjs.com/package/bookshelf-postgis
[npm-image]: https://badge.fury.io/js/bookshelf-postgis.svg