Sort points on line in PolyData

So I have a PolyData object of lines generated from extracting feature edges from a 2D unstructured grid and then cutting out portions of the feature edges I didn’t want.

In my example, the original grid was just a square, so the feature edges would equally just be a square. Then I “extracted” out one side of the square. I would like to have the points of this PolyData object be in the order of the line, as currently they are more-or-less random.

From this definition on the VTK examples website, maybe the solution would be to convert the PolyData to a PolyLine? I can’t find any obvious path to achieve this though.

You can use vtkStripper to merge randomly ordered line segments into polylines. If the polydata is large then you may need to increase MaximumLength.

So this does work, but it has the unintended effect of combining the individual cells into single lines. ie.

wallpoly.GetNumberOfCells() # 1246

strip = vtk.vtkStripper()
wallstrip = strip.GetOutput()

wallstrip.GetNumberOfCells() # 2

I tried setting strip.SetJoinContiguousSegments(False), but this did not change anything. It’s not a deal breaker by any means, but it would be nice to preserve the cells/lines.