如何在Shapely中检查多边形是否为空? [英] How to check if a polygon is empty in Shapely?

查看:122
本文介绍了如何在Shapely中检查多边形是否为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Python来说还很陌生,所以这个问题的答案可能很简单,但是我四处寻找并尝试了很多,但找不到答案.

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.

使用Shapely简化多边形可能会导致一个空的多边形.如果多边形为空,我想用一个点替换多边形.像这样的东西:

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)]

推荐答案

鉴于mypoly是形状多边形,您可以使用Shapely内置的is_empty检查其是否为空.

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)

这篇关于如何在Shapely中检查多边形是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆