I don't understand your question:
line = LineString([(0, 0), (2, 2)])
# create a point which lies along the line
point = line.interpolate(1)
line.contains(point)
True
You want the two lines which lie either side of the point ?
line1 = LineString([line.coords[0],(point.x, point.y)])
line2 = LineString([(point.x, point.y), line.coords[1]])
Upgrade 1: with a line with multiple vertices
You need to iterate through the segments of the LineString to find the one that contains the point
The LineString must be iterate as pair to divide the line in segments.
def pairs(lst):
for i in range(1, len(lst)):
yield lst[i-1], lst[i]
line = LineString([(0,0),(1,2), (2, 2), (2,3), (4,2),(5,5)])
for pair in pairs(list(line.coords)):
if LineString([pair[0],pair[1]]).contains(point):
print LineString([pair[0],pair[1]])
LINESTRING (2.00 2.00, 2.00 3.00)
And you can use the previous answer: a rapid solution, for example ( this can be done better):
line1 = []
line2 = []
cp = False
for pair in pairs(list(line.coords)):
if cp == False:
line1.append(pair[0])
if cp == True:
line2.append(pair[1])
if LineString([pair[0],pair[1]]).contains(point):
line1.append((point.x,point.y))
line2.append((point.x,point.y))
line2.append(pair[1])
cp = True
line1 = LineString(line1)
line2 = LineString(line2)
Result:
I think you are misunderstanding a little what the buffer operation is actually doing. When you buffer a geometry, you create a polygon around an existing geometry with an edge at a specified distance from the original geometry. In the case of a point, this results in a circular polygon with radius equal to the distance of the buffer. For lines and polygons this creates more complicated shapes, but with the same principle.
The illustration on the ArcGIS documentation shows this quite nicely: http://desktop.arcgis.com/en/arcmap/10.3/tools/analysis-toolbox/buffer.htm
Your "dilated" geometry is a polygon with an edge that is 0.5 units away from the original line at all positions. When you buffer by 0.0 units what you are doing is saying: create a polygon with an edge exactly 0 units away from the dilated. The result is the same as the dilated polygon, NOT the original line string.
You can buffer a polygon with a negative distance, but this still always returns a polygon - at the point it would return your original line, it actually collapses to an empty polygon.
In answer to your actual question - how do you get the original line back - there isn't an easy way. Certainly Shapely provides no methods to do this.
Best Answer
I'm assuming you want each pixel point along each line. You can do this by interpolating each point along a distance of 1.0 units along the line. This might need to be refined, but try:
Gives you:
You may also be interested in
rasterize()
from rasterio to burn the shape of geometries into a raster image. It's a bit more complicated, as you would need to define an affine transform for the bounds of the geometry.