Azure SQL has a hemisphere limitation where it errors on any geography having an envelope angle greater than 90 degrees.

My coworker wants to set up some detection in the web server to catch such instances before they hit the database. How can envelope angle be calculated from a series of coordinates that define a polygon or multipolygon?

  • Besides just calculating a min/max of x (lon) values? – Vince May 29 '14 at 15:48
  • @Vince Does longitude alone define envelope angle? (I'm having a hard time even finding a good definition of envelope angle.) From my tests with a simple small rectangle, the envelope angle is affected by the latitude of the points as well. – Mike Asdf May 29 '14 at 17:24
  • Latitude delta can't exceed 180* – Vince May 29 '14 at 17:36
  • Shouldn't this question be: "what is an envelope angle?"? – Martin F May 29 '14 at 18:58
  • @martinf I thought it was the maximal angle between any two points in the shape(s), but Vince's comments about only considering longitudes made me second-guess myself. Apparently we were both wrong. – Mike Asdf May 29 '14 at 19:07

I found a note on Microsoft SQL Azure (see Note 4.4) that stated that the hemisphere limitation is the same as Microsoft SQL Server 2008. That led to a blog post on how to calculate an envelope angle and several examples of supported/unsupported polygons.

Do I understand it well enough to reproduce here? Nope. However, there's a function, EnvelopeAngle that will calculate it.

The writer, Isaac Kunen, describes it as

"it is the maximum angle from the center to any of the points in the figure, yielding a minimal cap with that center. The center, however, is determined by summing the vectors from the center of the globe to each vertex in the figure, essentially averaging the vertices."

  • Blog post link is broken fyi. Also, the EnvelopeAngle function can't be called if the geography object can't be instantiated in the first place because it exceeds the limit. – Mike Asdf May 29 '14 at 19:06
  • But yeah, the MSDN documentation for EnvelopeCenter just helped educate me on what the heck it's doing: EnvelopeCenter and EnvelopeAngle define a circle that encompasses all of the shape(s) (possibly not a minimal circle). – Mike Asdf May 29 '14 at 19:06
  • Fixed the blog post link! I don't know how I managed that one. – mkennedy May 29 '14 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.