STContains Equivalent

  • Hi all,

    So I don't usually post my problems on these forums as I tend to prefer to find the answers myself but this one has me stumped and I'm not even sure what to put in to google to find the answer.

    Basically its all to do with geolocations, it would be nice if i could use SQL 2008 as this is all already done.

    What I have is a list of Northings and Eastings, together they make up a polygon (A) which serves as an area on a map. We've then got another set of locations which make up another polygon (B) which should be contained within the first area.

    Given that I'm using SQL 2005... How do I find out if polygon B is contained within polygon A?

  • shaun.turner (12/6/2010)


    Hi all,

    So I don't usually post my problems on these forums as I tend to prefer to find the answers myself but this one has me stumped and I'm not even sure what to put in to google to find the answer.

    Basically its all to do with geolocations, it would be nice if i could use SQL 2008 as this is all already done.

    What I have is a list of Northings and Eastings, together they make up a polygon (A) which serves as an area on a map. We've then got another set of locations which make up another polygon (B) which should be contained within the first area.

    Given that I'm using SQL 2005... How do I find out if polygon B is contained within polygon A?

    Since there are no geometric or geographic functions whatsoever in SQL Server 2005, you only have two options. First, pull the data (how are you storing it?) down to an application and have the app perform the functionality. Second, write a CLR function in VB or C# that does the compare and then deploy that to your database. There's really nothing else you can do because that type of functionality just doesn't exist in 2005.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • yeah I did think about CLR, but the guys here don't have CLR enabled and they are very funny about using anything aside from SQL itself. It took me months to convince them to use the SQL agent

    I was wondering if someone who knew something about euclidean geometry could write a function based on this

  • I hated geometry, so don't look at me. But even if someone could write the function in TSQL, they shouldn't. It's not something that the T-SQL language is going to be good at. Better to write it in CLR.

    BTW, this one screams upgrade or CLR. You should be able to convince them. I think you'd be better off just upgrading, but if you can't...

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply