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
출력 가상 레이어는 다음과 같습니다.