Get milepost from road segment

3506
7
Jump to solution
06-30-2015 11:00 AM
JohnPreston
Occasional Contributor

Hi, I'm trying to get the milepost on a road segment returned from Identity Task (or some other way) in JavaScript. The road segment has Beginning MP and Ending MP as attributes. is there a tool that can calculate (or return) where I clicked on the road? Do you I need to change how road layer is published (using routing)?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

John,

something like this:

IdentifyTask.execute (paramters, function (idResults) {
     if (idResults.length > 0) {
          var polyl;
          for(var r=idResults.length-1; r >= 0; r--){
              polyl = idResults.feature.geometry;
              for(var l=polyl.paths.length-1; l >= 0; l--){
                  var pathArray = [];
                  for (j = 0; j < polyl.paths.length; j++){
                      mp = polyl.getPoint(l,j);
                     //mp is a point object so you can use x and y properties on it.
                  }
              }
          }
          
     }
});

View solution in original post

7 Replies
XanderBakker
Esri Esteemed Contributor

Although I am not a JavaScript expert, I guess you could use the nearestCoordinate(geometry, inputPoint) (see: esri/geometry/geometryEngine | API Reference | ArcGIS API for JavaScript or esri/geometry/geometryEngineAsync | API Reference | ArcGIS API for JavaScript ) to obtain the coordinate of the point on the line (nearest to where the user clicked) and then loop through the vertice pairs of the line and sum the length until you reach the point. (see: Polyline | API Reference | ArcGIS API for JavaScript )

Use the summed length divided by the total line length multiplied with the MP difference to get the MP of the point clicked.

In arcpy (python), ArcObjects and other Runtime SDK's the geometry library seems to be a lot larger and these type of analysis are standard. So, I'm not sure if this is the way you should do this.

Maybe Kelly Hutchins can advise on this?

0 Kudos
JohnPreston
Occasional Contributor

Thank you Xander, do you know what property of the line I would loop through to get the vertice pairs?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

John,

   Once you have the lines geometry (i.e a Polyline Object) you can use the getPoint method in a array.

Polyline | API Reference | ArcGIS API for JavaScript

XanderBakker
Esri Esteemed Contributor

Thanks Robert Scheitlin, GISP  for jumping in.

0 Kudos
JohnPreston
Occasional Contributor

Thank you Robert,

I have feature set of results from Identify task. Do I define a Polyline then set the geometry equal to the geometry of the found feature?

IdentifyTask.execute (paramters, function (idResults) {

     if (idResults.length > 0) {function (result) {

          var foundroadgeometry = result.feature.geometry;

          var feature = result.feature;

          var polyline = new esri.geometry.Polyline(map.spatialReference);

          polyline.geometry = foundroadgeometry;

     }

});

Like that? 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

John,

something like this:

IdentifyTask.execute (paramters, function (idResults) {
     if (idResults.length > 0) {
          var polyl;
          for(var r=idResults.length-1; r >= 0; r--){
              polyl = idResults.feature.geometry;
              for(var l=polyl.paths.length-1; l >= 0; l--){
                  var pathArray = [];
                  for (j = 0; j < polyl.paths.length; j++){
                      mp = polyl.getPoint(l,j);
                     //mp is a point object so you can use x and y properties on it.
                  }
              }
          }
          
     }
});
XanderBakker
Esri Esteemed Contributor

I guess you have to use the path property (Polyline | API Reference | ArcGIS API for JavaScript ) which is of type Number[][][] (but I'm really getting out of my comfort zone right now...)