views:

39

answers:

1

Hello,

I have a set P of 2D points that I could like to cluster in a 2D uniformly spaced grid, where each cell is length X.

I want to do this because I am trying to create a heat map, and I have way to much information so I am hoping by clustering the points into a uniformly spaced grid I can just report the final count of each grid.

Thanks!

if It makes any difference I am getting my information via SQL (the points) that are within a certain radius of a specified point first prior to subdivision.

A: 

Are you looking for something like this?

var result = from p in points
              group p by new { X = p.X / length, Y = p.Y / length } into g
              select new
              {
                  g.Key.X,
                  g.Key.Y,
                  Count = g.Count()
              };

I don't know if there's a way to take advantage of the order of points.

dtb
I don't really understand the code above. Could you break it down slightly so I can tell if it is helpful?
Setheron
@Setheron: It simply groups all points into their respective cell and then returns the count of points for each cell. (See also: [group clause](http://msdn.microsoft.com/en-us/library/bb384063.aspx))
dtb
so I am not using C# 3.0 :(
Setheron