PolygonVB - sindizzy/DSW GitHub Wiki

Sample code for creating a new polygon and calculating the area.

Imports DotSpatial.Geometries
Imports DotSpatial.Common

Private Sub btnPolygon_Click(sender As Object, e As EventArgs)
			'creates a new coordinate array
			Dim coords As Coordinate() = New Coordinate(9) {}
			'creates a random point variable
			Dim rnd As New Random()
			'Creates the center coordiante for the new polygon
			Dim center As New Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90)
			'a for loop that generates a new random X and Y value and feeds those values into the coordinate array
			For i As Integer = 0 To 9
				coords(i) = New Coordinate(center.X + Math.Cos((i * 2) * Math.PI / 18), center.Y + (i * 2) * Math.PI / 18)
			Next
			'creates a new polygon from the coordinate array
			Dim pg As New Polygon(coords)
			'new variable for the area of the polgyon
			Dim area As [Double](Double)
			area = pg.Area
			'displays the area of the polygon
			MessageBox.Show("The Area of the polygon is: " & area)
End Sub