-
Notifications
You must be signed in to change notification settings - Fork 944
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
New module @turf/clusters #787
Conversation
ooo this looks nifty @stebogit |
|
update typescript definition
|
added test with properties; updated bench, index.d.ts and types;
@DenisCarriere I replaced |
The more I think about it the more I believe this should be called 'clusters', since it's returning (and really expected to return) multiple clusters. The majority of Turf modules are singular because they deal with or generate a singular "thing", but few of them do return multiple elements and they have plural names, like |
👍 Ok that works, we can name it |
That's great, yea it was really slow before... I'm glad it's a lot faster now |
packages/turf-cluster/index.js
Outdated
numberOfClusters = numberOfClusters || Math.round(Math.sqrt(count / 2)); | ||
|
||
// collect points coordinates | ||
var data = featureReduce(points, function (prevValue, currentFeature) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using coordEach
makes it about ~30-80% faster.
// collect points coordinates
var data = [];
coordEach(points, function (coord) {
data.push(coord);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 good to know! I still don't master these methods 😕
|
@DenisCarriere I added the validation on |
@stebogit 👍 Looks good! |
Awesome, I've been waiting this for sooooo long. |
We should be pushing a new minor release soon with all these new modules being merged in the past week. |
What about the complexity on adding a EDIT: this involves the ability to "switch" clustering algorithm, keeping same API |
@cyrilchapon I'm not an expert in clustering, even less in clustering algorithms, however it seems to me an algo requiring a |
@stebogit yep.. I'm not an expert too in custering algos, but it seems indeed that it would be a very different algorithm. Speaking of API, I would be suggesting something like var clusters = require('@turf/clusters')
var points = // featurecollection of points
//kmeans strategy
var options = {
numberOfClusters: 4
}
var kmeansClustered = clusters(clusters.consts.algorithms.KMEANS, points, options)
//OR
//maxDistance strategy
var options = {
maxDistance: 3,
maxDistanceUnit: 'km'
}
var kmeansClustered = clusters(clusters.consts.algorithms.SOMENAME, points, options) or maybe var clusters = require('@turf/clusters')
var points = // featurecollection of points
//kmeans strategy
var numberOfClusters = 4
var kmeansClustered = clusters.kmeans(points, numberOfClusters)
//OR
//maxDistance strategy
var maxDistance = 3
var maxDistanceUnit = 'km'
var kmeansClustered = clusters.somename(points, maxDistance, maxDistanceUnit) But I'm not able to implement such a thing |
Both strategies shouldn't be implemented in the same module, they should be separate modules with unique names. A good to read blog post from @mourner https://www.mapbox.com/blog/supercluster/ about Clustering.
Another good library built by @mourner is |
First draft of
@turf/cluster
, Ref: #33Uses
clusters
for simplicity, but there might be a faster/better implementation.Not sure if the output is ok, I tried to follow @tmcw's suggestion.
Open to suggestions and further testing.