sql-servergeospatialsqlgeometry

Corners from a SQLGeometry


I used the envelope function on my geometry shape to get this:

POLYGON ((-179.231086 51.175092, 179.859681 51.175092, 179.859681 71.441059, -179.231086 71.441059, -179.231086 51.175092))

Is there a built-in function that will allow me to get the North-East and South-West corners from that rectangle?


Solution

  • Since you're using an envelope, it will be a box that's aligned to the axes. It looks to me as though it starts enumerating the corners at the SE and goes counter-clockwise. So, we just need to grab the 1st and 3rd points.

    declare @g geometry = geometry::STGeomFromText('POLYGON ((-179.231086 51.175092, 179.859681 51.175092, 179.859681 71.441059, -179.231086 71.441059, -179.231086 51.175092))', 0);
    select @g.STPointN(1) as [SW], @g.STPointN(3) as [NE]