All geometric objects with coordinate sequences (Point, LinearRing, LineString) provide the Numpy array interface and can thereby be converted or adapted to Numpy arrays.
所有具有坐标序列的几何对象(Point, LinearRing, LineString)都提供了Numpy数组接口,因此可以转换为Numpy数组。
>>> from numpy import asarray
>>> asarray(Point(0, 0))
array([ 0., 0.])
>>> asarray(LineString([(0, 0), (1, 1)]))
array([[ 0., 0.],
[ 1., 1.]])
Note |
The Numpy array interface is provided without a dependency on Numpy itself. Numpy数组接口并不依赖于Numpy本身。 |
The coordinates of the same types of geometric objects can be had as standard Python arrays of x and y values via the xy
attribute.
通过xy属性,同种类型的几何对象的坐标可以作为标准的Python的x、y值数组。
>>> Point(0, 0).xy
(array('d', [0.0]), array('d', [0.0]))
>>> LineString([(0, 0), (1, 1)]).xy
(array('d', [0.0, 1.0]), array('d', [0.0, 1.0]))
The shapely.geometry.asShape()
family of functions can be used to wrap Numpy coordinate arrays so that they can then be analyzed using Shapely while maintaining their original storage. A 1 x 2 array can be adapted to a point
shapely.geometry.asShape()系列函数可以用来转换Numpy坐标数组,这样它们就可以在保持原始存储的情况下用Shapely进行分析。一个1 x 2的数组可以被采纳为一个点
>>> from shapely.geometry import asPoint
>>> pa = asPoint(array([0.0, 0.0]))
>>> pa.wkt
'POINT (0.0000000000000000 0.0000000000000000)'
and a N x 2 array can be adapted to a line string
而一个N×2的数组可以被采纳为一条线
>>> from shapely.geometry import asLineString
>>> la = asLineString(array([[1.0, 2.0], [3.0, 4.0]]))
>>> la.wkt
'LINESTRING (1.0000000000000000 2.0000000000000000, 3.0000000000000000 4.0000000000000000)'
Polygon and MultiPoint can also be created from N x 2 arrays:
Polygon和MultiPoint也可以从N x 2数组中创建。
>>> from shapely.geometry import asMultiPoint
>>> ma = asMultiPoint(np.array([[1.1, 2.2], [3.3, 4.4], [5.5, 6.6]]))
>>> ma.wkt
'MULTIPOINT (1.1 2.2, 3.3 4.4, 5.5 6.6)'
>>> from shapely.geometry import asPolygon
>>> pa = asPolygon(np.array([[1.1, 2.2], [3.3, 4.4], [5.5, 6.6]]))
>>> pa.wkt
'POLYGON ((1.1 2.2, 3.3 4.4, 5.5 6.6, 1.1 2.2))'