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 geojson-groupby with all npm packages installed. Try it out:

var geojsonGroupby = require("geojson-groupby")

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

geojson-groupby v1.0.0

Group geojson features or array of json based on associated properties.


Group GeoJSON features or FeatureCollection based on associated properties and merge geometries to multigeometries.


npm install geojson-groupby


var geoGroupBy = require('geojson-groupby')
var group = geoGroupBy(array, properties [, collect])
  • array Array of JSON objects

  • properties Array JSON properties' path like or lookup object


      intervals: array of numbers
      ,property: string
      [,labels: array of string]

    intervals Array of intervals. Like [ 10, 20, 30, 40, 50] group the data in four ranges, whereas lower bound is inclusive and upper bound is exclusive.

    peroperty Property path like price

    labels Array of interval labels like [ 'low', 'medium', 'high']

  • collect Array of properties that need to be collected in array


data set
var features = [
    "id": 1, "geometry": {"type": "Point", "coordinates": [10, 10]},
    "properties": {"color": "blue","price": 150,"address": {"city": "New York"}}
  }, {
    "id": 2, "geometry": {"type": "Point", "coordinates": [20, 20]},
    "properties": {"color": "green","price": 200,"address": {"city": "London"}}
  }, {
    "id": 3, "geometry": {"type": "Point", "coordinates": [30, 30]},
    "properties": {"color": "red","price": 210,"address": {"city": "London"}}
  }, {
    "id": 4, "geometry": {"type": "Point", "coordinates": [40, 40]},
    "properties": {"color": "red","price": 280,"address": {"city": "New York"}}
  }, {
    "id": 5, "geometry": {"type": "Point", "coordinates": [50, 50]},
    "properties": {"color": "green","price": 300,"address": {"city": "New York"}}
  }, {
    "id": 6, "geometry": {"type": "Point", "coordinates": [60, 60]},
    "properties": {"color": "red","price": 360,"address": {"city": "Mumbai"}}

##### group features and merge geometries to multigeometries
geoGroupBy(features, ['properties.color'])
// output as
{blue: {geometry: {type: 'MultiPoint', coordinates: [[10, 10]]}},
  green: {geometry: {type: 'MultiPoint', coordinates: [[20, 20], [50, 50]]}},
      {type: 'MultiPoint',
        coordinates: [[30, 30], [40, 40], [60, 60]]}}}
##### group features, merge geometries to multigeometries and collect ids
geoGroupBy(features, ['properties.color'],['id'])
// output as
   {id: [1],
     geometry: {type: 'MultiPoint', coordinates: [[10, 10]]}},
   {id: [2, 5],
     geometry: {type: 'MultiPoint', coordinates: [[20, 20], [50, 50]]}},
   {id: [3, 4, 6],
      {type: 'MultiPoint',
        coordinates: [[30, 30], [40, 40], [60, 60]]}}}


This package `geojson-groupby` is based on [json-groupby](, so please also check different [examples]( on usage of json-groupby
## developing
Once you run
```npm isntall```

then for running test 

```npm run test```

to create build

```npm run build```

## license
This project is licensed under the terms of the MIT license.
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