質問

I'm pretty new to Python so the answer to this question is probably quite simple, but I've looked everywhere and tried a lot but couldn't find the answer.

Simplifying a polygon using Shapely may result in an empty polygon. I want to replace the polygon with a point if the polygon is empty. Something that would work like:

if mypoly is empty:
    mypoly = [(0,0)]
役に立ちましたか?

解決

Given that mypoly is a shapely polygon, you can check if it's empty using is_empty which is built in to Shapely to check for empty ones.

from shapely.geometry import Point

if mypoly.is_empty:
    mypoly = Point(0, 0)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top