当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python cuspatial.GeoArrowBuffers用法及代码示例


用法:

class cuspatial.GeoArrowBuffers(data: typing.Union[dict, cuspatial.geometry.geoarrowbuffers.T], data_locale: object = <module 'cudf' from '/opt/conda/envs/rapids/lib/python3.9/site-packages/cudf/__init__.py'>)

基础:object

GPU GeoArrowBuffers 对象。

参数

data一个 dict 或一个 GeoArrowBuffers 对象。
The GeoArrow format specifies a tabular data format for geometry
information. Supported types include `Point`, `MultiPoint`, `LineString`,
`MultiLineString`, `Polygon`, and `MultiPolygon`. In order to store
these coordinate types in a strictly tabular fashion, columns are
created for Points, MultiPoints, LineStrings, and Polygons.
MultiLines and MultiPolygons are stored in the same data structure
as LineStrings and Polygons. GeoArrowBuffers are constructed from a dict
of host buffers with accepted keys:
* points_xy
* points_z
* multipoints_xy
* multipoints_z
* multipoints_offsets
* lines_xy
* lines_z
* lines_offsets
* mlines
* polygons_xy
* polygons_z
* polygons_polygons
* polygons_rings
* mpolygons
There are no correlations in length between any of the above columns.
Accepted host buffer object types include python list and any type that
implements numpy’s `__array__interface__` protocol.
GeoArrow Format
GeoArrow format packs complex geometry types into 14 single-column Arrow
tables. This description is included for better understanding GeoArrow
format. Interacting with the GeoArrowBuffers is only required if you want
to convert cudf data to GeoPandas objects without starting from GeoPandas.
The points geometry is the simplest: N points are stored in a length 2*N
buffer with interleaved x,y coordinates. An optional z buffer of length N
can be used.
The multipoints geometry is the second simplest - identical to points,
with the addition of a multipoints_offsets buffer. The offsets buffer
stores N+1 indexes. The first multipoint is specified by 0, which is always
stored in offsets[0], and offsets[1], which is the length in points of
the first multipoint geometry. Subsequent multipoints are the prefix-sum of
the lengths of previous multipoints.
Consider::
缓冲区 = GeoArrowBuffers({
“multipoints_xy”:

[0, 0, 0, 1, 0, 2, 1, 0, 1, 1, 1, 2, 2, 0, 2, 1, 2, 2],

“multipoints_offsets”:

[0, 6, 12, 18]

})

which encodes the following GeoPandas Series::
系列 = geopandas.Series([

多点((0, 0), (0, 1), (0, 2)), 多点((1, 0), (1, 1), (1, 2)), 多点((2, 0), (2, 1), (2, 2)),

])

LineString geometry is more complicated than multipoints because the
format allows for the use of LineStrings and MultiLineStrings in the same
buffer, via the mlines key::
缓冲区 = GeoArrowBuffers({
“lines_xy”:
[0, 0, 0, 1, 0, 2, 1, 0, 1, 1, 1, 2, 2, 0, 2, 1, 2, 2, 3, 0,

3, 1, 3, 2, 4, 0, 4, 1, 4, 2],

“lines_offsets”:

[0, 6, 12, 18, 24, 30],

“mlines”:

[1, 3]

})

Which encodes a GeoPandas Series::
系列 = geopandas.Series([

LineString((0, 0), (0, 1), (0, 2)), MultiLineString([(1, 0), (1, 1), (1, 2)],

[(2, 0), (2, 1), (2, 2)],

) LineString((3, 0), (3, 1), (3, 2)), LineString((4, 0), (4, 1), (4, 2)),

])

Polygon geometry includes `mpolygons` for MultiPolygons similar to the
LineString geometry. Polygons are encoded using the same format as
Shapefiles, with left-wound external rings and right-wound internal rings.
An exact example of `GeoArrowBuffers` to `geopandas.Series` is left to the
reader as an exercise. Convert any GeoPandas `Series` or `DataFrame` with
`cuspatial.from_geopandas(geopandas_object)`.

注意

传统的尖顶算法依赖于分开的 x 和 y 列。使用.x.y 属性访问它们。

例子

GeoArrowBuffers 接受一个字典作为参数。有效键在上面的项目符号列表中。有效值是实现 numpy 的 __array_interface__ 的任何数据类型。支持四种基本几何类型中的任何一种或全部作为参数:

buffers = GeoArrowBuffers({
    "points_xy":
        [0, 0, 0, 1, 0, 2, 1, 0, 1, 1, 1, 2, 2, 0, 2, 1, 2, 2],
    "multipoints_xy":
        [0, 0, 0, 1, 0, 2, 1, 0, 1, 1, 1, 2, 2, 0, 2, 1, 2, 2],
    "multipoints_offsets":
        [0, 6, 12, 18]
    "lines_xy":
        [0, 0, 0, 1, 0, 2, 1, 0, 1, 1, 1, 2, 2, 0, 2, 1, 2, 2, 3, 0,
         3, 1, 3, 2, 4, 0, 4, 1, 4, 2],
    "lines_offsets":
        [0, 6, 12, 18, 24, 30],
    "mlines":
        [1, 3]
    "polygons_xy":
        [0, 0, 0, 1, 0, 2, 1, 0, 1, 1, 1, 2, 2, 0, 2, 1, 2, 2, 3, 0,
         3, 1, 3, 2, 4, 0, 4, 1, 4, 2],
    "polygons_polygons": [0, 1, 2],
    "polygons_rings": [0, 1, 2],
    "mpolygons": [1, 3],
})

或另一个 GeoArrowBuffers:

buffers2 = GeoArrowBuffers(buffers)

属性

lines

包含坐标列、偏移列和 mlines 列。

multipoints

与添加了偏移量列的点列类似。

points

一个简单的数字列。

polygons

包含坐标列、指定每个多边形的开始和结束的环列、指定每个多边形的开始或外部环和结束环的多边形列。

相关用法


注:本文由纯净天空筛选整理自rapids.ai大神的英文原创作品 cuspatial.GeoArrowBuffers。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。