3

I have a selection of vectors in QGIS (about 1000) that I'd like to split in half at once. I've already used the v.split from GRASS but as the length of links are very different one from another, I couldn't find a proper value for the 'maximum segment length'.

Is there any way to do that?

2

2 Answers 2

6

You can use the Geometry by Expression tool with this expression:

collect_geometries(
    line_substring($geometry, 0, $length/2),
    line_substring($geometry, $length/2, $length)
)

The output is a multipart geometry, so run Multipart to Singleparts tool on it.

Result:

enter image description here

From the Help panel of the expression editor:

function line_substring

Returns the portion of a line (or curve) geometry which falls between the specified start and end distances (measured from the beginning of the line). Z and M values are linearly interpolated from existing values.

Syntax
line_substring(geometry,start_distance,end_distance)

Arguments
geometry - a linestring or curve geometry
start_distance - distance to start of substring
end_distance - distance to end of substring

3

For Polylines

There is a possibility of using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer...

Let's assume there is a layer called 'route', see the image below.

input

With the following Query, it is possible to split it in half at once.

SELECT "id", ST_Line_Substring(geometry, 0, 0.5) AS geom
FROM "route"
UNION ALL
SELECT "id", ST_Line_Substring(geometry, 0.5, 1) AS geom
FROM "route"

Now, the output Virtual Layer will look as follows

result


For Polygons

Check this thread: Splitting polygon into equal area polygons using QGIS


References:

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.