/postgeo

Node module for returning PostGIS queries as GeoJSON or TopoJSON [Deprecated - please use dbgeo instead.]

Primary LanguageJavaScriptCreative Commons Zero v1.0 UniversalCC0-1.0

Deprecated - please use dbgeo instead.

postgeo

A Node.js module for returning PostGIS queries as usable GeoJSON or TopoJSON objects. While PostGIS allows you to select geometries as GeoJSON with ST_AsGeoJSON, it does not return the entire query as a usable GeoJSON FeatureCollection for use with mapping APIs such as Leaflet.js or D3.js.

Heavily influenced by Bryan McBride's PostGIS to GeoJSON PHP script and postgis2geojson.py.

Example Usage
var postgeo = require("postgeo");

postgeo.connect("postgres://user@host:port/database");

postgeo.query("SELECT id, name ST_AsGeoJSON(geom) AS geometry FROM table", "geojson", function(data) {
    console.log(data);
});
Installation
npm install postgeo

API

The API is very limited for now, but there is a lot of room for extension and improvement. Feel free to contribute!


connect(credentials)

Takes a single string parameter, credentials, in the format

postgres://user@host:port/database

In most cases host will be localhost and port will be 5432.


query(sql, format, callback(output))

Arguments (all are required)

  • sql - The query to be executed on the database. **Must include ST_AsGeoJSON(geom) AS geometry ** in order to work properly.
  • format - can be either "geojson" or "topojson"
  • callback - a function with one parameter that returns the output of the query

License

CC0