Probado en QGIS 2.18 y QGIS 3.4
Supongamos que hay una capa de polilínea llamada "lines"
.
Puedo sugerir el uso de una "Capa virtual" a través de Layer > Add Layer > Add/Edit Virtual Layer...
Hay varios casos posibles:
Caso 1. Dividir la línea en segmentos iguales, básicamente de la misma longitud definida por el usuario.
Con la siguiente consulta, es posible lograr el resultado. Para aumentar / disminuir la longitud del segmento, ajuste el 1000 AS step_length
en -- configurations
.
-- generate series
WITH RECURSIVE generate_sections(id, sec) AS (
SELECT conf.start + 1, conf.start
FROM conf
UNION ALL
SELECT id + conf.step, sec + conf.step_length/conf.length_line
FROM generate_sections, conf
WHERE sec + conf.step_length/conf.length_line <= 1
),
-- configurations
conf AS (
SELECT
0.0 AS start,
1.0 AS step,
1000 AS step_length,
ST_Length(l.geometry) AS length_line
FROM lines AS l
)
-- query
SELECT gs.id AS id,
ROUND(ST_Length(ST_Line_Substring(l.geometry, start + sec, sec + conf.step_length/conf.length_line)),0) AS seg_length,
ST_Line_Substring(l.geometry, start + sec, sec + conf.step_length/conf.length_line) AS geom
FROM generate_sections AS gs, lines AS l, conf
GROUP BY gs.id
La capa virtual de salida tendrá el siguiente aspecto
Nota: Si 'delta' (por ejemplo, el último segmento más corto) no debe ser incluida, a continuación, inserteWHERE sec_length >= step_length
en-- query
, ver más abajo
-- query
SELECT gs.id AS id,
ROUND(ST_Length(ST_Line_Substring(l.geometry, start + sec, sec + conf.step_length/conf.length_line)),0) AS seg_length,
ST_Line_Substring(l.geometry, start + sec, sec + conf.step_length/conf.length_line) AS geom
FROM generate_sections AS gs, lines AS l, conf
WHERE seg_length >= step_length
GROUP BY gs.id
Caso 2. División de la línea en un cierto número de segmentos.
Con la siguiente consulta, es posible lograr el resultado. Para aumentar / disminuir el número de segmentos, ajuste el 8 AS sections
en -- configurations
.
-- generate series
WITH RECURSIVE generate_sections(id, sec) AS (
SELECT conf.start + 1, conf.start
FROM conf
UNION ALL
SELECT id + conf.step, sec + conf.step
FROM generate_sections, conf
WHERE sec + conf.step < conf.sections
),
-- configurations
conf AS (
SELECT
8 AS sections,
0.0 AS start,
1.0 AS step
)
-- query
SELECT gs.id AS id,
ST_Line_Substring(l.geometry, conf.start + sec/conf.sections, sec/conf.sections + step/conf.sections) AS geom,
ROUND(ST_Length(ST_Line_Substring(l.geometry, conf.start + sec/conf.sections, sec/conf.sections + step/conf.sections)),2) AS seg_length
FROM generate_sections AS gs, lines AS l, conf
WHERE start + step < sections
GROUP BY gs.id
La capa virtual de salida tendrá el siguiente aspecto