Some PostGIS functions only accept multi type geometry, so I write a simple geojson utility package to help me aggregate geojson features.
The basic purpose of geojson-multiply is to generate a MutliPoint/MultiLineString/MultiPolygon geojson feature from many Point/LineString/Polygon geojson features. So this package provides a function
1 | multiply(geojsons[, options]) |
Where the geojsons could be a geojson feature, an array of geojson features, or a geojson feature collection
Not just the coordinates, the multiply() also supports the aggregation of properties. Its options parameter accepts two input:
properties- the default properties of result geojsononEachFeature- a function to aggregate properties. It has four parameters:properties- the result geojson’s propertiesfeatureProp- input feature geojson’s propertiesindex- input feature geojson’s index in the arraygeojsons- geojson array.
It takes the form of Array.reduce() and make the aggregation pretty straightforward:
1 | var multiply = require('geojson-multiply'); |
This package has been published at npm. If you think it’s helpful, just install and try!
1 | npm install geojson-multiply --save |