當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。