npm

Bring the best of OSS JavaScript development to your projects with npm Orgs - private packages & team management tools.Learn more »

bookshelf-geojson

1.0.0 • Public • Published

bookshelf-geojson

This Bookshelf.js plugin automatically parses and formats PostGIS geometry columns as GeoJSON in your models.

npm version Dependency Status Build Status Coverage Status License

Developed at the Media Engineering Institute (HEIG-VD).

Usage

const bookshelf = require('bookshelf');
const bookshelfGeojson = require('bookshelf-geojson');
const knex = require('knex');
 
const db = knex({
  client: 'postgresql',
  connection: 'postgres://localhost/bookshelf-geojson'
});
 
const Bookshelf = bookshelf(knex);
Bookshelf.plugin(bookshelfGeojson(db));
 
const Address = Bookshelf.Model.extend({
  tableName: 'addresses',
 
  // Indicate the column containing a PostGIS geometry type.
  geojson: 'location'
});
 
const geojson = {
  type: 'Point',
  coordinates: [ 24, 42 ]
};
 
// The GeoJSON is automatically serialized for PostGIS.
const address = new Address();
address.set('location', geojson);
address.save();
 
// The GeoJSON is automatically parsed with PostGIS's ST_AsGeoJSON function.
const anotherAddress = new Address({ id: 1 }).fetch();
console.log(anotherAddress.get('location'));
// { id: 1, location: { type: 'Point', coordinates: [ 33, 66 ] } }

install

npm i bookshelf-geojson

Downloadsweekly downloads

14

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability