I have a line shapefile in GeoPandas. How can I extract the start and end coordinates as (x,y) pairs in two separate columns?
import geopandas as gpd
gdf = gpd.read_file(pth_line_shapefile)
gdf['start_coordinates_XY'] = gdf.apply(lambda x: [y[0] for y in x['geometry'].coords], axis=1)
The above code extracts X coordinates of all points in the geometry not the first point (in x,y format)
An example line shapefile linked here
Best Answer
This can make it:
Which results in:
You can tweak that to suit what ever format your need for your points...
Source:
https://shapely.readthedocs.io/en/latest/manual.html#Point
Reference
Gillies, S. others.(2007). Shapely: Manipulation and analysis of geometric objects. toblerity. org.