Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement @turf/clusters-dbscan module #812

Merged
merged 33 commits into from
Jul 14, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d0d8970
Implement `@turf/clusters-distance` module
DenisCarriere Jun 21, 2017
24cf66d
Update yarn lock
DenisCarriere Jun 21, 2017
8669d30
Update debug file
DenisCarriere Jun 21, 2017
e5fb827
simplified calculation (run almost x2 faster);
stebogit Jul 7, 2017
17ca549
Convert index.js to ES5
DenisCarriere Jul 12, 2017
ed0e48a
Publish new clusters-distance approach
DenisCarriere Jul 12, 2017
88d3953
Add minPoints to tests param
DenisCarriere Jul 12, 2017
cf53d66
Update Typescript tests
DenisCarriere Jul 12, 2017
4636f3a
Merge branch 'master' into clusters-distance
DenisCarriere Jul 12, 2017
0893af2
added units parameter; added parameters validation and throw tests
stebogit Jul 13, 2017
359815a
Suggested DBSCAN implementation for `@turf/clusters-distance` (#840)
stebogit Jul 14, 2017
a14fa69
Update Typescript Defintion (3 outputs)
DenisCarriere Jul 14, 2017
0a60b90
Merge branch 'master' into clusters-distance
DenisCarriere Jul 14, 2017
144ef79
Merge branch 'clusters-distance' of /~https://github.com/Turfjs/turf in…
stebogit Jul 14, 2017
ef76c37
Add geokdbush as reference to repo
DenisCarriere Jul 14, 2017
7bee88f
Single line JSDocs param
DenisCarriere Jul 14, 2017
3eb3d66
Fix tests (results.points)
DenisCarriere Jul 14, 2017
07dea46
Make both index + index.geokdbush work
DenisCarriere Jul 14, 2017
62e4e91
Place Geokdbush to DevDependencies
DenisCarriere Jul 14, 2017
63275fc
Fix noise issue
DenisCarriere Jul 14, 2017
82485d8
Prevent input mutation & add edges
DenisCarriere Jul 14, 2017
8a45889
Major changes
DenisCarriere Jul 14, 2017
c2be7be
Create a set of clusters to colorize
DenisCarriere Jul 14, 2017
01e92de
Define edges with cross
DenisCarriere Jul 14, 2017
01bc50b
Add CentroidFromProperty to tests
DenisCarriere Jul 14, 2017
d3a3166
Updates based on @stebogit comments
DenisCarriere Jul 14, 2017
28436e7
Update Readme
DenisCarriere Jul 14, 2017
d926702
Update benchmark results & drop geokdbush
DenisCarriere Jul 14, 2017
7fe4acf
Add noisePoint.properties fallback incase no props
DenisCarriere Jul 14, 2017
67e9071
Added Array of Features handling
DenisCarriere Jul 14, 2017
e7fb4a8
Update library to clusters-dbscan
DenisCarriere Jul 14, 2017
9bdd634
Rename folder to clusters-dbscan
DenisCarriere Jul 14, 2017
af57608
Update readme to clusters-dbscan
DenisCarriere Jul 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updates based on @stebogit comments
  • Loading branch information
DenisCarriere committed Jul 14, 2017
commit d3a3166a3697dba71ff0b65da21525930b86f5ec
9 changes: 3 additions & 6 deletions packages/turf-clusters-distance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ var convertDistance = helpers.convertDistance;
* @param {string} [units=kilometers] in which `maxDistance` is expressed, can be degrees, radians, miles, or kilometers
* @param {number} [minPoints=3] Minimum number of points to generate a single cluster, points will be excluded if the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

* cluster does not meet the minimum amounts of points.
* @returns {Object} an object containing a `points` FeatureCollection, the input points where each Point
* has given a `cluster` property with the cluster number it belongs, a `centroids` FeatureCollection of
* Points, collecting all the cluster centroids each with its own `cluster` property, and a `noise` FeatureCollection
* collecting (if any) the points not belonging to any cluster.
* @returns {FeatureCollection<Point>} each Point has two extra properties; `cluster` property with the cluster number it belongs &
* `dbscan` which is defines the which type of point it has been flagged as ('core'|'edge'|'noise').
* @example
* // create random points with random z-values in their properties
* var points = turf.random('point', 100, {
Expand Down Expand Up @@ -63,8 +61,7 @@ module.exports = function (points, maxDistance, units, minPoints) {
});

// handle noise points, if any
// Skip Noise if cluster is already associated
// This might be a slight deviation of DBSCAN (or a bug in the library)
// edges points are tagged by DBSCAN as both 'noise' and 'cluster' as they can "reach" less than 'minPoints' number of points
dbscan.noise.forEach(function (noiseId) {
var noisePoint = points.features[noiseId];
if (noisePoint.properties.cluster) noisePoint.properties.dbscan = 'edge';
Expand Down
15 changes: 5 additions & 10 deletions packages/turf-clusters-distance/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,12 @@ function colorize(clustered) {

featureEach(clustered, function (point) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change this to:

switch (point.properties.dbscan) {
    case 'core':
    case 'edge': {
        const coreColor = colours[point.properties.cluster];
        const edgeColor = chromatism.brightness(-20, colours[point.properties.cluster]).hex;
        point.properties['marker-color'] = (point.properties.dbscan === 'core') ? coreColor : edgeColor;
        point.properties['marker-size'] = 'small';
        points.push(point);
        break;
    }
    case 'noise': {
        point.properties['marker-color'] = '#AEAEAE';
        point.properties['marker-symbol'] = 'circle-stroked';
        point.properties['marker-size'] = 'medium';
        points.push(point);
    }
}

as edges are not really a major feature to highlight.
But it's just a finesse 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol Yep! Looks good.

I really like this Switch statement, makes it really easy to control those clustered points.

switch (point.properties.dbscan) {
case 'core': {
const color = colours[point.properties.cluster];
point.properties['marker-color'] = color;
point.properties['marker-size'] = 'small';
points.push(point);
break;
}
case 'core':
case 'edge': {
const color = chromatism.brightness(-15, colours[point.properties.cluster]).hex;
point.properties['marker-color'] = color;
point.properties['marker-symbol'] = 'cross';
const coreColor = colours[point.properties.cluster];
const edgeColor = chromatism.brightness(-20, colours[point.properties.cluster]).hex;
point.properties['marker-color'] = (point.properties.dbscan === 'core') ? coreColor : edgeColor;
point.properties['marker-size'] = 'small';
points.push(point);
break;
}
Expand Down
20 changes: 10 additions & 10 deletions packages/turf-clusters-distance/test/out/many-points.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@
"properties": {
"cluster": 11,
"dbscan": "edge",
"marker-color": "#00b348",
"marker-symbol": "cross"
"marker-color": "#00993e",
"marker-size": "small"
}
},
{
Expand Down Expand Up @@ -493,8 +493,8 @@
"properties": {
"cluster": 10,
"dbscan": "edge",
"marker-color": "#00b301",
"marker-symbol": "cross"
"marker-color": "#009901",
"marker-size": "small"
}
},
{
Expand Down Expand Up @@ -1437,8 +1437,8 @@
"properties": {
"cluster": 12,
"dbscan": "edge",
"marker-color": "#00b390",
"marker-symbol": "cross"
"marker-color": "#00997b",
"marker-size": "small"
}
},
{
Expand Down Expand Up @@ -3533,8 +3533,8 @@
"properties": {
"cluster": 13,
"dbscan": "edge",
"marker-color": "#008db3",
"marker-symbol": "cross"
"marker-color": "#007999",
"marker-size": "small"
}
},
{
Expand Down Expand Up @@ -5133,8 +5133,8 @@
"properties": {
"cluster": 13,
"dbscan": "edge",
"marker-color": "#008db3",
"marker-symbol": "cross"
"marker-color": "#007999",
"marker-size": "small"
}
},
{
Expand Down