12

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 or QGIS?

  • 2
    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. – Richard Fairhurst May 6 '15 at 13:55
  • Does this answer your question? "How do I retrieve start and end point coordinates with Python/arcpy?" gis.stackexchange.com/q/31684/8104 – Aaron May 6 '15 at 14:25
  • I tried a similar approach but got lost along the way. I´ll try to redo it. The best will be create a macro that does all this job toguether so anyone could make the same procedure afterwards. Cheers! – user51651 May 8 '15 at 16:57
  • @RichardFairhurst method, that should probably be suggested as an answer as well. That's how I have done it historically – bwp8nt Feb 9 at 22:42
8

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.

  • Thank you very much!This probably get the job done, but I was looking for something more simple(visual) so other people without programming skills could perform the task. – user51651 May 8 '15 at 17:03
  • Where do you write that command? – blue_chip Oct 5 '17 at 4:43
  • To the command line. On Linux use the normal shell. On Windows use the command window but take care that your environment has right paths. Osgeo4w shell does that automatically. – user30184 Oct 5 '17 at 5:00
6

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.

4

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

  • This is great Ian! I´ll download it and test it and give you feedback asap. I think this tool will come in handy for what I need and will help automate the process better! Thank yoU! – user51651 May 8 '15 at 17:00
  • Hi Ian, Idk why but I can´t get your tool to work in ArcGIS 10.0 or 10.1... I added it to toolbox but it doesn`t lunch... =/ – user51651 May 18 '15 at 16:32
  • @user51651 Are you getting an error message? It won't work with 10.0, but it should work with 10.1 and above. If you go into the Geoprocessing menu, and then Results. Are there any messages in there? – ianbroad May 18 '15 at 16:53
4

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)
  • this should be accepted answer. most elegant – sys49152 May 14 '18 at 10:54
  • this is to generate cooridnates, then how to generate the object IDs? – chenzhongpu Jul 27 '18 at 7:35
1

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

  • This is a really good answer, I didn't realize this was possible. A snapshot of it in Field Calculator might help less-familiar people with the task. I assume you could do this with M values as well? – bwp8nt Feb 9 at 22:39
0

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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