This project is read-only.
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)
			'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)
			'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] = pg.Area
		Catch ex As Exception
		End Try
	End Sub

Last edited Jul 13, 2010 at 3:39 PM by AlamoMan, version 3