Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including dbgeo with all npm packages installed. Try it out:

var dbgeo = require("dbgeo")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

dbgeo v1.1.0

A Node.js module for converting database queries to GeoJSON and TopoJSON


Convert database query results to GeoJSON or TopoJSON. Inspired by Bryan McBride's PHP-Database-GeoJSON. Works with your database of choice - ideally paired with node-mysql, node-postgres, or mongodb. It is a more flexible version of postgeo and mysql2geojson (both deprecated).

npm install dbgeo
Example Usage
var dbgeo = require('dbgeo')

// Query a database...

dbgeo.parse(data, {
  outputFormat: 'geojson'
}, function(error, result) {
  // This will log a valid GeoJSON FeatureCollection

See test/test.js for more examples.


.parse(data, options, callback)

data (required)

An array of objects, usually results from a database query.

options (optional)

Configuration object that can contain the following keys:

argumentdescriptionvaluesdefault value
geometryTypeFormat of input geometrywkb, wkt, geojson, llwkb
geometryColumnName of column that contains geometry. If input geometry type is "ll", this is an array in the format ['longitude', 'latitude']Any stringgeom
outputFormatDesired output formatgeojson, topojsongeojson
precisionTrim the coordinate precision of the output to a given number of digits using geojson-precisionAny integernull (will not trim precision)
quantizationValue for quantization process, typically specified as powers of ten, see topojson.quantizeAny integer greater than onenull (no quantization)
callback (required)

A function with two parameters: an error, and a result object.

Examples can be found in test/test.js.


The default options for .parse(). You can set these before using .parse() if you plan to use the same options continuously.




RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free