Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

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

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 10 of 10

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. #1
    Dazzer is offline 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. #2
    Wilfried is offline 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. #3
    Dazzer is offline 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. #4
    DrExcitement is offline Junior Member White Belt
    Join Date
    Dec 2005
    Posts
    3
    I've wondered about this, too, but I've never found an answer that talks about polygons with (lat,long) vertices.

    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. #5
    Wilfried is offline 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. #6
    Dazzer is offline 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. #7
    Wilfried is offline 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. #8
    DrExcitement is offline 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. #9
    Dazzer is offline 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. #10
    Dazzer is offline 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(ByVal ID As String) As String
    
            Dim con As New System.Data.SqlClient.SqlConnection(ConnString)
            con.Open()
            Dim cmd As New System.Data.SqlClient.SqlCommand
            Dim da As New System.Data.SqlClient.SqlDataAdapter
            Dim ds As New DataSet
            Dim dr As DataRow
            Dim MyItem As ListViewItem
            Dim xCoord() As Double
            Dim yCoord() 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(ds, "Coords")
    
            ReDim xCoord(ds.Tables("Coords").Rows.Count)
            ReDim yCoord(ds.Tables("Coords").Rows.Count)
    
            For n = 0 To UBound(xCoord)
                If n = UBound(xCoord) Then
                    xCoord(n) = xCoord(0)
                Else
                    xCoord(n) = ds.Tables("Coords").Rows(n).Item("Lat")
                End If
    
                If n = UBound(yCoord) Then
                    yCoord(n) = yCoord(0)
                Else
                    yCoord(n) = ds.Tables("Coords").Rows(n).Item("Lon")
                End If
    
            Next
    
            For n = 0 To UBound(xCoord)
                x += xCoord(n)
            Next
    
            x = x / (UBound(xCoord) + 1)
    
            dist = DistanceFrom(x, x, 0, 1)
    
            For n = 0 To UBound(xCoord)
                xCoord(n) = xCoord(n) * 69.11
            Next
    
            For n = 0 To UBound(yCoord)
                yCoord(n) = yCoord(n) * dist
            Next
            CalculateArea = Format(AreaByCoordinates(xCoord, yCoord), "#00.000 sqMiles")
    
        End Function
        Function AreaByCoordinates(ByVal Xcoord() As Double, ByVal Ycoord() As Double) 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(Xcoord)
            Xold = Xcoord(ArrayUpBound)
            Yorig = Ycoord(ArrayUpBound)
            Yold = 0.0#
    
            For I = LBound(Xcoord) To ArrayUpBound
                x = Xcoord(I)
                y = Ycoord(I) - Yorig
                AreaByCoordinates = AreaByCoordinates + (Xold - x) * (Yold + y)
                Xold = x
                Yold = y
            Next
    
            AreaByCoordinates = Abs(AreaByCoordinates) / 2
        End Function
        Function DistanceFrom(ByVal lat1 As Double, ByVal lat2 As Double, ByVal lon1 As Double, ByVal lon2 As Double) As Double
            Dim theta, dist As Double
            theta = lon1 - lon2
            dist = Sin(deg2rad(lat1)) * Sin(deg2rad(lat2)) + Cos(deg2rad(lat1)) * Cos(deg2rad(lat2)) * Cos(deg2rad(theta))
            dist = Acos(dist)
            dist = rad2deg(dist)
            DistanceFrom = dist * 60 * 1.1515
    
        End Function
        Function deg2rad(ByVal deg As Double) As Double
            deg2rad = CDbl(deg * PI / 180)
        End Function
        Function rad2deg(ByVal rad As Double) As Double
            rad2deg = CDbl(rad * 180 / PI)
        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 !)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Selected Area
    By amanuel in forum MapPoint Desktop Discussion
    Replies: 5
    Last Post: 10-12-2010, 07:55 PM
  2. How to use area code in MapPoint
    By dukester in forum MapPoint Desktop Discussion
    Replies: 4
    Last Post: 06-12-2006, 05:13 PM
  3. is an address within an area?
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 4
    Last Post: 02-23-2005, 02:51 PM
  4. How to get the 4 map area coordinates ?
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 01-22-2004, 02:44 PM
  5. Avoided Area?
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 09-25-2003, 01:46 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96