Answered by:
Geography .STIntersects() incorrect if polygon is big
Question

Hi,
What is the reason when a polygon becomes large (width >= North America continent) then STIntersects() miss a point which is inside the polygon?
The test code below shows that a point is clearly defined within the boundaries of two polygons. And yet the big polygon fails to intersect with the point. Thanks very much in advance for any enlightment.
DECLARE @myPoint geography, @polySmall geography, @polyBIG geography
SET @myPoint = geography:arse('POINT(49.274138 123.098562)')
SET @polySmall = geography:arse('POLYGON((47.0 124.0, 47.0 122.0, 50.0 122.0, 50.0 124.0, 47.0 124.0))')
SET @polyBIG = geography:arse('POLYGON((47.0 155.0, 47.0 85.0, 50.0 85.0, 50.0 155.0, 47.0 155.0))')
SELECT @polySmall.STIntersects(@myPoint) AS Intersect_polySmall, @polyBIG.STIntersects(@myPoint) AS Intersect_polyBIG
Results:
Intersect_polySmall Intersect_polyBIG
1 0Wednesday, January 9, 2008 7:54 PM
Answers

Hi TiPi
Please remember that you are operating on a sphere... That means that the polygon, when it is big does not behave as a normal Euklidian rectangle but as a more complex shape that is impacted by the curvature of the earth.
If you plot them (or intersect them) you will see that the two polygons are not contained in each other. The smaller one is located to the south of the larger one.
Best regards
Michael
Wednesday, January 9, 2008 9:04 PM
All replies

Hi TiPi
Please remember that you are operating on a sphere... That means that the polygon, when it is big does not behave as a normal Euklidian rectangle but as a more complex shape that is impacted by the curvature of the earth.
If you plot them (or intersect them) you will see that the two polygons are not contained in each other. The smaller one is located to the south of the larger one.
Best regards
Michael
Wednesday, January 9, 2008 9:04 PM 
A good way to see what Michael is talking about is to use the STBuffer to expand the polygon slightly. In doing this it has to define more points around the boundary of the polygon.
The key thing to remember is that the lines of latitude are rings that are parallel to the equator. They do not define the shortest distance between two points. So the line from your points 47.0 155.0 to 47.0 85.0, does not follow the 47 latitude but actually arcs up to the ~ 52.5 latitude
Get Mortens spatial tool and plot the shapes. If you plot them as you have it looks like they overlap. However the tool does allow for the curve of the earth. create shape by using hte STBuffer method i.e.
, @PolyBig.STBuffer(1).STBuffer(1).ToString() and then plot it you will see who the shape is actually curved.
Thursday, January 10, 2008 5:11 PM 
Thursday, January 10, 2008 5:19 PM

Thank you very much for helping me out. A couple of more questions (and sorry in advance if thy sound silly).
"The key thing to remember is that the lines of latitude are rings that are parallel to the equator. They do not define the shortest distance between two points. So the line from your points 47.0 155.0 to 47.0 85.0, does not follow the 47 latitude but actually arcs up to the ~ 52.5 latitude"
I thought that coordinates expressed in Lat/Long would mean that the positions follow the angular coordinates. Which I interpret as "two points on the 47 degree latitude remain on the same ring, regardless of their longitude" and this also respect the earth curvature. The 47 degree lalitude ring is perfectly parallel to the equator. Therefore any point having a lalitude greater than 47 will be on the North of this line.
I really don't see why the line 47.0 155.0 to 47.0 85.0 should curve up to the 52.5 latitude. Why would the line stray that far in the North? It is not at all parallel to the equator.Thursday, January 10, 2008 11:25 PM 
If you have ever looked at the routes airplanes fly, they look a bit like rainbows rather than straight lines when shown on a 2D map. Simply put, the longer the route the more bend to the rainbow.
Look on the web for information on "Great Circle Routes". One site that has many useful formulas is
http://williams.best.vwh.net/avform.htmFriday, January 11, 2008 4:17 AM 
The key thing here is that just because your line starts at latitude 47 and ends on latitude 47 doesn't mean all the points on the line are one the latitude 47.
Pick up and orange or football or anything round and a piece of string and pick two points not on the equator. put the piece of string between the points.You will find that the shortest distance involves a line that curves up and is not parallel to the equator.
To get a line to follow the equator you will have to define lots of points on the same latitude i.e.
LINESTRING (47 0,47 1, 47 2,47 3 ......)
Friday, January 11, 2008 6:27 AM 
These forums need a way to attach images... See the plot of the polygons here: http://www.thehemingrays.com/sql/ForumPost.png if you don't have an orange or a football and a string handy :)
Friday, January 11, 2008 7:16 AM 
Ok thanks for the illustration. Now I see what all of you meant.
Then I misundestood the description of the geography class. In SQL Server 2008 Books Online (October 2007), section "Types of Spatial Data / Differences Between the Two Data Types"
"In the planar, or flatearth, system, measurements of distances and areas are given in the same unit of measurement as coordinates. Using the geometry data type, the distance between (2, 2) and (5, 6) is 5 units, regardless of the units used.
In the ellipsoidal, or roundearth system, coordinates are given in degrees of latitude and longitude. However, lengths and areas are usually measured in meters and square meters, though the measurement may depend on the spatial reference identifier (SRID) of the geography instance. The most common unit of measurement for the geography data type is meters."
I then expect that all geography objects would follow the earch curvature. Meaning that the line linking two points on latitude 47 is the latitude ring and not the straight line in the geometry sense.
Then this bring another question: I assume that if I draw a line using geography data type. I would get a straight line that would ignore the earth curvature. Is it true?
Or more pratically: Point1 is Vancouver/Canada, Point2 is in Paris/France. What does the value of @Point1.STDistance(@Point2) represent? the distance between two points at sea level 0? Or an imaginary straight line projected between these two points (the shortest distance in plane geometry).
How should I use the geography data type to make it to really follow the earth curvature?
Thanks very much for any help.Friday, January 11, 2008 4:56 PM 
It will be the shortest distance at sea level, following a great circle. Also see my blogpost on straight lines on a sphere: http://www.sharpgis.net/2008/01/12/StraightLinesOnASphere.aspxSaturday, January 12, 2008 8:43 AMAnswerer

Hi Morten,
Thank you very much for the detailed explanation found on your blog mentioned above. Now I really get it.Monday, January 14, 2008 4:38 PM