As far as I can tell, the aboce code calculates the weighted center. There is no guarantee that this is inside the polygon. For instance try it on a polygon shaped like a "C", or a ring with a hole in the center.
there are probably half a dozen reasons not to do it this way that Morten and Co. can point out, but doing it client-side using the extension method below works for me.
<Extension()> _ Public Function GetTruePolygonCenter(ByVal pgnPolygon As Polygon) As MapPoint Try Dim iNumberOfMapPoints As Integer = 0 Dim centroidX As Double = 0 Dim centroidY As Double = 0 For Each pc As PointCollection In pgnPolygon.Rings For Each mp As MapPoint In pc centroidX += mp.X centroidY += mp.Y iNumberOfMapPoints += 1 Next Next Return New MapPoint(centroidX / iNumberOfMapPoints, centroidY / iNumberOfMapPoints, pgnPolygon.SpatialReference) Catch ex As Exception Return Nothing End Try End Function
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.