files.zip (86.4 KB)
Hello. I’ve attached a geojson file containing a FeatureCollection of 4 MultiPolygons in WGS84 lat/long (EPSG 4326). This geojson validates with geojsonlint. When I calculate the area of those geometries in square meters (unprojected, or projected to UTM zone 13 (EPSG 32613)) using any of three methods 1) QGIS Field Calculator; 2) ArcMap Calculate Geometry; 3) PostGIS ST_AREA() - I get consistent results at least to several decimal places. But when I use MultipolygonShape.GetArea(), some features calculate fairly closely, while others differ substantially.
I’ve included screenshots of a table showing the areas calculated by QGIS and ArcGIS, and a screenshot from the Visual Studio debugger showing the area calculated after projecting to UTM Zone 13 (EPSG 32613). The second and 3rd features are the worst offenders, with area off by 1-5 sq meters.
Here is the function I use to calculate area. I hope you can tell me that I am doing something wrong?
public static double GetUtmAreaMeters(int sourceDataEPSGId, Feature sourceFeature)
{
BaseShape sourceShape = sourceFeature.GetShape();
PointShape centerShape = sourceShape.GetCenterPoint();
int utmzoneEpsg = Convert.ToInt32(32700.0 - Math.Round((45.0 + centerShape.Y) / 90.0) * 100.0 + Math.Round((183.0 + centerShape.X) / 6.0));
Proj4Projection projection = new Proj4Projection();
projection.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(sourceDataEPSGId);
projection.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(utmzoneEpsg);
projection.Open();
MultipolygonShape projectedShape = projection.ConvertToExternalProjection(sourceShape) as MultipolygonShape;
double area = projectedShape.GetArea(GeographyUnit.Meter, AreaUnit.SquareMeters);
return area;
}