Shapely 2.0.0 中文文档

  1. 主页
  2. 文档
  3. Shapely 2.0.0 中文文档
  4. User Manual
  5. Other Operations(其他操作)
  6. Diagnostics(诊断)

Diagnostics(诊断)

  • validation.explain_validity(ob):

Returns a string explaining the validity or invalidity of the object.

返回阐明该对象有效性或无效性的一个字符串。

New in version 1.2.1.

The messages may or may not have a representation of a problem point that can be parsed out.

这些信息可能有也可能没有解析出来问题。

>>> coords = [(0, 0), (0, 2), (1, 1), (2, 2), (2, 0), (1, 1), (0, 0)]
>>> p = Polygon(coords)
>>> from shapely.validation import explain_validity
>>> explain_validity(p)
'Ring Self-intersection[1 1]'
  • validation.make_valid(ob)

Returns a valid representation of the geometry, if it is invalid. If it is valid, the input geometry will be returned.

如果是无效的,返回一个有效的几何对象。如果是有效的,将返回输入的几何对象自身。

In many cases, in order to create a valid geometry, the input geometry must be split into multiple parts or multiple geometries. If the geometry must be split into multiple parts of the same geometry type, then a multi-part geometry (e.g. a MultiPolygon) will be returned. if the geometry must be split into multiple parts of different types, then a GeometryCollection will be returned.

在许多情况下,为了创建一个有效的几何对象,输入的几何对象必须被分割成多个部分或多个几何对象。如果几何对象必须被分割成相同的几何对象类型的多个部分,那么将返回一个多部分的几何对象(如MultiPolygon)。如果几何对象必须被分割成不同类型的多个部分,那么将返回一个几何集合。

For example, this operation on a geometry with a bow-tie structure:

例如,对一个具有蝴蝶领结形状的几何对象执行该操作。

>>> from shapely.validation import make_valid
>>> coords = [(0, 0), (0, 2), (1, 1), (2, 2), (2, 0), (1, 1), (0, 0)]
>>> p = Polygon(coords)
>>> make_valid(p)
<MULTIPOLYGON (((1 1, 0 0, 0 2, 1 1)), ((2 0, 1 1, 2 2, 2 0)))>

Yields a MultiPolygon with two parts:

(Source codepnghires.pngpdf)

While this operation:
>>> from shapely.validation import make_valid
>>> coords = [(0, 2), (0, 1), (2, 0), (0, 0), (0, 2)]
>>> p = Polygon(coords)
>>> make_valid(p)
<GEOMETRYCOLLECTION (POLYGON ((2 0, 0 0, 0 1, 2 0)), LINESTRING (0 2, 0 1))>

Yields a GeometryCollection with a Polygon and a LineString:

(Source codepnghires.pngpdf)

New in version 1.8  Requires GEOS > 3.8

The Shapely version, GEOS library version, and GEOS C API version are accessible via shapely.__version__shapely.geos_version_string, and shapely.geos_capi_version.

Shapely版本、GEOS库版本和GEOS C API版本可以通过shapely.version、shapely.geos_version_string和shapely.geos_capi_version访问。

>>> import shapely
>>> shapely.__version__  
'2.0.0'
>>> shapely.geos_version  
(3, 10, 2)
>>> shapely.geos_capi_version_string  
'3.10.2-CAPI-1.16.0'
标签 ,
这篇文章对您有用吗?

我们要如何帮助您?

欢迎留下您的宝贵建议

Please enter your comment!
Please enter your name here