|
I prefer using 8, as well, given the simplicity of the SQL the nice cut/paste capabilities of tables, and the less overhead of managing indexes. I reserve 9 for simply working with larger data sets. But if there are under 150,000 objects, I much prefer 8. So, here is the example you can try. I have a drawing called [D]. Here is how you get the distance from every point to every other point: SELECT a.id, b.id, Distance(a.id, b.id) AS dist FROM [D] AS a, [D] AS b WHERE a.id <> b.id now, what you want to do is find those points that are within a specified distance. So, I wrap that in a sub query like this: SELECT * FROM (SELECT a.id, b.id, Distance(a.id, b.id) AS dist FROM [D] AS a, [D] AS b WHERE a.id <> b.id ) WHERE dist < 50 now, if you want the number of points that are within the cluster you simply make a small change and add a GROUP BY: SELECT a.id, count(*) AS numpoints FROM (SELECT a.id, b.id, Distance(a.id, b.id) AS dist FROM [D] AS a, [D] AS b WHERE a.id <> b.id ) WHERE dist < 50 GROUP BY a.id finally, if you have two columns named [numneighbors] and [cluster], you can easily update that column with a slight modification to the above query: UPDATE (SELECT * FROM D, (SELECT a.id, count(*) AS numpts FROM [D] AS a, [D] AS b WHERE a.id <> b.id AND Distance(a.id, b.id) < 50 GROUP BY a.id) AS t1 WHERE d.id = t1.id) SET cluster = 1, numneighbors = numpts So, this last query is all you need. I like this because you aren't creating artifacts like buffers along the way. I also love how 8 handles updates - it's non standard SQL, but it makes things super convenient. If you want more help, feel free to contact me.
|