Polygon Measure Results are Not the Same - ESRI samples

3167
4
07-31-2012 07:14 AM
RobertMEIER
Occasional Contributor
I am trying to do a bit of simple area measuring using the geometryService.areasAndLengths and was not getting the expected result, so I started looking at the online samples and found the samples do not give the same result when measuring the same area.

These two samples:
http://help.arcgis.com/en/webapi/javascript/arcgis/demos/widget/widget_measurement.html

http://help.arcgis.com/en/webapi/javascript/arcgis/demos/util/util_measurepoly.html

If you go to this coordinate : 38.8776559269747,-94.75016940780633, which is in Olathe, KS, where most of the main thoroughfares are on square miles and measure a square mile you get 2 different results.

The Widget correctly measures a square mile as 1, the other using geometryService.areasAndLengths, measures a square mile to about 1.6 sqmi.

Why?

I posted on a similar thing in the Silverlight forum - http://forums.arcgis.com/threads/34484-Geometry-Service-Areas-and-Length

*** Edit - I went back and looked at my Silvelright code, I had to project the measure geometry from mercator to geographic then to Equal Area in order to get the correct measurement. Still the fact remains that the sample code using geometryService.areasAndLengths does not show any projecting and gives an incorrect result.

Since both JS and Silverlight use the same REST geometry service, is it an issue with the REST geometry service?

Any help is appreciated.

-bert
0 Kudos
4 Replies
RobertMEIER
Occasional Contributor
ok, to get the correct area mesurement using the areasAndLengths I had to first project the geometry to an equal area projection, code is below:

          var projPoly;
          var outSR = new esri.SpatialReference(54034);
          geometryService.project([geometry], outSR, function (projGeom) {
              projPoly = projGeom[0];
         
          dojo.connect(geometryService, "onAreasAndLengthsComplete", outputMeasureResults);
          var areasAndLengthParams = new esri.tasks.AreasAndLengthsParameters();

          areasAndLengthParams.areaUnit = eval("esri.tasks.GeometryService." + measureUnits);                        areasAndLengthParams.calculationType = "preserveShape";

          geometryService.simplify([projPoly], function (simplifiedGeometries) {
              areasAndLengthParams.polygons = simplifiedGeometries;
              geometryService.areasAndLengths(areasAndLengthParams);
          });
      });

Don't know if I should mark this as solved because the sample is still incorrect.
0 Kudos
JianHuang
Occasional Contributor III
Bert,

This was an issue on geometry service, which has been fixed at server 10.1. The latest geometry service has a parameter that you can specify the calculation type. Please check: http://sampleserver6.arcgisonline.com/arcgis/sdk/rest/index.html?areasandlengths.html
So that you don't have to project the polygon before calling the method by using the parameter preserveShape.
The measurement widget calculates the area on client without using geometry service.
0 Kudos
SRIKANTHSwarna
New Contributor
hi rwmeier,
        I also has the similar issue, In My app I draw a polygon using esri.toolbar.draw.polygon, after that i used the geometry service  areasAndLengths complete functionality to calculate the area of the polygon, It gave me the result, But the result is not accurate. if You already solved the issue could you please help me to get out from this issue.

Code: 

   dojo.connect(toolbar, "onDrawEnd", function(geometry) {
    if(geometry.type=="polygon"){
    //globals.map.graphics.clear();
             var lengthAndAreaParams = new esri.tasks.AreasAndLengthsParameters();
                             dojo.connect(geometryService, "onAreasAndLengthsComplete",results);
            lengthAndAreaParams .polygons = [geometry];
    lengthAndAreaParams .areaUnit = esri.tasks.GeometryService.UNIT_FOOT;
    lengthAndAreaParams .lengthUnit = esri.tasks.GeometryService.UNIT_FOOT;
    lengthAndAreaParams .geodesic = true;
    geometryService.areasAndLengths(lengthAndAreaParams );});



thanks,
sri
0 Kudos
RobertMEIER
Occasional Contributor
See the second post on this thread, I indicated that I solved the issue by projecting the geometry to an equal area projection before the AreaAndLengths calculation.. Here's the code:

var projPoly;
var outSR = new esri.SpatialReference(54034);
geometryService.project([geometry], outSR, function (projGeom) {
projPoly = projGeom[0];

dojo.connect(geometryService, "onAreasAndLengthsComplete", outputMeasureResults);
var areasAndLengthParams = new esri.tasks.AreasAndLengthsParameters();

areasAndLengthParams.areaUnit = eval("esri.tasks.GeometryService." + measureUnits); areasAndLengthParams.calculationType = "preserveShape";

geometryService.simplify([projPoly], function (simplifiedGeometries) {
areasAndLengthParams.polygons = simplifiedGeometries;
geometryService.areasAndLengths(areasAndLengthParams);
});
});
0 Kudos