# Area as it appears on a Bing map?

• ### Question

• I'm trying to figure out areas in .Net. I've been using the SqlTypes.dll but, when it gets right down to the details, I'm not precisely sure what it is really calculating.

To do my checking, I've been using a pretty large rectangle covering 49 to 54 north degrees latitude and 100 to 118 west degrees longitude.  If I plug this in to SqlTypes using WGS 84, I get an area of 226,213 square miles.  Great, but what did I actually calculate?  On my map control, that bottom line sits right on the US/Canada border.  But is the calculated rectangle following that, too, or is it using the great circle that bends well to the north?

To find out, I tried adding a couple more points along the southern border.  On my map, it looks exactly the same.  (It looks the same on Google Earth, too.)  However, the area jumps up to 277,866 square miles!  So I expect it's using the great circles.  That's sensible mathematically but it doesn't match what my users are seeing on the map.

I also found a formula in a math forum that gives the formula as (pi/180)R^2 |sin(lat1)-sin(lat2)| |lon1-lon2|.  When I use that, though, I come up with an area of 267,411 square miles.  That's nice as far as it goes but I'm calculating things much more complicated than a simple rectangle.

Is there a way to tell SQL (or SqlTypes in this case) to calculate the area as it appears on my Bing map?

Wednesday, April 22, 2020 3:56 PM

• I think I've got it! The key was something called the NETGeographicLib which has a way to calculate areas based on a polygon with Rhumb line borders.  Instead of corresponding to the shortest distance along the surface, they are lines of a constant heading.  When I do the calculation using that:

```        Dim earth As New NETGeographicLib.Rhumb(3959, 0, False)
Dim PolyArea = New NETGeographicLib.PolygonAreaRhumb(earth, False)
With PolyArea
End With

Dim perimeter, area As Double
PolyArea.Compute(False, False, perimeter, area)```

then I get exactly the answer I was expecting.  Remove the points for -113 and -106 and I still get exactly the same answer.  (Note the "earth" variable is actually making the numbers less accurate as they force Earth to be treated as a perfect sphere.)

So now my only confusion is: why was this so hard?  I can't be the only person trying to figure out large areas drawn on a Mercator-style projection.  Many political borders are drawn along lines of latitude (e.g. most of Kansas' north border is 40 degrees north).  Am I understanding the problem wrong?

• Marked as answer by Tuesday, April 28, 2020 6:30 PM
Tuesday, April 28, 2020 6:29 PM

### All replies

• Hi Zloth X,

https://stackoverflow.com/questions/28241218/polygon-area-in-bing-maps

best regards,
Cathy

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to  MSDN Support, feel free to contact MSDNFSF@microsoft.com

Thursday, April 23, 2020 8:39 AM
• I had to modify that a little. It would give an index out of range error as is so, when the last point comes around, I use the 0th entry instead of the i+1 entry.

That results in 265559 and 277190 square miles for 4 and 6 point polygon's respectively.  Still quite a bit different for polygons that, on the map, appear the same.

Edit:  The code I used was the following:

```            Dim nRickysArea As Double
For i = 0 To Poly.Locations.Count - 1
Dim Loc1 = Poly.Locations(i)
Dim nNext = i + 1
If nNext = Poly.Locations.Count Then nNext = 0
Dim Loc2 = Poly.Locations(nNext)

nRickysArea += Math.Atan(
Math.Tan(Math.PI / 180 * (Loc2.Longitude - Loc1.Longitude) / 2) *
Math.Sin(Math.PI / 180 * (Loc2.Latitude + Loc1.Latitude) / 2) /
Math.Cos(Math.PI / 180 * (Loc2.Latitude - Loc1.Latitude) / 2))
Next
If nRickysArea < 0 Then nRickysArea = -nRickysArea

• Edited by Thursday, April 23, 2020 4:24 PM added code snip
Thursday, April 23, 2020 4:21 PM
• I think I've got it! The key was something called the NETGeographicLib which has a way to calculate areas based on a polygon with Rhumb line borders.  Instead of corresponding to the shortest distance along the surface, they are lines of a constant heading.  When I do the calculation using that:

```        Dim earth As New NETGeographicLib.Rhumb(3959, 0, False)
Dim PolyArea = New NETGeographicLib.PolygonAreaRhumb(earth, False)
With PolyArea