- 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)
>>> str(make_valid(p))
'MULTIPOLYGON (((0 0, 0 2, 1 1, 0 0)), ((1 1, 2 2, 2 0, 1 1)))'
Yields a MultiPolygon with two parts:
(Source code, png, hires.png, pdf)
While this operation:
>>> from shapely.validation import make_valid
>>> coords = [(0, 2), (0, 1), (2, 0), (0, 0), (0, 2)]
>>> p = Polygon(coords)
>>> str(make_valid(p))
Yields a GeometryCollection with a Polygon and a LineString:
(Source code, png, hires.png, pdf)
The Shapely version, GEOS library version, and GEOS C API version are accessible via shapely.__version__
, shapely.geos.geos_version_string
, and shapely.geos.geos_capi_version
.
Shapely版本、GEOS库版本和GEOS C API版本可以通过shapely.version、shapely.geos.geos_version_string和shapely.geos.geos_capi_version访问。
>>> import shapely
>>> shapely.__version__
'1.3.0'
>>> import shapely.geos
>>> shapely.geos.geos_version
(3, 3, 0)
>>> shapely.geos.geos_version_string
'3.3.0-CAPI-1.7.0'