If you want to cluster by "postal code", and you have the postal code in your records, then this is a simple "group by" scenario based on the postal code string and not something that requires any geospatial calculations. It would be the same grouping logic that could be used on any property in the records. Here is a simple example:
var records = [
{ id: 1, postalCode: "90210" },
{ id: 2, postalCode: "98052" },
{ id: 3, postalCode: "90210" },
{ id: 4, postalCode: "98052" },
{ id: 5, postalCode: "98052" },
{ id: 6, postalCode: "90210" },
{ id: 7, postalCode: "90210" },
];
var clusters = {}; //key = postalcCode, value = [ids]
//Group the records into clusters.
records.forEach(r => {
//See if a cluster already exists for the postal code.
if(clusters[r.postalCode]){
//Add the id to the list of items in the cluster.
clusters[r.postalCode].push(r.id);
} else {
//Create a new cluster and add the record id.
clusters[r.postalCode] = [r.id];
}
});
//Output the cluster information.
Object.keys(clusters).forEach(key => {
console.log(`Cluster for postal code ${key}, contains records: ${clusters[key]}`);
});
This would output:
Cluster for postal code 90210, contains records: 1,3,6,7
Cluster for postal code 98052, contains records: 2,4,5
If you don't have the postal code information, then you would either need to geocode your records ahead of time or retrieve the postal code boundaries that intersect with your records (ideally you would retrieve a unique postal code only once, then have other records check to see if they intersect).