I crafted a function for you.
Here is your line, which I call old_line:
old_line=LineString([(0,0), (9,0)]) # your line with 2 vertices
Here is the function that takes a line geometry as main input, you assign a step (i.e the spacing along the old line) and and additional Coordinate Reference System (crs) to georeference the new densified line.
def densify_geometry (line_geometry, step, crs=None):
# crs: epsg code of a coordinate reference system you want your line to be georeferenced with
# step: add a vertice every step in whatever unit your coordinate reference system use.
length_m=line_geometry.length # get the length
xy= # to store new tuples of coordinates
for distance_along_old_line in np.arange(0,int(length_m),step):
point = line_geometry.interpolate(distance_along_old_line) # interpolate a point every step along the old line
xp,yp = point.x, point.y # extract the coordinates
xy.append((xp,yp)) # and store them in xy list
new_line=LineString(xy) # Here, we finally create a new line with densified points.
if crs != None: # If you want to georeference your new geometry, uses crs to do the job.
densify_geometry(line_geometry=old_line, step= 0.5, crs= 32754)
LINESTRING (0.00000 0.00000, 0.50000 0.00000, ...
If you want to .apply it to a whole
GeoDataFrame geometry column:
This should do the job.