Convert line to polyline

Hi all,

I need to convert my line geometry to polylines, unfortunately, exploding the lines and rebuilding them as polylines in grasshopper still yields line geometry as result.
They need to be converted in order for QGIS to read the DXF as a single layer. Regardless of merging layers, QGIS always differentiates between curves and polylines.
Is there an alternative approach to converting the lines? Or should I just add midpoints in between the lines and create polylines from those? There are 11000 lines in the project though and 42000 curves in total (metropolitan scale data).
Ideally, I would just batch convert them using Selline and change the data type from line to polyline.

Go to the curve tab in grasshopper, then utilities. There are a few options there but curve to polyline sounds like a good fit.

Unfortunately neither that component, nor the polyline component create polylines from just start and end points, so I suppose there needs to be an additional points for there to be polyline segments. Unless I am mistaken.

Hello - I think I can make you a thing that will convert these. Hold on a bit.
@Intuos - see if this does anything good - you can use the same code, presumably, in a GH python component.

ConvertLinesToPolylines.py (687 Bytes)

To use the Python script use RunPythonScript, or a macro:

_-RunPythonScript "Full path to py file inside double-quotes"

-Pascal

1 Like

Hi @pascal Pascal thanks for the help, though I am receiving an error for some of the lines on my end:


Most lines converted well, but some didn’t.

E: There doesn’t seem to be anything odd in particular about them:

Hm - can you send me one or two of these? This was a very quick and dirty script…

-Pascal

I saw you added segments to the lines, so I fixed it in grasshopper now, like so:

And now it’s all good and well! Thank you!

@pascal in case you want to thinker further with the script, here’s two of the lines.
Two lines.3dm (26.6 KB)

Hm - both of those work here.

-Pascal

@pascal Is there a way to convert lines that are joined as a polyline to an open polyline?
Apparently QGIS still treats those as lines :confused:

Here’s the file:
Subelement line to polyline.3dm (53.9 KB)

Preferably, I’d like to have the line subelement become part of the open polyline, or in other words, add the line as segment to the polyline, but I am not sure how I could retrieve the subelement, or I’d need to sort the points by lines for 40k points in grasshopper somehow.

Hello - try SimplifyCrv on that one.

-Pascal