Answers:
GRASS 的v.split.length函数可以通过将线划分为用户定义的相等段而无需点层,从而完全满足您的要求。这是一条直线的简单示例(它也适用于非直线和多条直线):
我$length
在表达式中添加了一个列来计算其长度:
通过Processing Toolbox使用GRASS 的v.split.length函数,我选择将线分成25m个分段,该分段总共应由4个部分组成:
然后,我更新了输出层的“长度”列,并使用与上述相同的命令来重新计算长度:
不知道为什么会收到错误消息,是否可以共享线层供人们测试?
在QGIS 2.18和QGIS 3.4上测试
假设有一个称为的折线图层"lines"
。
我可以建议通过以下方式使用“虚拟层” Layer > Add Layer > Add/Edit Virtual Layer...
情况1.将线分成相等的段,长度由用户定义,长度基本相等。
通过以下查询,可以实现结果。要增加/减少段长度,请在1000 AS step_length
中进行调整-- 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
输出虚拟层将如下所示
注意:如果 “三角洲”(例如,最近的最短段)不应该被包括在内,然后插入WHERE sec_length >= step_length
在-- query
,见下文
-- 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
情况2。将线分成一定数量的段
通过以下查询,可以实现结果。要增加/减少段数,请调整8 AS sections
中的-- 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
输出虚拟层将如下所示