How to collect all polygons to MBR ?

Answered How to collect all polygons to MBR ?

  • Thursday, June 07, 2012 11:13 AM
     
     

    I am new to SQL spatial querys.

    I would like to know if i can write a query that automatically gives me the MBR of all polygons that are positioned in the same area without knowing that area in first place

    Consider it as a paragraph of words on a sheet of paper, i want to select only those polygons ( rectangle of each word) where the left, right, below and top neigbours ( other words) are within certain x,y distance ?

    I am an absolute beginner :)

    Thx !

All Replies

  • Thursday, June 07, 2012 2:18 PM
    Answerer
     
     Answered

    Hi,

    So you're trying to group a set of source polygons together into a number of discrete clusters, where each cluster contains a set of "close together" features (i.e. those that are "positioned in the same area")? Is that right?

    If so, it sounds like k-means clustering might be what you're after: http://en.wikipedia.org/wiki/K-means_clustering.

    SQL Server has no function to perform clustering out-of-the-box, but it's relatively easy to write a SQLCLR procedure that will do this. <plug>In fact, I demonstrate a k-means clustering algorithm in Chapter 13 of Pro Spatial with SQL Server 2012. That example uses a set of point data, but you could do the same by applying it to the centroid of each Polygon</plug>


    twitter: @alastaira blog: http://alastaira.wordpress.com/

    • Marked As Answer by TOMvanas Thursday, June 14, 2012 12:52 PM
    •  
  • Thursday, June 07, 2012 2:30 PM
     
     

    You are absolutely right ! I was hoping that SQL had an out of the box solution :)

    Do you have a script for this ?

    Thx !

  • Thursday, June 07, 2012 3:50 PM
    Answerer
     
     Answered
    Yes - let me just check with the publishers whether it's ok to reproduce.

    twitter: @alastaira blog: http://alastaira.wordpress.com/

  • Friday, June 08, 2012 6:57 AM
     
     

    It's ok , I have bought the ebook !

    Grtz,

    Tom