@acrossthecloud/dbgeo 中文文档教程
dbgeo
将数据库查询结果转换为 GeoJSON 或 TopoJSON。 灵感来自 Bryan McBride 的 PHP-Database- GeoJSON。 与您选择的数据库一起工作 - 最好与 node-mysql、node-postgres,或 mongodb。 它是 postgeo 和 mysql2geojson 的更灵活的版本(均已弃用)。
Installation
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
console.log(result)
});
有关更多示例,请参见 test/test.js
。
API
.parse(data, options, callback)
data (required)
一组对象,通常来自数据库查询。
options (optional)
可以包含以下键的配置对象:
argument | description | values | default value |
---|---|---|---|
geometryType | Format of input geometry | wkb, wkt, geojson, ll | wkb |
geometryColumn | Name of column that contains geometry. If input geometry type is "ll", this is an array in the format ['longitude', 'latitude'] | Any string | geom |
outputFormat | Desired output format | geojson, topojson | geojson |
precision | Trim the coordinate precision of the output to a given number of digits using geojson-precision | Any integer | null (will not trim precision) |
quantization | Value for quantization process, typically specified as powers of ten, see topojson.quantize | Any integer greater than one | null (no quantization) |
callback (required)
具有两个参数的函数:错误和结果对象。
示例可以在 test/test.js
中找到。
.defaults{}
.parse()
的默认选项。 如果您打算连续使用相同的选项,则可以在使用 .parse()
之前设置这些。
License
CC0
dbgeo
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).
Installation
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
console.log(result)
});
See test/test.js
for more examples.
API
.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:
argument | description | values | default value |
---|---|---|---|
geometryType | Format of input geometry | wkb, wkt, geojson, ll | wkb |
geometryColumn | Name of column that contains geometry. If input geometry type is "ll", this is an array in the format ['longitude', 'latitude'] | Any string | geom |
outputFormat | Desired output format | geojson, topojson | geojson |
precision | Trim the coordinate precision of the output to a given number of digits using geojson-precision | Any integer | null (will not trim precision) |
quantization | Value for quantization process, typically specified as powers of ten, see topojson.quantize | Any integer greater than one | null (no quantization) |
callback (required)
A function with two parameters: an error, and a result object.
Examples can be found in test/test.js
.
.defaults{}
The default options for .parse()
. You can set these before using .parse()
if you plan to use the same options continuously.
License
CC0