locked
get all polygon neighbors RRS feed

  • Question

  • Hi Forum,

    how is it possible to get all neighbors of a Polygon? My Basic SQL query is

    Select [Name],[geom] From Table Where [Name]='Polygon1'

    So this returns the poygon called Polygon1. BUT this Polygon has neighbors. Is there a method that gives me all the neighbors of Polygon1? My first approach was to use the STBuffer, but I am sql rookie, so I really don´t know how the query it :-( Sorry for the easy question, but its a real problem for me .

    My second approach was:

    Declare @poly geography;
    set @poly = (Select [geom].STBuffer(10)
     FROM [database].[dbo].[TABLE]WHERE Name='Polygon1')
     
     Declare @all geography;
     set @all =(Select [geom]
     FROM [database].[dbo].[TABLE])
     
     Select * From database.dbo.TABLE WHERE @poly.STIntersects(geography::(@all,4326);
    But that query is full of errors....

    Thanks again to you all, I am thankful for every hint !

    regards,

    Thomas

    Thursday, September 30, 2010 1:56 PM

Answers

  • Hi there,

    Assuming that your neighbouring polygons have touching sides with Polygon1, then you can retrieve them using STIntersects (since "touching" is a kind of intersection):

    -- Retrieve the "master" polygon
    DECLARE @poly geography;
    SELECT @poly = geom
    FROM [database].[dbo].[TABLE] WHERE Name='Polygon1')
     
    -- Retrieve all polygons that intersect this polygon
    SELECT * From database.dbo.TABLE
    WHERE geom.STIntersects(@poly) = 1;
    
    


    Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
    • Marked as answer by Dru_MS Thursday, September 30, 2010 3:22 PM
    Thursday, September 30, 2010 3:13 PM
    Answerer

All replies

  • Hi there,

    Assuming that your neighbouring polygons have touching sides with Polygon1, then you can retrieve them using STIntersects (since "touching" is a kind of intersection):

    -- Retrieve the "master" polygon
    DECLARE @poly geography;
    SELECT @poly = geom
    FROM [database].[dbo].[TABLE] WHERE Name='Polygon1')
     
    -- Retrieve all polygons that intersect this polygon
    SELECT * From database.dbo.TABLE
    WHERE geom.STIntersects(@poly) = 1;
    
    


    Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
    • Marked as answer by Dru_MS Thursday, September 30, 2010 3:22 PM
    Thursday, September 30, 2010 3:13 PM
    Answerer
  • Thanks a lot ! I tried something similar but got polygons far away :-)

     

    THANK YOU!!!

    Thursday, September 30, 2010 3:23 PM