1

I have two geometry variables and I want to find out if they intersect.

My first variable is called @orderBounds2.

DECLARE @orderBounds2 geography

I set it to a value

 set @orderBounds2 = 0xE6100000010405000000B81E85EB51F837C07CF2B0506B3A40C0B81E85EB51F837C01283C0CAA1955C4097900F7A363343401283C0CAA1955C4097900F7A363343407CF2B0506B3A40C0B81E85EB51F837C07CF2B0506B3A40C001000000020000000001000000FFFFFFFF0000000003;

I look to see what it is in text.

select   @orderBounds2.STAsText() --POLYGON ((-32.4564 -23.97, 114.338 -23.97, 114.338 38.4001, -32.4564 38.4001, -32.4564 -23.97))

My 2nd variable is @geo

declare @geo geography

I set it to a value.

select @geo = 0xE6100000010405000000A228D027F2C6514033F9669B1B034B40CDCCCCCCCC4C514033F9669B1B034B40CDCCCCCCCC4C51400000000000404F40A228D027F2C651400000000000404F40A228D027F2C6514033F9669B1B034B4001000000020000000001000000FFFFFFFF0000000003;

I look to see what it is in text.

select @geo.STAsText() --POLYGON ((54.02428 71.10853, 54.02428 69.2, 62.5 69.2, 62.5 71.10853, 54.02428 71.10853))

Now I want to find out if the polygons that my two variables represent intersect?

select @geo.STIntersects(@orderBounds2)  --= 1

The answer is 1, so yes the two areas do intersect.

However, I don't understand why . The polygons in text show (longitude.latitude) points and I cannot see how they intersect.

The 2nd Polygon is between latitude 69.2 and 71.1
The 1st Polygon is between latitude -23.4 and 38.4

Martin Smith
  • 438,706
  • 87
  • 741
  • 845
AlastairS
  • 11
  • 1
  • "I have two geometry variables" you don't, you have `geography` variables. Are you sure that's what you wanted? – Charlieface Sep 07 '22 at 22:17

1 Answers1

1

The edges of a geography polygon follow great circle arcs, so the segment from 114.338 38.4001 to -32.4564 38.4001 goes very far north.

  DECLARE @orderBounds2 geography = cast(0xE6100000010405000000B81E85EB51F837C07CF2B0506B3A40C0B81E85EB51F837C01283C0CAA1955C4097900F7A363343401283C0CAA1955C4097900F7A363343407CF2B0506B3A40C0B81E85EB51F837C07CF2B0506B3A40C001000000020000000001000000FFFFFFFF0000000003 as geography)
    declare @geo geography = cast( 0xE6100000010405000000A228D027F2C6514033F9669B1B034B40CDCCCCCCCC4C514033F9669B1B034B40CDCCCCCCCC4C51400000000000404F40A228D027F2C651400000000000404F40A228D027F2C6514033F9669B1B034B4001000000020000000001000000FFFFFFFF0000000003 as geography)
    
    select @orderBounds2
    union all
    select @geo

outputs

enter image description here

David Browne - Microsoft
  • 80,331
  • 6
  • 39
  • 67