I am trying to extract the start and endpoint coordinates in GeoPandas. Following this link, I am using this code to extract the start and endpoints for GeoJSON files.
def add_start_end_nodes_to_gdf(self, gdf=None): # This function adds start and end nodes to geodataframe if gdf is None: gdf=self.GeoData.gdf gdf['start_node'] = None gdf['end_node'] = None for index, row in gdf.iterrows(): coords = [(coords) for coords in list(row['geometry'].coords)] start_node, end_node = [coords[i] for i in (0, -1)] gdf.at[index, 'start_node'] = start_node gdf.at[index, 'end_node'] = end_node
This is giving me an error
coords = [(coords) for coords in list(row['geometry'].coords)] File "****lib\site-packages\shapely\geometry\base.py", line 841, in coords "Multi-part geometries do not provide a coordinate sequence") NotImplementedError: Multi-part geometries do not provide a coordinate sequence
What is happening here and how can I extract the start and endpoint of any polylines? I tried this
list(row['geometry']) to get the first line in the Multi-part geometries (polylines) with no success. My file contains only lines.