Help! How can I measure the distance between points

3382
6
08-20-2010 01:45 PM
AlejandroMorales
New Contributor
Hi, everyone

I'm having this problem, I have 2 layers let's say I have this situation:
Layer A:
Point1
Point2
Point3
Point4

Layer B:
Point1
Point2
Point3
Point4

The Points of the two layers are related this way:
A.Point1 connected to B.Point1 
A.Point2 connected to B.Point2 
A.Point3 connected to B.Point3 
A.Point4 connected to B.Point4 

How can I measure their distance between each other using the JavaScript API , If each point is in a different layer.
Please If you have some code I can use I will thank you so much!


Alex
0 Kudos
6 Replies
RahulRavikumar
New Contributor
If all you care about is the distance, then you can get the coordinates of the points for which you need to measure distances; and pass them to the geometry service's "lengths" operation.
0 Kudos
AlejandroMorales
New Contributor
Thanks for your response,

How can I do that? Can you give some code please?

Thank you.
0 Kudos
AlejandroMorales
New Contributor
Thanks for the help guys! I really appreciate but
what I'm trying to do is to measure the distance between 2 points that already have X and Y coordinates so
Point A (Layer 1) has all its properties including X and Y
Point B (Layer 2) same as Point B

is there a procedure, function where I can get the distance between A and B ?
0 Kudos
TimRourke
New Contributor
Alex,

I think if you take a close look at the first page swingley pointed out (http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/util_distance....), you'll see some code that shows how to set up the parameters for a call to the GeometryService's distance task. It shows how to add geometries from an array. In your case, you'd add your two known points:

var distParams = new esri.tasks.DistanceParameters();
distParams.distanceUnit = esri.tasks.GeometryService.UNIT_STATUTE_MILE;    
distParams.geometry1 = pointA;     //<--- your Point A geometry
distParams.geometry2 = pointB;     //<--- your Point B geometry
distParams.geodesic = true;


The sample code on the page shows how to call GeometryService.distance and work with its results. The section where it says function(distance){..}) catches the data returned by GeometryService.distance in the parameter distance.

geometryService.distance(distParams, function(distance) {
     // Do what you want with the result.
     });
});


Hope that helps,

Tim
0 Kudos
AlejandroMorales
New Contributor
Tim, thank you so much!, I'm trying it right now I just have one question, when I create the points I use this lines (just to try) : 
p1 = new esri.geometry.Geometry.Point(767045.94,1620609.96,??);
p2 = new esri.geometry.Geometry.Point(768450.94,7621609.90,??);

I don't know what to put in the spatial reference parameter because my map has this as a spatial reference:
PROJCS["WGS_1984_UTM_Zone_15N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-93.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Kilometer",1000.0]]

It's a lot and I don't think i have to put all that into a parameter right?
Please can You tell me, what should I do?

Thanks
Alex,

Alex,

I think if you take a close look at the first page swingley pointed out (http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/util_distance....), you'll see some code that shows how to set up the parameters for a call to the GeometryService's distance task. It shows how to add geometries from an array. In your case, you'd add your two known points:

var distParams = new esri.tasks.DistanceParameters();
distParams.distanceUnit = esri.tasks.GeometryService.UNIT_STATUTE_MILE;    
distParams.geometry1 = pointA;     //<--- your Point A geometry
distParams.geometry2 = pointB;     //<--- your Point B geometry
distParams.geodesic = true;


The sample code on the page shows how to call GeometryService.distance and work with its results. The section where it says function(distance){..}) catches the data returned by GeometryService.distance in the parameter distance.

geometryService.distance(distParams, function(distance) {
     // Do what you want with the result.
     });
});


Hope that helps,

Tim
0 Kudos