Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading