21

I have a vector(polyline) shapefile and I need to retrieve each line´s start and end points(nodes) and create a shapefile with these points. Then I need to add to the polyline´s attribute table the start and end point for each line based in the points ID.

How could I do that in a simple way in ArcGIS Desktop or QGIS?

0

7 Answers 7

16

QGIS solution: It is possible to extract begin and ending nodes (coordinates) of a line vector file, simply by using xat and yat in the field calculator, with the respective indices 0 (start) and -1 (end).

xat(0)    
yat(0)
xat(-1)
yat(-1)
0
9

That is an one-liner for GDAL. This command creates a shapefile from the start nodes with selected attributes:

ogr2ogr -f "ESRI Shapefile" -dialect sqlite output.shp -sql "select ST_StartPoint(geometry), attribute_1, attribute_2, attribute_3 from input" input.shp

Use ST_EndPoint for endpoints.

0
8

There is a QGIS plugin "Locate points along lines". To derive start and endpoints choose Add endpoints an use an Interval longer than your longest line.

6

For an ArcGIS solution, I've made a geoprocessing tool that creates points on lines.

You can download it, and view the code here: Create Points on Lines

For the Type, you will want to choose START/END POINTS. This will create a new point feature class that contains the start and end points for each polyline.

The output point feature class will also have a field called LineOID, which records the OID of the polyline it was created from. That way you can join your attribute data back.

Here's a screenshot of how you'd set the parameters:

enter image description here

0
6

In QGIS use Extract Specific Vertices tool. Set Vertex indices to 0 to get start points and -1 to get end points or 0,-1 to get both.

QGIS Extract Specific Vertices

Note the description:

The first vertex corresponds to an index of 0, the second vertex has an index of 1, etc. Negative indices can be used to find vertices at the end of the geometry, e.g., an index of -1 corresponds to the last vertex, -2 corresponds to the second last vertex, etc.

4

for adding the coordinate of the end points in the attribute table, using ArcGIS, you can use the field calculator (no need to create geometries). Click on the field name, field calculator, then use the Python syntax with the single lines below (example with the X coordinate):

!shape.firstPoint.X!

!shape.lastPoint.X!

note that everything is inside the !!'s

0
3

In ArcGIS, if you have an Advanced license, you can use the Data Management Toolbox->Features Toolset->Feature Vertices to Points tool with the Both Ends option. All attributes of the line are retained. However, you would have to add a field to your original line feature class and calculate the feature ID on your line to have that value preserved in the points. If you have another unique value field on your lines you could join and calculate the FID after running the tool. Final option would involve doing a Spatial Join with the One To Many option and removing copies with bad attributes.

Not the answer you're looking for? Browse other questions tagged or ask your own question.