1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Find coordinate of the closest point on polygon in Shapely

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    Say I have the following Polygon and Point:

    >>> poly = Polygon([(0, 0), (2, 8), (14, 10), (6, 1)])
    >>> point = Point(12, 4)


    [​IMG]

    I can calculate the point's distance to the polygon...

    >>> dist = point.distance(poly)
    >>> print(dist)
    2.49136439561


    ...but I would like to know the coordinate of the point on the polygon border where that shortest distance measures to.

    My initial approach is to buffer the point by its distance to the polygon, and find the point at which that circle is tangent to the polygon:

    >>> buff = point.buffer(dist)


    [​IMG] However, I'm not sure how to calculate that point. The two polygon's don't intersect so list(poly.intersection(buff)) will not give me that point.

    Am I on the right track with this? Is there a more straightforward method?

    Continue reading...

Compartilhe esta Página