I adapted the code for my needs, polyline to polyline intersection. Yet I noticed after looking at the results and the code, even with Snapping enabled in ArcGIS Pro for some reason the intersection was returning empty. I decided to create a intersect check with a buffer. Hazzah it worked.........kinda.
The code works great on features that are not curved.
As you can see in the examples above A1 line goes from Start Field B to End Field W, returning the proper values, same for A2. Yet when we move to curved lines, we get only the first line object values returned.
As you can see in B1 the right values are returned. B1 line goes from Start Field A to End Field Z. Yet B2 and B3 are returning the first line segment values Start Field A to End Field Z. When B2 should return Start Field A to End Field Y, and B3 should return Start Field B to End Field Z.
I'm not sure how the curves are being handled differently.
@HusseinNasser2 do you have any thoughts?
/* *********************************************************** */
var fields = ['START_FIELD', 'END_FIELD']
var line_fs = FeatureSetByName($datastore, "Old_Line", fields, true);
var line_shape = Geometry($feature)
var spRef = line_shape['spatialReference']
// Get the origin and end points of the line
var orig_x = line_shape['paths'][0][0].x
var orig_y = line_shape['paths'][0][0].y
var orig_point = Point({x: orig_x, y: orig_y, spatialReference: spRef})
var end_x = line_shape['paths'][-1][-1].x
var end_y = line_shape['paths'][-1][-1].y
var end_point = Point({x: end_x, y: end_y, spatialReference: spRef})
var attributes = {}
function IsEmptyButBetter(data) {
if (IsEmpty(data)) return true;
for (var x in data) return false;
return true;
}
//find point intersecting origin
var origIntx = Intersects(orig_point,line_fs);
if (Count(origIntx) == 0) {
origIntx = Intersects(line_fs, Buffer(orig_point, 1,"meters"));
if (Count(origIntx) == 0) return { "errorMessage": "First vertex must intersect at least one line" }
}
var origIntx = First(origIntx);
if (!IsEmptyButBetter(origIntx)) {
attributes['START_FIELD'] = origIntx['START_FIELD']
}
//find point intersecting end
var endIntx = Intersects(end_point, line_fs);
if (Count(endIntx) == 0) {
endIntx = Intersects(line_fs, Buffer(end_point, 1, "meters"));
if (Count(endIntx) == 0) return { "errorMessage": "Last vertex must intersect at least one line" }
}
var endIntx = First(endIntx);
if (!IsEmptyButBetter(endIntx)) {
attributes['END_FIELD'] = endIntx['END_FIELD']
}
var result = {}
if (!IsEmptyButBetter(attributes)) {
result['result'] = {
'attributes': attributes
}
}
return result
The code works