Calculate startpoint endpoint of line

840
5
Jump to solution
05-02-2023 09:05 AM
EddyClark
Occasional Contributor

Need to capture the starting point and end point of line features.  Surely the table would contain fields for each - [StartX], [StartY], [EndX], [EndY].   

Does anyone know if Field Maps/Arcade has an expression that would do this calculation? 

Otherwise I'd ask the field crews to capture both point (x2) and line.  In which case they would complain.  

2 Solutions

Accepted Solutions
JohannesLindner
MVP Frequent Contributor
var start_x = Geometry($feature).paths[0][0].x
var start_y = Geometry($feature).paths[0][0].y
var end_x = Geometry($feature).paths[-1][-1].x
var end_y = Geometry($feature).paths[-1][-1].y

Have a great day!
Johannes

View solution in original post

sondickerson
New Contributor III

This was a great question and solution! 

I used it to pull the coordinates for 2 arcade expressions representing the start and end points of the line.  I didn't try it in fieldmaps but I think it would work to have it calculate column values for the line start/end points but I don't think you can have it create a point that represents the start/end point.   

//Find the start coordinates

var xval = Geometry($feature).paths[0][0].x
var yval = Geometry($feature).paths[0][0].y

function metersToLatLon(xval, yval) {
   var originShift = 2.0 * PI * 6378137.0 / 2.0;
  var lon = (xval / originShift) * 180.0;
   var lat = (yval / originShift) * 180.0;
   lat = 180.0 / PI * (2.0 * Atan(Exp(lat * PI / 180.0)) - PI / 2.0);

return [lat, lon];
}

var latlon = "";
var result = "";
var latlon = metersToLatLon(xval, yval);

result = Round(latlon[0], 6) + ', ' + Round(latlon[1], 6);
return result;

 

//Find the end coordinates
var xval = Geometry($feature).paths[-1][-1].x
var yval = Geometry($feature).paths[-1][-1].y

function metersToLatLon(xval, yval) {
   var originShift = 2.0 * PI * 6378137.0 / 2.0;
  var lon = (xval / originShift) * 180.0;
   var lat = (yval / originShift) * 180.0;
   lat = 180.0 / PI * (2.0 * Atan(Exp(lat * PI / 180.0)) - PI / 2.0);

return [lat, lon];
}

var latlon = "";
var result = "";
var latlon = metersToLatLon(xval, yval);

result = Round(latlon[0], 6) + ', ' + Round(latlon[1], 6);
return result;

View solution in original post

5 Replies
JohannesLindner
MVP Frequent Contributor
var start_x = Geometry($feature).paths[0][0].x
var start_y = Geometry($feature).paths[0][0].y
var end_x = Geometry($feature).paths[-1][-1].x
var end_y = Geometry($feature).paths[-1][-1].y

Have a great day!
Johannes
EddyClark
Occasional Contributor

Perfect!  I merged this with the code found in the "Common Calculated Expressions" blog post to get Lat/Long instead of meters.  

Thank you so much!

https://www.esri.com/arcgis-blog/products/field-maps/field-mobility/common-calculated-expressions-fo...

0 Kudos
EddyClark
Occasional Contributor

You wouldn't happen to know how to get Field Maps to make this calculation, would you?  Calcs work in ArcGIS Online, but not Field Maps.  Probably because you cannot "Finish" the drawing in Field Maps (Submit) like you do in AGOL (double click).  

0 Kudos
JohannesLindner
MVP Frequent Contributor

Sadly, I have no idea of field maps 😞


Have a great day!
Johannes
0 Kudos
sondickerson
New Contributor III

This was a great question and solution! 

I used it to pull the coordinates for 2 arcade expressions representing the start and end points of the line.  I didn't try it in fieldmaps but I think it would work to have it calculate column values for the line start/end points but I don't think you can have it create a point that represents the start/end point.   

//Find the start coordinates

var xval = Geometry($feature).paths[0][0].x
var yval = Geometry($feature).paths[0][0].y

function metersToLatLon(xval, yval) {
   var originShift = 2.0 * PI * 6378137.0 / 2.0;
  var lon = (xval / originShift) * 180.0;
   var lat = (yval / originShift) * 180.0;
   lat = 180.0 / PI * (2.0 * Atan(Exp(lat * PI / 180.0)) - PI / 2.0);

return [lat, lon];
}

var latlon = "";
var result = "";
var latlon = metersToLatLon(xval, yval);

result = Round(latlon[0], 6) + ', ' + Round(latlon[1], 6);
return result;

 

//Find the end coordinates
var xval = Geometry($feature).paths[-1][-1].x
var yval = Geometry($feature).paths[-1][-1].y

function metersToLatLon(xval, yval) {
   var originShift = 2.0 * PI * 6378137.0 / 2.0;
  var lon = (xval / originShift) * 180.0;
   var lat = (yval / originShift) * 180.0;
   lat = 180.0 / PI * (2.0 * Atan(Exp(lat * PI / 180.0)) - PI / 2.0);

return [lat, lon];
}

var latlon = "";
var result = "";
var latlon = metersToLatLon(xval, yval);

result = Round(latlon[0], 6) + ', ' + Round(latlon[1], 6);
return result;