I am trying to use shapely to find the intersection of a line and a polygon, but I am having problems with some floating point numbers.
Code example:
polygon = [(4.0, -2.0), (5.0, -2.0), (4.0, -3.0), (3.0, -3.0), (4.0, -2.0)] shapely_poly = shapely.geometry.Polygon(polygon) line = [(4.0, -2.0000000000000004), (2.0, -1.1102230246251565e-15)] shapely_line = shapely.geometry.LineString(line) intersection_line = list(shapely_poly.intersection(shapely_line).coords) print intersection_line
What I expect is a list of two peaks.
Point 1: the point that will be inside the polygon, or (4.0, -2.0000000000000004) in this case.
Point 2: the point that is the intersection of [(4.0, -2.0000000000000004), (2.0, -1.1102230246251565e-15)] and [(3.0, -3.0), (4.0, -2.0)].
However, I get the result:
[(4.0, -2.0000000000000004)]
I also checked if there is any intersection with the edge I am looking at:
>>> edge = shapely.geometry.LineString([(3.0, -3.0), (4.0, -2.0)]) >>> edge.intersects(shapely_line) False
If I replaced (4.0, -2.0000000000000004) with (4.0, -2.000000000000000), then the intersection of the edges will be evaluated as True.
Does anyone have any ideas on what is happening or what I don't see? Thanks!

Edit:
I tested using the beautiful version 1.12 and geography 3.3.1, 3.3.5, 3.3.6, 3.3.7.
If anyone is interested in how I updated the version of geoinformation in Windows:
Download the geos- [version] .tar.bz2 file from the GEOS website. Extract the files and run CMake on it using the Visual Studio 10 Win64 generator. After opening the .sln file and building it, he moved the created geos_c.dll file and pasted it on top of where geos_c.dll was installed correctly in the Python directory.