I have a shapefile dataset. Some roads (line) have the same name but are located at different places and are not connected.
Here is a picture of the roads with a same name in my geopandas datafile:
I would like to be able to measure the distance between road chunks (linestrings) to be able to rename the roads if the distance is higher than a threshold, such that each road has its own unique name.
Hence, do you know how to find the distance between linestrings ?
In geopandas, the geometries are shapely objects. To get a distance between any two shapely objects, you use the cleverly named
distance
method:If you have a geopandas GeoSeries/GeoDataFrame, you need to be a little smarter about it.
Returns all zeros, because it lines up
gs
togs
on the index, which is all the same geometries.But:
Gives you the distances from line1 to line2, and line2 to line3: