Deprecated - please use dbgeo instead.
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.
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);
});
npm install postgeo
The API is very limited for now, but there is a lot of room for extension and improvement. Feel free to contribute!
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
.
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
CC0