Find polygon centroid with Shapely given vertices with lat, lon

Trying to find the centroid of Polygon with Shapely but I do not understand how to tell the library that the vertices are (lon, lat). Perhaps I need to set a projection?

Here is my code:

from shapely.geometry import Polygon, Point

# LON, LAT
vertices = [
    Point(-79.8726944444444, 8.68505555555556),
    Point(-79.8733888888889, 8.50419444444444),
    Point(-79.54552777777779, 8.68386111111111),
    Point(-79.54622222222221, 8.503),
    Point(-79.8726944444444, 8.68505555555556),
]

p1 = Polygon(vertices)
centroid = p1.centroid
print(centroid)

# POINT (-1805804163717.8823 6592764402.930745) 

The result is clearly wrong.

>Solution :

It’s a degenerate shape. It’s bowtie that crosses itself. Shapely can’t handle that.

Leave a Reply