Shapely 1.8.5 中文文档

  1. 主页
  2. 文档
  3. Shapely 1.8.5 中文文档
  4. Migrating to Shapely 1.8 / 2.0(迁移到Shapely 1.8 / 2.0版本)
  5. Consistent creation of empty geometries(创建空的几何对象)

Consistent creation of empty geometries(创建空的几何对象)

Shapely 1.x is inconsistent in creating empty geometries between various creation methods. A small example for an empty Polygon geometry:

Shapely 1.x在各种创建方法中创建的空几何对象是不一致的。一个关于创建空多边形几何对象的小例子:

# Using an empty constructor results in a GeometryCollection
# 使用一个空的构造函数产生一个几何集合
>>> from shapely.geometry import Polygon
>>> g1 = Polygon()
>>> type(g1)
<class 'shapely.geometry.polygon.Polygon'>
>>> g1.wkt
GEOMETRYCOLLECTION EMPTY

# Converting from WKT gives a correct empty polygon
# 从WKT转换得到一个正确的空多边形
>>> from shapely import wkt
>>> g2 = wkt.loads("POLYGON EMPTY")
>>> type(g2)
<class 'shapely.geometry.polygon.Polygon'>
>>> g2.wkt
POLYGON EMPTY

Shapely 1.8 does not yet change this inconsistent behaviour, but starting with Shapely 2.0, the different methods will always consistently give an empty geometry object of the correct type, instead of using an empty GeometryCollection as “generic” empty geometry object.

Shapely 1.8还没有改变这种不一致的行为,但从Shapely 2.0开始,不同的方法将总是一致地给出一个正确类型的空几何对象,而不是使用一个空的GeometryCollection作为 “通用 “的空几何对象。

How do I update my code? Those cases that will change don’t raise a warning, but you will need to update your code if you rely on the fact that empty geometry objects are of the GeometryCollection type. Use the .is_empty attribute for robustly checking if a geometry object is an empty geometry.

我怎样才能更新我的代码?那些会改变的情况不会引起警告,但如果你依赖空几何对象是GeometryCollection类型的事实,你将需要更新你的代码。使用.is_empty属性来稳健地检查一个几何体对象是否是空的几何体。

In addition, the WKB serialization methods will start supporting empty Points (using "POINT (NaN NaN)" to represent an empty point).

此外,WKB的序列化方法将开始支持空点(使用 “POINT (NaN NaN) “来表示一个空点)。

标签 ,
这篇文章对您有用吗?

我们要如何帮助您?

欢迎留下您的宝贵建议

Please enter your comment!
Please enter your name here