
I am using the following code to construct a polygon object and return the area. My question is what is the area units? i am using a polygon the size of a small town and the result is 0.00489008147093151. I am constructing using wgs84 lat/lng points. any
ideas?




I have followed up with all other reliant posts without avail.




if you put in lat/lon coordinates you will get a meaningless area computed from the degree values.
You need to transform your geometry to a projected coordinate system in order to get a reasonable result.
Hth FObermaier




Thank you FObermaier. I am new to dotspatial. I will see what i can learn regarding the projected coordinate used to construct the polygon. Any good examples i may leverage?



Nov 6, 2013 at 1:31 PM
Edited Nov 6, 2013 at 1:34 PM

I have added the a projected feature set and used it to create the polygon with the same result. Any suggestions?
Using t As New DataTable
Using myReader As SqlDataReader = sqlCmd.ExecuteReader()
t.Load(myReader)
End Using
'create a new coordinate array
Dim coords As Coordinate() = New Coordinate(t.Rows.Count  1) {}
Dim i As Integer = 0
For Each r As DataRow In t.Rows
coords(i) = New Coordinate(r("Latitude"), r("Longitude"))
i = i+1
Next
'create the featureset
Dim fs As New FeatureSet(FeatureType.Polygon)
Dim prjLatLng As ProjectionInfo = KnownCoordinateSystems.Geographic.World.WGS1984
fs.Projection = prjLatLng
fs.Features.Add(coords, FeatureType.Polygon)
'create a new polygon from the coordinate array
Dim pg As New Polygon(fs.Features(0).Coordinates)
'get the area of the polygon
retArea = pg.Area ' what is this area in?
End Using




you need to reproject it to a projected coordinate system. the one you assigned is geographic. sth Like
fs.Reproject(ProjectionInfo.FromEpsgCode("EPSG:31466"))
retArea = (IPolygon)fs.Features(0).Area



Nov 6, 2013 at 3:33 PM
Edited Nov 6, 2013 at 3:47 PM

FObermaiar, thank you for the reply!. I revised the code according to your instruction, it seems to be working! here is the working version: My only question is what are the engineering units of the results?
Using t As New DataTable
Using myReader As SqlDataReader = sqlCmd.ExecuteReader()
t.Load(myReader)
End Using
'create a new coordinate array
Dim coords As Coordinate() = New Coordinate(t.Rows.Count  1) {}
Dim i As Integer = 0
For Each r As DataRow In t.Rows
coords(i) = New Coordinate(r("Latitude"), r("Longitude"))
i += 1
Next
'create the featureset
Dim fs As New FeatureSet(FeatureType.Polygon)
Dim prjLatLng As ProjectionInfo = KnownCoordinateSystems.Geographic.World.WGS1984
fs.Projection = prjLatLng
fs.Features.Add(coords, FeatureType.Polygon)
'reproject grom geographic to projected coordinate system
fs.Reproject(KnownCoordinateSystems.Projected.NorthAmerica.NorthAmericaAlbersEqualAreaConic)
'create a new polygon from the reprojected coordinate array
Dim pg As New Polygon(fs.Features(0).Coordinates)
'get the area of the polygon
retArea = pg.Area
End Using
Thank you!



Nov 6, 2013 at 5:13 PM
Edited Nov 6, 2013 at 7:59 PM

IIRC the projection info object you use has a "Unit" property.
If it's 'Meter' property is ~0.33 you have some square feet.



Nov 6, 2013 at 6:44 PM
Edited Nov 6, 2013 at 6:45 PM

i am not finding this 'k' property in the projectioninfo class here:
Link to documentation
There is something called 'scalefactor' but it appears to be 1.0 in any case. Any suggestions?



Nov 6, 2013 at 7:49 PM
Edited Nov 6, 2013 at 7:59 PM

It is 'Unit.Meter', sorry. If you call ToProj4String() its value is described as 'to_meter'.
If it is 1.0 I suppose you have square meters.




Thank you for your help; i am graetful.
Here is my problem, each projection coordinate system results in different area results, but the scale and Unit.Meter remains 1.0 regardless of the projection used.
Any suggestions? Here is the code as of now:
Using t As New DataTable
Using myReader As SqlDataReader = sqlCmd.ExecuteReader()
t.Load(myReader)
End Using
'create a new coordinate array
Dim coords As Coordinate() = New Coordinate(t.Rows.Count  1) {}
Dim i As Integer = 0
For Each r As DataRow In t.Rows
coords(i) = New Coordinate(r("Latitude"), r("Longitude"))
i += 1
Next
'create the featureset
Dim fs As New FeatureSet(FeatureType.Polygon)
Dim prjLatLng As ProjectionInfo = KnownCoordinateSystems.Geographic.World.WGS1984
fs.Projection = prjLatLng
fs.Features.Add(coords, FeatureType.Polygon)
'reproject grom geographic to projected coordinate system
' Dim prjProjected As ProjectionInfo = KnownCoordinateSystems.Projected.NorthAmerica.NorthAmericaEquidistantConic
Dim prjProjected As ProjectionInfo = KnownCoordinateSystems.Projected.NorthAmerica.USAContiguousLambertConformalConic
fs.Reproject(prjProjected)
'create a new polygon from the reprojected coordinate array
Dim pg As New Polygon(fs.Features(0).Coordinates)
'get the area of the polygon
'mult area by scale
retArea = pg.Area * prjProjected.Unit.Meters
End Using
Thank you




You will get a different value for length and area depending on the projection you use. You need to pick that projection that suits your area of interest best to get the most accurate result.








okay, figured it out. has to be in the proper projection and you need to use the multiplier squared:
Using t As New DataTable
Using myReader As SqlDataReader = sqlCmd.ExecuteReader()
t.Load(myReader)
End Using
'create a new coordinate array
Dim coords As Coordinate() = New Coordinate(t.Rows.Count  1) {}
Dim i As Integer = 0
For Each r As DataRow In t.Rows
coords(i) = New Coordinate(r("Longitude"), r("Latitude"))
i += 1
Next
'create the featureset
Dim fs As New FeatureSet(FeatureType.Polygon)
Dim prjLatLng As ProjectionInfo = KnownCoordinateSystems.Geographic.World.WGS1984
fs.Projection = prjLatLng
fs.Features.Add(coords, FeatureType.Polygon)
'reproject grom geographic to projected coordinate system
Dim prjProjected As ProjectionInfo = KnownCoordinateSystems.Projected.StatePlaneNad1983Feet.NAD1983StatePlaneMassachusettsMainlandFIPS2001Feet
fs.Reproject(prjProjected)
'create a new polygon from the reprojected coordinate array
Dim pg As New Polygon(fs.Features(0).Coordinates)
'get the area of the polygon
'mult area by scale
retArea = pg.Area * Math.Pow(prjProjected.Unit.Meters, 2)
End Using




I'm not sure if this is the most "correct" way of doing it, but I calculated the area of a shape in Lat/Long using the code below. First I may an array of X/Y coordinates in the shape, then multiplied each one by .017453293 (0.017453293 converts
degrees to radians: 2pi/360). Then I looped through each of the point to find the area
'm2 because the starting point must be the same as the ending point
For j = 0 To numpoints  2
Area = Area + ((X(j + 1))  (X(j))) * ((Math.Sin(Y(j))) + (Math.Sin(Y(j + 1))))
Next
Then to chose which unit I wanted to display the area
'Example for Feet
AreaFt = Math.Abs(Area * 6378137 * 6378137 / 2) * 10.76391041671
This got me pretty close to the correct area, even though it is not absolutely exact.

