Irregular Polygon Area

icb12

New Member
Joined
Sep 15, 2009
Messages
9
I have a need to calculate the area of an irregular polygon.
Using the area by coordinates method. Given that you have the x,y coordinates of every vertice.

The equation is as follows..
A=(1/2)[{(x1*y2)+(x2*y3)+(x3*y4)...(xN*y1)} - {(y1*x2)+(y2*x3)+(y3*x4)...(yN*x1)}]

Assuming the vertice coordinates are (x1,y1), (x2,y2),...(xN,YN)- listed in separate columns on sheet1

This is simple enough to do in excel when the polygon has just a few vertices.
But when the closed traverse (polygon) is huge with tons of vertices the equation becomes convoluted and a PITA.

I'd like to write a function in VB that would allow me to quickly and easily compute the area simply by selecting the coordinates I have entered on the sheet1.

This was suggested to me by someone more skilled than I... but I can't seem to make it work.
Public Function getArea(ByVal a As ListBox, ByVal b As ListBox)

' Make sure to add the first element to the end to close the polygon
a.Items.Add (a.Items(0))
b.Items.Add (b.Items(0))

Dim n, area, i
n = a.Items.Count

i = 0
area = 0

Do
area = (a.Items.Item(i) * b.Items.Item(i + 1) - a.Items.Item(i + 1) * b.Items.Item(i))

i = i + 1
Loop While i < n - 1

area = Math.Abs(area * 0.5)

' if you have a certain scale you can use this, or skip it
area = applyScale((9 / 64), area)

Return area
End Function
Any suggestions? On how to make the above work, or a better way?

I appreciate any and ALL assistance.

-Iain
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Would this formula work for a shape like the outline of the letter "L" or the letter "W"?

Hi
Welcome to the board

I don't see why it would not work. I don't see anything special in those 2 polygons.

Did you test it and got a bad result?

Please post your test.
 
Upvote 0
I used the following (GPS) coordinates (simplified). By my calculations, the area should be 480,000 sq m but the formula gives me an area of 800,000. This is an L shape where the top block is 400x400 (160,000 sq m) and the lower block is 800x400 (320,000 sq m).

PostEastingNorthing
CP15408005396000
DP15408005395600
DP25412005395600
CP25412005395200
CP35400005395200
CP45400005396000

<colgroup><col><col span="2"></colgroup><tbody>
</tbody>
 
Upvote 0
Hah! Never mind, I put in the wrong co-ordinates. All is good!

The Easting for CP3 and CP4 should be 540400.
 
Upvote 0
OK--This thread is awesome! I have a slightly different data set. My data is a "cloud" of XY data, so only some xy locations are on the exterior, and should be used for calculating the area. Any ideas on VB to find just the XY locations that represent the outer edge, ignoring interior data points to find the area?
 
Upvote 0

Forum statistics

Threads
1,215,325
Messages
6,124,252
Members
449,149
Latest member
mwdbActuary

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top