Select to view content in your preferred language

Geometry Service Geodesic Distance/WrapAround180 Problem

1298
10
12-20-2011 10:32 AM
MarkHoover
Frequent Contributor
We don't use the native Measurement widget and instead we have built our own, which leverages the GeometryService's Distance method, as seen below:

distParams.geometry1 = this.inputPoints[this.inputPoints.length - 2];
            distParams.geometry2 = this.inputPoints[this.inputPoints.length - 1];
            distParams.geodesic = true;

            //draw a polyline to connect the input points
            var polyline = new esri.geometry.Polyline(map.spatialReference);
            polyline.addPath([distParams.geometry1, distParams.geometry2]);
            this.measureGraphics.add(new esri.Graphic(polyline, polylineSymbol));
            //Calculate the geodesic distance 
            this.geometryService.distance(distParams, dojo.hitch(this, this.calculateDistance));


The problem is, with WrapAround180 set to true for the app, any measurement across the International Date Line returns "null" instead of a mileage.  For example, if I measure from LA to China, across the Pacific ocean, I get null.  However, if I measure from LA to China going the other direction, I get a value just fine.

Is this a bug or is there some workaround I need to allow the Distance task to work properly with WrapAround180?
0 Kudos
10 Replies
MarkHoover
Frequent Contributor
I don't think that's what I want...for example, using the method you prescribed, the distance from Wyoming to Nevada is 10,000 miles.

Basically I want the user to be able to click on the map, then click a second point, anywhere in the world, and have it return a distance.  The distance method of the Geometry Service does that quite nicely for our needs, especially with the distanceParam.geodesic set to true, except whenever a measurement spans the IDL (even if it's a very small measurement), I get "null miles" back.

Is it a bug of the GeometryService's Distance method that it fails to work across the IDL?  Because if that worked, that would be the functionality I need for my app.
0 Kudos
JeffPace
MVP Alum
I don't think that's what I want...for example, using the method you prescribed, the distance from Wyoming to Nevada is 10,000 miles.

Basically I want the user to be able to click on the map, then click a second point, anywhere in the world, and have it return a distance.  The distance method of the Geometry Service does that quite nicely for our needs, especially with the distanceParam.geodesic set to true, except whenever a measurement spans the IDL (even if it's a very small measurement), I get "null miles" back.

Is it a bug of the GeometryService's Distance method that it fails to work across the IDL?  Because if that worked, that would be the functionality I need for my app.


A bit of a hack, but would it be possible to check geom1 and geom2, and if east to west, switch them so measurement is always west to east?
0 Kudos
MarkHoover
Frequent Contributor
That's not ideal.  The user should be able to specify whether they want to measure east-to-west or west-to-east.  If a user wants to know the distance from NY to LA, they should get the same result whether they pick NY or LA as their starting point.
0 Kudos
JeffPace
MVP Alum
That's not ideal.  The user should be able to specify whether they want to measure east-to-west or west-to-east.  If a user wants to know the distance from NY to LA, they should get the same result whether they pick NY or LA as their starting point.


Very much agreed.  I was not suggesting you tell the user to measure west to east, but for you as a developer to check the points prior to submitting them to the calculation and swap them behind the scenes.
0 Kudos
JianHuang
Deactivated User
Could you please post your code regarding the observation of "the distance from Wyoming to Nevada is 10,000 miles."? We compared the results between from the geometry service and the client algorithm. They are identical. Meanwhile the client method handles the wraparound case with no problem.
0 Kudos
MarkHoover
Frequent Contributor
Ah, I misinterpreted your initial post.  I was thinking you were suggesting that if they put NY in first, then LA, that we measure west-to-east starting from NY and going the long way around the globe.  Now I see you meant to exchange the values in geom1 and geom2 and call the task normally.

That might be possible using the alternate method, if I could figure out how to determine which point is "west" of the other (especially if you're measuring more than halfway around the globe).

I contend I shouldn't have to do that, though, if the Distance task worked across the IDL.
0 Kudos
MarkHoover
Frequent Contributor
Jian,

I believe the 10,000 miles may have been caused by the polyline not being in a geographic coordinate system, as specified by the method you referenced.  I will try again and convert the polyline first.

Still, is this not a bug of the geometryService?  Shouldn't it be able to handle wrapAround too?
0 Kudos
JeffPace
MVP Alum
Ah, I misinterpreted your initial post.  I was thinking you were suggesting that if they put NY in first, then LA, that we measure west-to-east starting from NY and going the long way around the globe.  Now I see you meant to exchange the values in geom1 and geom2 and call the task normally.

That might be possible using the alternate method, if I could figure out how to determine which point is "west" of the other (especially if you're measuring more than halfway around the globe).

I contend I shouldn't have to do that, though, if the Distance task worked across the IDL.


Completely agreed that you shouldn't have to.  I write alot of code I shouldn't have to as well (primarily if(dojo.isIE){})
0 Kudos