JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 141
  • Score
    100M100P100Q88149F
  • License BSD-3-Clause

PostGIS data types for node-postgres

Package Exports

  • pg-postgis-types

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pg-postgis-types) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

pg-postgis-types Build Status

Use PostGIS geometry types with node-postgres.

This module registers parsers for the PostGIS geometry types. You can also plug in your own WKB parser.

Installation

npm install pg-postgis-types

Documentation

postgis(pg, connection, callback)

Fetches the OIDs for the given types.

Parameters

parameter type description
pg Object The pg object from require('pg')
connection String The connection string to use when fetching the types
callback Function The callback to call after the types are fetched

Callback is called with an error argument.

postgis.isGeometryType(oid)

Returns true if the given OID is a geometry or geography type

Parameters

parameter type description
oid Number The oid of a column

postgis.setGeometryParser(parser)

Setup a custom parser for geometry/geography columns. The parser is a function that accepts one argument for the string value to parse. The library uses wkx by default to parse goemetries. You can use this if you want to use your own WKB parser.

Parameters

parameter type description
parser Function The custom parser to use for geometry columns

Example

var postgis = require('pg-postgis-types');

postgis(pg, connection, (err, oids) {
  if (err) {
    throw err;
  }

  pg.connect(connection, function (err, client, done) {
    if (err) {
      return callback(err);
    }

    var sql = "SELECT ST_GeomFromText('POINT(1 2)') AS geom";

    client.query(sql, null, function (err, results) {
      done();

      if (err) {
        throw err;
      }

      var geojson = results.rows[0].geom.toGeoJSON();

      // do something cool with geojson
    });
  });
});