Geometric objects are created in the typical Python fashion, using the classes themselves as instance factories. A few of their intrinsic properties will be discussed in this sections, others in the following sections on operations and serializations.
几何对象是以典型的 Python 方式创建的,使用类来实例化。它们的一些内在属性将在本节中讨论,其他的将在下面关于操作和序列化的章节中讨论。
Instances of Point
, LineString
, and LinearRing
have as their most important attribute a finite sequence of coordinates that determines their interior, boundary, and exterior point sets. A line string can be determined by as few as 2 points, but contains an infinite number of points. Coordinate sequences are immutable. A third z coordinate value may be used when constructing instances, but has no effect on geometric analysis. All operations are performed in the x-y plane.
Point、LineString和LinearRing实例最重要的属性是一个决定了其的内部、边界和外部点集的有限序列的坐标。一个线由少至2个点决定,但包含无限多的点。坐标序列是不可改变的。在构造实例时可以使用第三维Z坐标值,但对几何分析没有影响。所有操作都在x-y二维平面内进行。
In all constructors, numeric values are converted to type float
. In other words, Point(0, 0)
and Point(0.0, 0.0)
produce geometrically equivalent instances. Shapely does not check the topological simplicity or validity of instances when they are constructed as the cost is unwarranted in most cases. Validating factories are easily implemented using the :attr:is_valid
predicate by users that require them.
在所有的构造函数中,数字值被转换为float
浮点类型。换句话说,Point(0, 0)和Point(0.0, 0.0)会产生等同的几何实例。Shapely在构造实例时不检查其拓扑结构的有效性,因为在大多数情况下是不必要的。可以使用:attr:is_valid
谓词对几何实例的有效性进行验证。
Note:
Shapely is a planar geometry library and z, the height above or below the plane, is ignored in geometric analysis. There is a potential pitfall for users here: coordinate tuples that differ only in z are not distinguished from each other and their application can result in surprisingly invalid geometry objects. For example, LineString([(0, 0, 0), (0, 0, 1)])
does not return a vertical line of unit length, but an invalid line in the plane with zero length. Similarly, Polygon([(0, 0, 0), (0, 0, 1), (1, 1, 1)])
is not bounded by a closed ring and is invalid.
Shapely是一个平面几何库,在几何分析中忽略了z,即平面上或平面下的高度。这里对用户来说有一个潜在的问题:只在z上有差异的坐标图元是不能相互区分的,它们的应用会导致无效的几何对象。例如,LineString([(0, 0, 0), (0, 0, 1)])不会返回一条单位长度的垂直线,而是返回平面内一条长度为零的无效线。同样,Polygon([(0, 0, 0), (0, 0, 1), (1, 1, 1)])没有被一个封闭的环所包围,是无效的。