Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4026958
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:02:13+00:00 2026-05-20T11:02:13+00:00

I am using SQL 2008 Geography datatype for a project that deals with mapping

  • 0

I am using SQL 2008 Geography datatype for a project that deals with mapping out some areas. I need to check to make sure a smaller area is fully within the bounds of a larger area. With the Geometry datatype I could simply use .STWithin().

I would simply make the polygon’s geometry datatypes as well as geography, but I’m not sure if using a polygon that was mapped on geography coordinants will work as expected if used as a simple geometry type.

Is there any way to do something like .STWithin() on a geography datatype?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:02:13+00:00Added an answer on May 20, 2026 at 11:02 am

    Well, this isn’t an approach as clean as using STWithin, but you could do it using “STDifference”. I’ve prepared a small example:

    Basically there’s a large rectangle which serves as the container. There’s also two rectangles, “inside” and “outside”, where the first one is fully contained on the “container” and the second one only partially.

    The idea is just to check if the STDifference between the child and the parent has any points (the trick is in the direction of the call).

    declare @container geography;
    declare @inside geography;
    declare @outside geography;
    
    select @container = geography::STGeomFromText('POLYGON((-10 10, -10 0, 0 0, 0 10, -10 10))', 4326);  -- large rectangle (container)
    
    select @inside = geography::STGeomFromText('POLYGON((-9 9, -9 1, -1 1, -1 9, -9 9))', 4326); -- smaller rectangle (fully contained)
    
    select @outside = geography::STGeomFromText('POLYGON((-9 9, -9 1, 2 1, 2 9, -9 9))', 4326); -- smaller rectangle (partially contained)
    
    select @inside.STDifference(@container).STNumPoints() as [Points Outside Container] -- returns 0
    
    select @outside.STDifference(@container).STNumPoints() as [Points Outside Container] -- returns > 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using: SQL Server 2008 R2 I'd like to write a query that will select
I'm new to using SQL Server 2008 DB Project's in VS 2010. I found
I've got a database that is mirrored using SQL 2008 Mirroring. I have a
Using SQL Server 2008... I'm having some troubles in trying to order my rows
Using SQL Server 2008: assuming I have a valid geography object geog1 , converting
Using Microsoft SQL 2008 I have a loop that should grab data from each
Using SQL Server 2008, I need to select this XML into a Table. I
Using SQL Server 2008, is there a way to allow inserts to a table
I'm using SQL Server 2008 with Advanced Services on my Vista Home Premium. I'd
I'm using SQL Server 2008 Management studio viewing a 2005 server and have just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.