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.
Solved! Go to Solution.
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
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;
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
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!
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).
Sadly, I have no idea of field maps 😞
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;