Determining if point on boundary using shapely? [closed]

I'm new to Python, and I want to test if a certain point lies ON the (boundary) of a polygon - not inside, not outside, just if it's on the boundary. The points and polygon already defined

``````polygon = [(3, 2), (5, 1), (7, 2), (8, 6), (9, 7), (11, 6), (10, 4), (12, 2), (15, 2), (16, 5), (19, 7), (18, 11), (14, 12), (11, 9), (5, 9), (2, 6)]
Point_X = 14
Point_Y = 12
``````

this point should be a boundary. How can I do that?

• Welcome to GIS SE. Thank you for taking the Tour. Due to the imprecision associated with floating-point values, far fewer points which are "on" a line will actually be reported as such in real-world situations. If you want to test this, your code needs to use ArcPy functions to assemble `Polygon` and `PointGeometry` objects, so that you can cast the Polygon to a line (using `Geometry.boundary()`) and test for point intersection with `Geometry.contains()`. Be sure to specify an appropriate `SpatialReference`. Commented Jan 14, 2018 at 19:37
• You had a tag for ArcPy but your question body and title make no mention that it is being used so I am removing it.
– PolyGeo
Commented Jan 14, 2018 at 20:22
• I'm also adding a tag for shapely to match the answer. If you are not using that library then please ask a new and more focused question.
– PolyGeo
Commented Jan 14, 2018 at 21:18
• @PolyGeo You've altered the question twice to make it fit an answer that did not help the OP, and in so doing, made my comment nonsensical. This was not a greatest moment in moderation. Commented Jan 15, 2018 at 12:25
• @PolyGeo Saw that. Busy day here today, and probably tomorrow. I'll see if I can do better while caged at home after the snow storm. Commented Jan 16, 2018 at 5:19

Here's an example using shapely, based on the shapely documentation. https://shapely.readthedocs.io/en/stable/manual.html#binary-predicates

``````from shapely import geometry

polygon = [(3, 2), (5, 1), (7, 2), (8, 6), (9, 7), (11, 6), (10, 4), (12, 2), (15, 2), (16, 5), (19, 7), (18, 11), (14, 12), (11, 9), (5, 9), (2, 6)]
Point_X = 14
Point_Y = 12

line = geometry.LineString(polygon)
point = geometry.Point(Point_X, Point_Y)

print(line.contains(point))
``````
• The original question was unclear, but it was tagged "arcpy", which was an indication that this answer would not be useful to the OP. Please hold off on answering unclear questions, since it is not usual that a question is altered to make the inappropriate answer correct. Commented Jan 15, 2018 at 12:17
• Doc URL mentioned above is now at: shapely.readthedocs.io/en/stable/… Commented Oct 28, 2020 at 14:49