I am using a combination of the measurement widget and Geometry Service for measuring distances and areas. I am getting different results from each method when trying to get the area of a polygon. I have read in earlier posts that I should project my polygon before doing the calculation. I added the project command and I am still getting different results from each method, measurement widget vs. geometry service. My map is in Web Mercator Auxiliary Sphere and my area of interest is in Washington State Plane North. I am using two functions to do the actual work and can see that the polygon is being projected. My issue is possibly the values that I am using in the project parameters... I have tried many different combinations for outSR and transformation. It appears that the measurement widget and geometry service area measures are off by the same amount no matter which combinations I have tried. The code for my two functions is below. GetAreaAndDistances is called when the final vertex in the polygon is drawn and getProjectedArea is called on geometry service project-complete.
What am I doing wrong? Should I be able to get the same area measurement from the measurement widget and the geometry service for the same polygon?
by the way, I am using 3.13.
Thanks,
Janice.
function GetAreaAndDistances(evtObj) { ///******************************************************************************************** ///******************************************************************************************** ///FROM:: https://developers.arcgis.com/en/javascript/jssamples/util_measurepoly.html ///******************************************************************************************** ///******************************************************************************************** console.debug(measureTool + ", In GetAreaAndDistances..."); require(["esri/geometry/geometryEngine", "esri/tasks/ProjectParameters", "esri/SpatialReference"], function (GeometryEngine, ProjectParameters, SpatialReference) { if (evtObj.geometry === undefined) { return; } try { var geometry = GeometryEngine.simplify(evtObj.geometry); var params = new ProjectParameters(); params.geometries = [geometry]; params.outSR = new SpatialReference(2855);//(102100);//(102748); params.transformForward = false;//true;//false; params.transformation = { wkid: 1515 }; esriConfig.defaults.geometryService.project(params); } catch (exp) { // alert("Invalid Geometry... "); console.debug("Invalid Geometry in GetAreaAndDistances..." + exp.Description); } }); } function getProjectedArea(evtObj) { console.debug(measureTool + ", In getProjectedArea..."); require(["esri/geometry/geometryEngine", "esri/tasks/AreasAndLengthsParameters"], function (GeometryEngine, AreasAndLengthsParameters) { if (evtObj.geometries[0] === undefined) { return; } try { var areasAndLengthParams = new AreasAndLengthsParameters(); var areaUnit = getUnits(area_units); var distUnit = getUnits(dist_units); //setup the parameters for the areas and lengths operation areasAndLengthParams.lengthUnit = distUnit; areasAndLengthParams.areaUnit = areaUnit; areasAndLengthParams.calculationType = "geodesic"; areasAndLengthParams.polygons = [evtObj.geometries[0]]; esriConfig.defaults.geometryService.areasAndLengths(areasAndLengthParams); } catch (exp) { // alert("Invalid Geometry... "); console.debug("Invalid Geometry in GetAreaAndDistances..." + exp.Description); } }); }
Janice,
Here is a link that might help explain things.
Measure dijit - Geodesic Vs Planar
It also looks to me that you are using a simplify on the geometry too. That would generalize the geometry and would change the perimeter and area.
Regards,
Tom
Thanks Tom...
I removed the simplify and changed geodesic to planar and also tried preserveShape. In both of these tests I still receive results different than the measurement widget. Is the measurement widget correct or the geometry service?
Janice,
There are also some new methods in the geometry engine for doing planar calculations. I have not tested the results, but it may save you a geometry service request and produce a better calculation result.
Here is the link:
esri/geometry/geometryEngine | API Reference | ArcGIS API for JavaScript
Regards,
Tom
From what I have been reading, it sounds like projecting the polygon to a local coordinate system will give me the best measurement results for area calculations. I suppose I am incorrect in believing that the measurement widget should return valid results... Well, I guess they are valid results, just in a messy spatial reference? Anyways, if anyone out there is using both the measurement widget and the geometry service and has input please jump in! For now, I will be hiding the results of the measurement widget and using the geometry service results.