If you’re using GMap.NET to add maps to your .NET application, then the time may come when you want to calculate the area of a polygon on your map. In my case, I have an application that allows users to actually create polygons using a GMap.NET control, by placing and connecting markers to shape their […]

If you’re using GMap.NET to add maps to your .NET application, then the time may come when you want to calculate the area of a polygon on your map. In my case, I have an application that allows users to actually create polygons using a GMap.NET control, by placing and connecting markers to shape their polygon. Since the map system is used to indicate the limits of an area occupied by a rural community, it’s necessary to calculate how many hectares the delimited area occupies.

Google Maps actually provides a function in its API to calculate polygon areas:

Even so, unfortunately GMap.NET does not offer access to this API. Moreover, your GMap.NET control may be configured to work with a different map provider from Google Maps, like Bing. Consequently, you’ll have to implement your own polygon area calculation algorithms. Luckily, this is not all that complicated, and algorithms are available on the net.

Here’s my approach.

  • Assuming that you have a list of PointLatLng values that form the polygon…
  • For each PointLatLng value, create a new value with the latitude and longitude values converted to meters.
  • Calculate the area of the polygon using this algorithm.

In code:

Comments

4 4 Responses to “GMap.NET Tutorial: Calculating the area of a polygon on the map”
  1. YG says:

    hello
    I’d like without GMap.Net information balloons can be put, if the clip in the polygon to show me the area of the polygon

  2. Risky says:

    I don’t know why its giving me double value of area.

    So suppose I built a square having 25Metre length as one side, then it gives me area of 1300~ Sq. Metre. It should be 625 sq. Metre

  3. Martin Kirk says:

    this algorithm is shit… unless you are measuring a polygon on a 2D surface.
    use this one instead, which is very accurate !
    http://stackoverflow.com/questions/1340223/calculating-area-enclosed-by-arbitrary-polygon-on-earths-surface

  4. Martin Kirk says:

    private double area(ArrayList lats,ArrayList lons)
    {
    double sum=0;
    double prevcolat=0;
    double prevaz=0;
    double colat0=0;
    double az0=0;
    for (int i=0;i=90)
    {
    az=0;
    }
    else if (lats.get(i)0 && i<lats.size())
    {
    sum=sum+(1-Math.cos(prevcolat + (colat-prevcolat)/2))*Math.PI*((Math.abs(az-prevaz)/Math.PI)-2*Math.ceil(((Math.abs(az-prevaz)/Math.PI)-1)/2))* Math.signum(az-prevaz);
    }
    prevcolat=colat;
    prevaz=az;
    }
    sum=sum+(1-Math.cos(prevcolat + (colat0-prevcolat)/2))*(az0-prevaz);
    return 5.10072E14* Math.min(Math.abs(sum)/4/Math.PI,1-Math.abs(sum)/4/Math.PI);
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">