geojson-multiply: a simple package to pack single tyle geojson features
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
MultiPolygon geojson feature from many
Polygon geojson features. So this package provides a function
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 geojson
onEachFeature- a function to aggregate properties. It has four parameters:
properties- the result geojson’s properties
featureProp- input feature geojson’s properties
index- input feature geojson’s index in the array
geojsons- geojson array.
It takes the form of Array.reduce() and make the aggregation pretty straightforward:
This package has been published at npm. If you think it’s helpful, just install and try!