Welcome to MapForums!

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

## Find center of a polygon

This is a discussion on Find center of a polygon within the MapPoint Desktop Discussion forums, part of the Map Forums category; It would be useful if that page had some diagrams. Averaging the cartesian coordinates is what we used school - ...

1. It would be useful if that page had some diagrams.

Averaging the cartesian coordinates is what we used school - perhaps it was with smaller polygons.

Seeing what they've written about the "rectangle and trapezium", I think I see what they are getting at. You might have lots of points at one end of the shape. A simple average will then bring the calculated centre over to that side - when it shouldn't.
Yes integration is the way to go. It is a long time since I did this, but it looks/sounds like the momentum calculations we used to do at Univ...
(but in 2d and without the velocity component)

Richard

2. Senior Member Green Belt
Join Date
Sep 2003
Posts
103
When I need to find the (approximate) centriod of a polygon I tend to do the following. Note it is very inaccurate and won't return the exact centroid, if you need it exact you would need to look at the stuff Winwead mentioned earlier with 3d Cartisian Coords.

Code:
```        Dim i As Integer
Dim x, y As Double
Dim pt As Integer
Dim intPoints As Integer
Dim objShape As MapPoint.Shape

For Each objShape In MyMap.Shapes

intPoints = UBound&#40;objShape.Vertices&#41;

x = 0
y = 0

For pt = 0 To intPoints
If pt = intPoints Then
Exit For
Else
CalcPos&#40;MyMap, objShape.Vertices&#40;pt&#41;.Location, dblLat, dblLon&#41;
x = x + dblLat
y = y + dblLon
End If
Next pt

Next
x = x / intPoints
y = y / intPoints

objloc = MyMap.GetLocation&#40;x, y, 100&#41;

For CalcPos code see the appropriate article (I can't remember which one it was now)

Page 2 of 2 First 12