I have 2 layers (pipe layer<line> and fitting layer<point>) and the 2 layers is empty
I assigned an attribute rule to the pipe layer,
this Rule manage me to draw new feature in the pipe layer and
if that new feature intersected with an existed feature in the same layer (pipe layer) => new point will be created and inserted into the fitting layer
Trigger types: insert and update
Here is the code:
I have tried it and I can't get it to work. I hope I'm missing something simple and that I'm wrong here, but I think the problem is that we are assuming that Intersection is going to return a geometry of type point and I'm not sure from the documentation that it does.
The only work around I can think of is to return the path from $feature using something like this:
var pipeGeom = geometry($feature)
var paths = pipeGeom.paths
Then step through each point (vertice) in the "path" to determine if it intersects a pipe other than $feature. By this I mean you'll have to do something like this to make sure you don't consider the pipe you are currently entering; because of course all the points on that pipe's "path" will be intersected:
var thisPipe = $feature.GlobalID
var pipe = Filter(FeatureSetByName($datastore, "pipe"),'GlobalID <> @thisPipe')
When/if you find the point/vertice along the path that intersects another pipe, that will be the geometry you use to "edit:" your point layer.
Again, I hope I am wrong and that I'm missing something simple, but the Arcade documentation for Intersection doesn't mention "if you provide two line geometries as inputs a set of intersection points will be returned"....
Hi @AhmedElagroudy and @KimGarbade ,
When creating Attribute Rules you need to be sure to check for anything that could go wrong along the way:
And really, you should take a look at this great repository created by Mike Miller with a lot of examples: https://github.com/MikeMillerGIS/arcade-expressions/tree/master/attribute_rule_calculation
In order to not overcomplicate the expression I did the following:
Some more graphical explanations are below.
The initial situation, lines in blue and intersecting points displayed with red crosses:
Start drawing the line and create multiple intersections (only 1 per existing line):
The intersecting points are added to the points layer:
Now there are some things you will have to take into account:
The expression used:
var globid = $feature.GlobalID;
var sql = "GLOBALID <> @globid";
var pipes = Filter(FeatureSetByName($datastore, "pipe"), sql);
if (Count(pipes) > 0) {
var intersecting_features = Intersects(pipes, $feature);
var cnt = Count(intersecting_features);
var adds = [];
if (cnt > 0) {
var polf = Buffer($feature, 0.1, "m");
for (var pipe in intersecting_features) {
var poli = Buffer(pipe, 0.1, "m");
var polint = Intersection(poli, polf);
var pnt = Centroid(Polygon(polint));
Push(adds, {"geometry": pnt});
}
}
// don't try and return anything when there is no intersection!
if (Count(adds) > 0) {
return {
"edit": [
{"className": "test_point",
"adds": adds
}
]};
}
}