Welcome to MapForums!

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

## Surface Area

This is a discussion on Surface Area within the MapPoint Desktop Discussion forums, part of the Map Forums category; Heres an interesting one that I'm having a lot of difficulty with (i'm sure you maths boffins out there will ...

1. Senior Member Green Belt
Join Date
Sep 2003
Posts
103

## Surface Area

Heres an interesting one that I'm having a lot of difficulty with (i'm sure you maths boffins out there will scoff at my strugling with such a simple problem ) .

Given a set of lat\lon co-ordinates for a closed polygon shape how can I work out the surface area of that shape in sq miles or sq km (or feet or meters or something sensible!).

I've searched the internet but the solutions I find are all looking for the ultimate in accuracy and far to complex for me to understand! I'm really just looking at this from a 'Flat Earth' scenario it doesn't need to be extremly accurate (unless its just as easy to make it more accurate of course).

2. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433
Hi,

No so simple but not really difficult also I try to explain. Take a pencil and draw a irregular polygon.

First step is, you take first point and draw a line to a second point skipping 1 point. What you now have is a triangle. Easy to calculated surface area of a triangle.

go on with a line to next point (skipping also just 1 point), do over and over again until you have the last resulting triangle.

3. Senior Member Green Belt
Join Date
Sep 2003
Posts
103
I think I understand what your saying and I may be missing something but for the map shown here http://img384.imageshack.us/img384/1...acearea3kt.jpg

would the triangle shown with the red line not be outside the surface area of the shape?

4. Junior Member White Belt
Join Date
Dec 2005
Posts
3

Here's how to do it with (x,y) vertices: http://astronomy.swin.edu.au/~pbourk...etry/polyarea/. This works for concave polygons like the one you showed. To use with (lat,long) vertices, I guess you could convert each vertex to an (x,y) in meters (or whatever), based on a local coordinate system, and assuming the world is locally flat. Clearly there are some approximation errors involved here.

5. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433
Hi,

I think I understand what your saying and I may be missing something but for the map shown here http://img384.imageshack.us/img384/1...acearea3kt.jpg
would the triangle shown with the red line not be outside the surface area of the shape?
Yes that's what I meant in 'no so simple'. There are some complications here and there, but that's what we programmers do like eh dont we ?

6. Senior Member Green Belt
Join Date
Sep 2003
Posts
103
Thanks for you help Wilfred, DrExcitement, it appears that this isn't as simple as I hoped (I didn't really think it would be to be honest!)

Looking at DrExcitements link it appears that this could be something I could use in my application if I had a way of converting Lat, Lon to some local Grid system, does anyone know of a way to do this?

7. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433
Hi,

Just use lat/long pairs. eg multiply them with 10000 or so and make them integers. Using 1/10000 will give you accuratie around 11 meter. 1 minute is exact 1 sea mile.

You will have (small) calculation errors because 1 minute in longitude is 1 seamile on the equator and less of course if go more distance away for it. You can correct it by multiply it by Cos(Latitude).

8. Junior Member White Belt
Join Date
Dec 2005
Posts
3
A slight refinement of the reply above is to first compute the mean (lat,long) of all your vertices. This will be the origin of your local coordinate system, called (lat0,long0). Now for each (lat,long) vertext, the corresponding (x,y) is y = pi*earth_radius_meters*(lat - lat0)/180 and x = pi*earth_radius_meters*cos(lat0)*(long - long0)/180. This assumes (lat,long) is in degrees. earth_radius_meters is approximately 1000.0 * 6371.01. This will give you coordinates in meters, so your area will be in square meters. If you want another square area unit, use the corresponding linear unit for the radius of the earth.

9. Senior Member Green Belt
Join Date
Sep 2003
Posts
103
Excellent, thank you both for your help, I should have the basis for a working algorithm now. I'll post a reply containing the class for any one else whos interested in this when i'm finished.

10. Senior Member Green Belt
Join Date
Sep 2003
Posts
103
Not really a class for doing this but heres how I implemented this in my code (VB .NET), should give someone some ideas towards writing a class of there own. In this I have my coordinates held in the table 'Shapes' each shape has a unique ID.

Code:
```    Imports System.Math

Private Function CalculateArea&#40;ByVal ID As String&#41; As String

Dim con As New System.Data.SqlClient.SqlConnection&#40;ConnString&#41;
con.Open&#40;&#41;
Dim cmd As New System.Data.SqlClient.SqlCommand
Dim ds As New DataSet
Dim dr As DataRow
Dim MyItem As ListViewItem
Dim xCoord&#40;&#41; As Double
Dim yCoord&#40;&#41; As Double
Dim n As Integer
Dim x, y, dist As Double

cmd = con.CreateCommand
cmd.CommandText = "SELECT * FROM Shapes WHERE ID = '" & ID & "' ORDER BY point"
cmd.CommandType = CommandType.Text
da.SelectCommand = cmd
da.Fill&#40;ds, "Coords"&#41;

ReDim xCoord&#40;ds.Tables&#40;"Coords"&#41;.Rows.Count&#41;
ReDim yCoord&#40;ds.Tables&#40;"Coords"&#41;.Rows.Count&#41;

For n = 0 To UBound&#40;xCoord&#41;
If n = UBound&#40;xCoord&#41; Then
xCoord&#40;n&#41; = xCoord&#40;0&#41;
Else
xCoord&#40;n&#41; = ds.Tables&#40;"Coords"&#41;.Rows&#40;n&#41;.Item&#40;"Lat"&#41;
End If

If n = UBound&#40;yCoord&#41; Then
yCoord&#40;n&#41; = yCoord&#40;0&#41;
Else
yCoord&#40;n&#41; = ds.Tables&#40;"Coords"&#41;.Rows&#40;n&#41;.Item&#40;"Lon"&#41;
End If

Next

For n = 0 To UBound&#40;xCoord&#41;
x += xCoord&#40;n&#41;
Next

x = x / &#40;UBound&#40;xCoord&#41; + 1&#41;

dist = DistanceFrom&#40;x, x, 0, 1&#41;

For n = 0 To UBound&#40;xCoord&#41;
xCoord&#40;n&#41; = xCoord&#40;n&#41; * 69.11
Next

For n = 0 To UBound&#40;yCoord&#41;
yCoord&#40;n&#41; = yCoord&#40;n&#41; * dist
Next
CalculateArea = Format&#40;AreaByCoordinates&#40;xCoord, yCoord&#41;, "#00.000 sqMiles"&#41;

End Function
Function AreaByCoordinates&#40;ByVal Xcoord&#40;&#41; As Double, ByVal Ycoord&#40;&#41; As Double&#41; As Double
Dim I As Long
Dim Xold As Double
Dim Yold As Double
Dim Yorig As Double
Dim ArrayUpBound As Long
Dim x, y As Double

ArrayUpBound = UBound&#40;Xcoord&#41;
Xold = Xcoord&#40;ArrayUpBound&#41;
Yorig = Ycoord&#40;ArrayUpBound&#41;
Yold = 0.0#

For I = LBound&#40;Xcoord&#41; To ArrayUpBound
x = Xcoord&#40;I&#41;
y = Ycoord&#40;I&#41; - Yorig
AreaByCoordinates = AreaByCoordinates + &#40;Xold - x&#41; * &#40;Yold + y&#41;
Xold = x
Yold = y
Next

AreaByCoordinates = Abs&#40;AreaByCoordinates&#41; / 2
End Function
Function DistanceFrom&#40;ByVal lat1 As Double, ByVal lat2 As Double, ByVal lon1 As Double, ByVal lon2 As Double&#41; As Double
Dim theta, dist As Double
theta = lon1 - lon2
dist = Acos&#40;dist&#41;
DistanceFrom = dist * 60 * 1.1515

End Function
Function deg2rad&#40;ByVal deg As Double&#41; As Double
deg2rad = CDbl&#40;deg * PI / 180&#41;
End Function
End Function```
I got the figure 69.11 from using this site

http://www.zodiacal.com/tools/lat_table.htm

I don't really have time to explain all of the details write now and this isn't entirely accurate due to the complications involved in making it so, but hopefully this should help anyone looking to do anything similar and perhaps they can expand on it and improve it and post there results back here. (Also if i've made any obvious mistakes could someone let me know !)