npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

geojson-groupby

v1.0.0

Published

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

Downloads

1

Readme

geojson-groupby

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

installation

npm install geojson-groupby

usage

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

  • properties Array JSON properties' path like address.city or lookup object

    lookup

    {
      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

examples

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

```

This package `geojson-groupby` is based on [json-groupby](https://github.com/gagan-bansal/json-groupby), so please also check different [examples](https://github.com/gagan-bansal/json-groupby#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.