Geographic Information Systems Asked on June 4, 2021
I have 6 points in one layer as shown in the first image. I am trying to:
For demo, I have manually connected the lines (green)
and shown the sequence (red)
with numbers in Image 1. The sequence of connecting lines should be as follows:
Sequence | From_point | To_point |
---|---|---|
1 (building1) to (Junction) | 7b9f | aab4 |
2 (building2) to (Junction) | d052 | aab4 |
3 (Junction) to (Breaker) | aab4 | edb3 |
4 (Breaker) to (Station) | edb3 | c037 |
5 (Sation)) to (MainSource) | c037 | 4d3c |
Initial attempt with points to path:
I tried to achieve this Menu Processing / Toolbox / points to path
and Points2One plugin
but it does not maintain the required sequence of connections as shown in Image 2
For your probleme you can indeed use virtual layer, I didn't know you want use this method :
with
build_segment as (
select
a.mrid as start_point,
b.mrid as end_point,
makeline(a.geometry, b.geometry) as geometry
from <layername> a
left join <layername> b on (a.id + 1 = b.id ))
select
*
from build_segment
where geometry is not null
Correct answer by lejedi76 on June 4, 2021
For the fist part of your problem :
You could use the geometry by expression algorithm and use this expression :
collect_geometries(
array_foreach(
aggregate(
'LAYERNAME' ,
'array_agg',
"mrid",
filter:="id" = attribute(@parent, 'id')+1),
make_line($geometry, geometry(get_feature('LAYERNAME', 'mrid',@element)))
)
)
It's not the best approach to what mentioned Kadir. If there are 2 ore more children this expression will build a multilinestring.
For the second part, apply the multiparttosinglepart algorithm on the output of the first treatment. The mrid field correponds to the start and you can obtain the end by adding a new fied on the ouput with this formula :
aggregate('LAYERNAME',
'concatenate', "mrid", filter:= intersects($geometry,end_point(geometry(@parent))))
*intersects is used in place of equals
** LAYERNAME is the SOURCE LAYER (point layer)
Answered by lejedi76 on June 4, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP