Area calculation in planar with WebMercator polygon

812
5
11-23-2021 06:02 AM
JamesCrandall
MVP Frequent Contributor

JS 3.x

Before I got too far into this, wondering if anyone can point example of calculating more accurate acreage of input geometry of a web mercator aux sphere defined feature service?  I am currently determining acreage value calculations with  this function that implements esri.geometry.geodesicAreas but we see a discrepancy in values when we use ArcGIS Desktop and apply a planar projection to the same boundary.

getAcreageValueFromPolygon: function (geom) {
			  
			  var geometryService = new GeometryService("https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
			  var geographicGeometries = [];
			  //if self intersecting, simplify using geometry service
			  if (esri.geometry.polygonSelfIntersecting(geom)) {
				  //if self intersecting, simplify using geometry service
				  geometryService.simplify([geom], function (simplifiedGeometries) {
					  dojo.forEach(simplifiedGeometries, function (simplifiedGeometry, idx) {
						  geographicGeometries.push(esri.geometry.webMercatorToGeographic(simplifiedGeometry));
					  });
					  var areas = esri.geometry.geodesicAreas(geographicGeometries, esri.Units.ACRES);
					  acrevalue = new Number(areas[0]);
					  acrevalue = parseFloat(acrevalue.toPrecision(3));
				  });
			  }
			  else {
				  geographicGeometries.push(esri.geometry.webMercatorToGeographic(geom));
				  var areas = esri.geometry.geodesicAreas(geographicGeometries, esri.Units.ACRES);

				  acrevalue = new Number(areas[0]);
				  acrevalue = acrevalue.toPrecision(3);
			  }			  
			  return acrevalue
		  },

 

I think I'm simply looking for examples of applying a State Plane projection to the input geometry and calling planarAreas() instead.

0 Kudos
5 Replies
JamesCrandall
MVP Frequent Contributor

Init attempt shows odd results.  

 

WKID: 102658

When feature class is imported into an FGDB and projection of wkid referenced above is applied, the area is quite different from when I implement:

 

 

var sr = new SpatialReference({ wkid: 102658 }); //102100 102658  102258 3857 2881 https://spatialreference.org/ref/esri/102258/				  
				  geom.setSpatialReference(sr);
				  sqFt = geometryEngine.planarArea(geom, "square-feet").toPrecision(7);
				  console.log('sqFt: ' + sqFt)

Areas calculated:

1. ArcGIS Desktop 10.8.1:  61133457.122888

2. planarArea() Javascript:  7273987.555021531

0 Kudos
JamesCrandall
MVP Frequent Contributor

Last attempt with cleaned up compare checker.  Results in console:

 

sqFtGeodesic: 61138987.116298884

sqFtPlanar: 7273987.501667344

 

Code:

				  geographicGeometries.push(esri.geometry.webMercatorToGeographic(geom));				  
				  sqFtGeodesic = esri.geometry.geodesicAreas(geographicGeometries, esri.Units.SQUARE_FEET);
				  console.log('sqFtGeodesic: ' + sqFtGeodesic)

				  var sr = new SpatialReference({ wkid: 102658 }); //102100 102658  102258 3857 2881 https://spatialreference.org/ref/esri/102258/
				  geom.setSpatialReference(sr);
				  sqFtPlanar = geometryEngine.planarArea(geom, "square-feet");
				  console.log('sqFtPlanar: ' + sqFtPlanar)

 

0 Kudos
DanPatterson
MVP Esteemed Contributor

Just want to be clear. 

None of the examples above are for Web-mercator geometry right? they are for the Florida state plane? (projected).  I just see a lot of queries about area and length calculations being "off" when using web mercator sourced data


... sort of retired...
0 Kudos
JamesCrandall
MVP Frequent Contributor

All of our map services are sourced as Web Mercator Aux Sphere projection.  We're comparing against the same polygon that was projected to StatePlane in Pro and I wanted to get rid of the discrepancy that geodesicArea() produced.

 

The thing is .geodesicArea() returns very close to what we see when calculating the same polygon in Desktop/Pro that's been projected to HARN NAD83 SP Florida East 901.  It's off by a couple of acres:

 

geodesicArea(): 1400ac

Harn NAD 83: 1403ac

 

I am simply attempting to reproduce these results in the web application and was hopeful that using .planarArea() would produce the result above.

0 Kudos
KarenRobine1
New Contributor III

OK, I think I pulled this off. I did this some years ago, so bare with me.  

For Planar setting, you have to use areasandlengthsparameters. Here's my example (sorry, codes not formatted right when I dropped it in..).  

//https://developers.arcgis.com/javascript/3/jsapi/areasandlengthsparameters-amd.html
//https://developers.arcgis.com/javascript/3/jsapi/areasandlengthsparameters-amd.html#calculationtype
_getAreasAndLengthsParameters: function(geomArr) {
//https://community.esri.com/message/274372?commentID=274372#comment-274372
//https://community.esri.com/thread/79094
var areaLen = (this._isGeometryLine) ?
new LengthsParameters():
new AreasAndLengthsParameters();
if (this._isGeometryLine) {
areaLen.lengthUnit = GeometryService.UNIT_FOOT; //TODO GeometryService.UNIT_METER=9001 GeometryService.UNIT_FOOT = 9002
areaLen.polylines = geomArr;
} else {
areaLen.lengthUnit = GeometryService.UNIT_METER; //TODO GeometryService.UNIT_METER=9001 GeometryService.UNIT_FOOT = 9002
areaLen.areaUnit = GeometryService.UNIT_ACRES;
areaLen.polygons = geomArr;
}

areaLen.calculationType = this._getAcreageCalculationType(); //preserveShape, geodesic, planar
//console.log("_getAreasAndLengthsParameters() areaLen = ", areaLen);
return areaLen;
},

and how I  set it right before I used the geometry service to calculate it....

var areaLen = this._getAreasAndLengthsParameters(resultGeom);

this._geomService.areasAndLengths(areaLen, lang.hitch(this, this._onAreasLengthsFinish), lang.hitch(this, this._onError, "areas"));

Also, fyi: I noticed that the acreages came our slightly different when calculating it via Pro vs Desktop. My calculations matched one and not the other (I can't remember which one)..