# geojson-clustering

> Clustering geoJSON with k-means

Latest version **1.1.5** (published 2019-01-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install geojson-clustering
pnpm add geojson-clustering
yarn add geojson-clustering
bun add geojson-clustering
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.5 |
| Published | 2019-01-23 |
| First published | 2019-01-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 95.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | rickyplouis |
| Maintainers | ricardoplouis |
| Keywords | k-means, geoJSON, clustering, machine-learning |

## Links

- npm: https://www.npmjs.com/package/geojson-clustering
- Repository: https://github.com/rickyplouis/addressClustering
- Homepage: https://github.com/rickyplouis/addressClustering#readme
- Issues: https://github.com/rickyplouis/addressClustering/issues
- npm.io page: https://npm.io/package/geojson-clustering

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.1.5 (latest) — 2019-01-23
- 1.1.4 — 2019-01-22
- 1.1.3 — 2019-01-22
- 1.1.2 — 2019-01-22
- 1.1.1 — 2019-01-22
- 1.1.0 — 2019-01-22
- 1.0.0 — 2019-01-22

## README

## geojson-clustering [![Build Status](https://travis-ci.org/rickyplouis/geojson-clustering.svg?branch=master)](https://travis-ci.org/rickyplouis/geojson-clustering) [![Coverage Status](https://coveralls.io/repos/github/rickyplouis/geojson-clustering/badge.svg?branch=master)](https://coveralls.io/github/rickyplouis/geojson-clustering?branch=master) [![npm version](https://badge.fury.io/js/geojson-clustering.svg)](https://badge.fury.io/js/geojson-clustering)

### What is geojson-clustering
A tool built to allow k-means clustering of geojson data.

##### Note: A primer of geojson can be found  [here](http://geojson.org/)

### Installation
```
$ npm i geojson-clustering
```
### Example
```javascript
const geoclustering = require('geojson-clustering');
const { createClusters, writeClustersToFile } = geoclustering;

const filepath = './sampleData.geojson';

/*
 * geojson object must follow GEOJSON spec outlined
 * here: https://tools.ietf.org/html/rfc7946
 */
const samplegeojson =
	{
		"type": "FeatureCollection",
		"features":
			[...]
	}

/*
 * Clusters sampledata.geojson into three clusters
 * NOTE: maxIterations is optional (defaults to 1000)
 */
createClusters(filepath, 3);

/*
 * Clusters sampledata.geojson int four clusters
 * and writes it to output/output.geojson
 */
writeClustersToFile(filepath, 4)

/*
 * Clusters samplegeojson into seven clusters
 * and runs 2000 iterations
 * NOTE: The higher the iterations, the slower it runs
 */
createClusters(samplegeojson, 7, 2000);

/*
 * Clusters samplegeojson into three clusters
 * and runs 1500 iterations
 */

writeClustersToFile(samplegeojson, 3, 1500);

```
### Methods

#### createClusters(inputData, kClusters, maxIterations)

#### writeToFile(inputData, kClusters, maxIterations)

| parameter | type | description | required | default |
| -----------|:---------:| -----:|-----:|-----:|
| inputData      | Object or String |Takes in a geojson object or a filepath to a .geojson file| true | ---
| kClusters| Number      | The number of clusters to seperate data into| false | 3
| maxIter| number |The number of iterations to  | false | 1000


#### You can use sample .geojson data located [here](https://github.com/rickyplouis/geojson-clustering/tree/master/sampleData)

### Viewing geojson data
 If you want to quickly view your outputted geojson files then check out [this site](http://geojson.io) and upload your .geojson files.

---
_Source: https://npm.io/package/geojson-clustering · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
