How to check if a polygon is empty in Shapely?

I am pretty new to Python, so the answer to this question is probably pretty simple, but I searched everywhere and tried a lot, but could not find the answer.

Simplifying a polygon with Shapely can result in an empty polygon. I want to replace the polygon with a dot if it is empty. What will work like:

if mypoly is empty: mypoly = [(0,0)] 
+8
source share
1 answer

Given that mypoly is a beautiful polygon, you can check if it is empty using is_empty , which is built into Shapely to check for empty ones.

 from shapely.geometry import Point if mypoly.is_empty: mypoly = Point(0, 0) 
+8
source

Source: https://habr.com/ru/post/957445/


All Articles