PolygonAreaVB - sindizzy/DSW GitHub Wiki
Sample code demonstrating how to calculate the area of a polygon.
Imports DotSpatial.Geometries
Imports DotSpatial.Topology.Geometries
Private Sub btnArea_Click(sender As Object, e As EventArgs)
Try
'Creates a new array of coordinates
Dim coords As Coordinate() = New Coordinate(19) {}
'Creates a random number generator
Dim rnd As New Random()
'Createa a center point for the polygon
Dim center As New Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90)
'A For Loop that will randomly create coordinates and feeds the coordinates into the array of coordiantes
For i As Integer = 0 To 18
coords(i) = New Coordinate(center.X + Math.Cos((i * 10) * Math.PI / 10), center.Y + (i * 10) * Math.PI / 10)
Next
'Set the last coordinate equal to the first coordinate in the array, thus 'closing' the polygon
coords(19) = New Coordinate(coords(0).X, coords(0).Y)
'Creates a new polygon from the coordinate array
Dim pg As New Polygon(coords)
'Determines that area of the polygon
Dim area As [Double](Double) = pg.Area
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub