The GeometryEngine in runtime 100.1 onwards has a cut method that cuts a geometry using a polyline.
However, what would be the best and safest way to split an actual polyline by a single point?
Currently, I would need to create a polyline as the cutter. Since all I have is a single point, then technically, without knowing ahead of time the geometry of the polyline I want to cut, I would have to add another random point to my known point to create a polyline, then use that as the cutter to cut my initial polyline. No matter where I add that second random point, I could never be sure that it wouldn't intersect the initial polyline twice.
The only safe way is the way I previously did it, where I create a brand new polyline and add all the points up to that cut/split point and use that new polyline.
Is there a better way I'm missing? Or is this perhaps a suggestion for a variation of the cut method specifically for this task?
Solved! Go to Solution.
What is the sense behind cutting a polyline by a single point?
Is the single point an element of that polyline?
If so you can access all points of a polyline using
polyline.parts().part(0).pointCount() // pointCount of first part
Maybe the operator== is not sufficiant, give qFuzzyCompare a try....
Hope it helps 🙂
Thanks for the reply.
You ask what is the sense of cutting a polyline by a single point - perhaps 'cut' is the wrong term, but the concept is valid. Perhaps a use case would help understand:
e.g. I have a polyline that represents a waterway. I have a user standing beside that waterway. Given their gps location, I then find the nearest coordinate on the waterway polyline. I now have a 'point' on that polyline. I want to then obtain a section of that line, say, from the beginning of the line up to that point.
As I mention above, my current approach is to create a new line and copy all the points across from the original line up to the point in question. This works fine. My question is whether there is or should be a runtime method that can achieve this more efficiently.