geodesicLengths returns NaN

784
4
09-06-2012 04:45 PM
BryanBaker
Occasional Contributor
I'm getting an invalid value (NaN) back from the esri.geometry.geodesicLengths function for certain lines. This only happens occasionally, and I haven't detected a pattern as to what about the path is triggering the error. Here's an example that displays the problem. I tried this with the 3.1 API.

function init() {
  var line = new esri.geometry.Polyline({"paths":[[[-113.3388907526918,53.6252478988518],[-113.27571936597303,53.57961406863708],[-113.27571936597303,53.57961406863708],[-113.27571936597303,53.566566774741844],[-113.28121253003553,53.53964401478653],[-113.30318518628555,53.519236579065456],[-113.32241126050428,53.50943751677841],[-113.34438391675431,53.50943751677841],[-113.36772986401994,53.51025419185318],[-113.3869559382387,53.51678702593175],[-113.41167517651995,53.53882790615631],[-113.41030188550432,53.560041617991864],[-113.40068884839496,53.58613620592375],[-113.35262366284805,53.62036091795674],[-113.3388907526918,53.6252478988518]]],"spatialReference":{"wkid":4326}});
 
  var lengths = esri.geometry.geodesicLengths([line], esri.Units.METERS);
  document.write("Measured length is: " + lengths[0]);
 }
 
 dojo.addOnLoad(init);


The above line is derived from a polygon so closes on itself, but other I've had this with other polylines that do not close on themselves.
0 Kudos
4 Replies
derekswingley1
Frequent Contributor
There's a duplicated vertex in your line which is causing the calculation to fail. Try this:
var line = new esri.geometry.polyline({
  "paths": [
    [
      [-113.3388907526918, 53.6252478988518],
      [-113.27571936597303, 53.57961406863708],
      // [-113.27571936597303, 53.57961406863708], // duplicate 
      [-113.27571936597303, 53.566566774741844],
      [-113.28121253003553, 53.53964401478653],
      [-113.30318518628555, 53.519236579065456],
      [-113.32241126050428, 53.50943751677841],
      [-113.34438391675431, 53.50943751677841],
      [-113.36772986401994, 53.51025419185318],
      [-113.3869559382387, 53.51678702593175],
      [-113.41167517651995, 53.53882790615631],
      [-113.41030188550432, 53.560041617991864],
      [-113.40068884839496, 53.58613620592375],
      [-113.35262366284805, 53.62036091795674],
      [-113.3388907526918, 53.6252478988518]
    ]
  ],
  "spatialreference": {
    "wkid": 4326
  }
});


On jsfiddle (length printed to the console): http://jsfiddle.net/nLpax/
0 Kudos
BryanBaker
Occasional Contributor
Thanks - that's odd about the duplicate vertex. That line was derived directly from the freehand polygon/polyline draw toolbars. So apparently those tools are occasionally producing duplicate points. I'll have to weed those out in code I suppose.
0 Kudos
shreyesshiv
New Contributor III
Well i am getting a similar error that Length is returning NaN.
The vertices of the line features are not duplicate but still the problem is arising.


1278799.757 2755664.841
1278726.952 2755624.480
1278643.215 2755578.058
1278639.237 2755578.200
1278638.736 2755578.218

the difference is only in the decimal places but they are different.

Can you tell me how to resolve this problem.


thank you
0 Kudos
JianHuang
Occasional Contributor III
The input has to be in GCS.

Well i am getting a similar error that Length is returning NaN.
The vertices of the line features are not duplicate but still the problem is arising.


1278799.757 2755664.841
1278726.952 2755624.480
1278643.215 2755578.058
1278639.237 2755578.200
1278638.736 2755578.218

the difference is only in the decimal places but they are different.

Can you tell me how to resolve this problem.


thank you
0 Kudos