5

I have shape file with road network (line layer) as shown in Image 1. The road network contains multiple line segments as shown with blue line in image.

  • I am trying to generate start and end point of every road segment.
  • Save the start and end point in a seperate layer.

Based on the suggested answer here, I am trying to get the start and end points by using query in virtual layer

Problem:It merges start and end points into single colomn. I am trying to get them in seperate coloumns. For instance, Col 1: start points, Col2: end points

select From_id, st_startpoint(geometry) as geometry from lineshp 
union
select To_id, st_endpoint(geometry) as geometry from lineshp

Attempt with geometry generator:

Problem: It only displays the start and end points. It does not save the data in seperate layer.

union (
    end_point ( $geometry ),
    start_point ( $geometry )
)

enter image description here

Case Msee
  • 855
  • 4
  • 11

3 Answers3

3

Using the virtual layer, you can compute both start and end point in a single row. Beware that your layer will now have 2 geometry fields, which are a pain to display (the 1st one is usually used)

SELECT From_id, st_startpoint(geometry) as geometryFrom, 
       To_id, st_endpoint(geometry) as geometryTO 
FROM lineshp 
JGH
  • 41,794
  • 3
  • 43
  • 89
  • Thank you for great answer. I was wondering if the existing road network shapfile (TR_ROAD) has already start and end points as I can see FROM_UFI and TO_UFI in the attribute table https://i.stack.imgur.com/8sCzW.png. Are these are start and end points? as the road network shapefile is available here https://drive.google.com/drive/u/2/folders/1-DKB4bGSYzgrP2Za2FWdmO-tBJBsU1oT – Case Msee Feb 24 '21 at 04:09
1

you could just use the Vector->Geometry Tools->Extract Verctices tool to make an output of all vertices.

Then you could use a Select by expression to get the min and max vertices:

"vertex_ind" = maximum("vertex_ind", group_by:="[your_id_field]")
OR
"vertex_ind" = 0

Then export the selected features as a new shapefile.

You can add the coordinates to a new field using the formula:

x($geometry)

and

y($geometry)
jdavid05
  • 538
  • 3
  • 13
  • Does the coordinate means Latitude and Longitude?. Does the formmula will save 4 points for start and end points? For instance, • START_X: X-coordinate of line start• START_Y: Y-coordinate of line start, • END_X: X-coordinate of line end, • END_Y: Y-coordinate of line end. Something similar to here in ArcGis https://support.esri.com/en/technical-article/000012326 – Case Msee Feb 24 '21 at 04:12
  • This would create 1 point for the end point and 1 point for the start point (2 points total). Do it twice and it will create 4 points total. You can print the x and y values in any system you want - just reproject the data or use the 'transform()' function in your codeblock – jdavid05 Feb 25 '21 at 16:15
  • I run the extract specific vertices tool by selecting 0 and -1 for the start and end points as shown here https://i.stack.imgur.com/KP08p.png. It only displays 0,1,-1 etc. Is it possible convert these into unique ids such as start point:61543, edpoint:78654 – Case Msee Feb 26 '21 at 00:43
0

Run the extract specific vertices tool. Select 0 and -1 for the start and end points to be created as a point layer. Join attributes by location to get both point datasets into the same layer.

itsgupta
  • 538
  • 3
  • 7
  • The specific vertices tool only saves 0 and -1 in the attribute table. I need information of start and end points with ids such as start point:61543, edpoint:78654 – Case Msee Feb 23 '21 at 11:23