This is different than simply containing, overlapping, etc. For example, imagine a circle partially overlapping a square:

enter image description here

The circle and square both overlap each other, both intersect each other, but only the circle has vertices within the square. (The square only has four vertices, none of which are inside the circle. In practice, since I'm dealing with convex hulls that are creating arcs, the "circle" would be a high-N N-gon).

How can I check for this condition? I was hoping one of Shapely's polygon methods would help, but they don't seem to answer this question. I also tried using difference in both directions and seeing which one contained all the points of the other, but this not only is very slow but is prone to making accidental holes in the output shapefiles later.

I plan to ultimately end up with a result like this, in case it is helpful:

enter image description here

but it'll be done to a dynamic number of dynamically placed centroid-esque shapes

1 Answer 1


You would have to iterate each vertex of both reference and text polygon. If you are checking reference polygon (lets take it a square in your example), you take each vertex and check if it is within circle (i.e. N-polygon). After that you iterate circle vertices and check each of them with square geometry. Here is non-tested code (just for the idea). One function you can call it twice, just switch polygon orders to check both options. If you have multiple rings, than you would need to add two more level for loops (one for iterating interior rings and other to iterate its vertices).

from shapely.geometry Polygon, Point

def getVerticesWithinPolygon(refPolygon, testPolygon):
  result = []
  for vertex in polygon.exterior.cords:
    if vertex.within(testPolygon):

  return result
  • This is basically what I ended up doing, but I felt sure that there had to be something cleverer and it was just my lack of familiarity with these libraries that was making me miss it. Thanks! Feb 25, 2019 at 18:24
  • Usually the simplest solution is the best. If you don't have so many data I think it will work just fine. My approach is first to get it working and then I try to optimizer or find better solution. Feb 26, 2019 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.