Skip to content

Commit 86fb413

Browse files
committed
first pass on view types
1 parent c61b1eb commit 86fb413

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

geoarrow-types/src/geoarrow/types/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
large_wkb,
1818
wkt,
1919
large_wkt,
20+
wkb_view,
21+
wkt_view,
2022
box,
2123
point,
2224
linestring,
@@ -42,6 +44,8 @@
4244
"large_wkb",
4345
"wkt",
4446
"large_wkt",
47+
"wkb_view",
48+
"wkt_view",
4549
"geoarrow",
4650
"box",
4751
"point",

geoarrow-types/src/geoarrow/types/constants.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ class Encoding(TypeSpecEnum):
9191
LARGE_WKT = 4
9292
"""Well-known text encoding with 64-bit offsets"""
9393

94-
GEOARROW = 5
94+
WKB_VIEW = 5
95+
"""Well-known binary encoding using binary views as a storage type"""
96+
97+
WKT_VIEW = 6
98+
"""Well-known binary encoding using string views as a storage type"""
99+
100+
GEOARROW = 7
95101
"""GeoArrow native nested list encoding"""
96102

97103
def is_serialized(self):
@@ -100,6 +106,8 @@ def is_serialized(self):
100106
Encoding.LARGE_WKB,
101107
Encoding.WKT,
102108
Encoding.LARGE_WKT,
109+
Encoding.WKB_VIEW,
110+
Encoding.WKT_VIEW
103111
)
104112

105113

geoarrow-types/src/geoarrow/types/type_pyarrow.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,10 @@ def _parse_storage(storage_type):
558558
return [("string", ())]
559559
elif pa_types.is_large_string(storage_type):
560560
return [("large_string", ())]
561+
elif hasattr(pa_types, "is_binary_view") and pa_types.is_binary_view(storage_type):
562+
return [("binary_view", ())]
563+
elif hasattr(pa_types, "is_string_view") and pa_types.is_string_view(storage_type):
564+
return [("string_view", ())]
561565
elif pa_types.is_float64(storage_type):
562566
return [("double", ())]
563567
elif isinstance(storage_type, pa.ListType):
@@ -925,9 +929,9 @@ def _add_union_types_to_native_storage_types():
925929

926930
for coord_type in ALL_COORD_TYPES:
927931
for dimension in ALL_DIMENSIONS:
928-
_NATIVE_STORAGE_TYPES[
929-
(GeometryType.GEOMETRY, coord_type, dimension)
930-
] = _generate_union_storage(coord_type=coord_type, dimensions=[dimension])
932+
_NATIVE_STORAGE_TYPES[(GeometryType.GEOMETRY, coord_type, dimension)] = (
933+
_generate_union_storage(coord_type=coord_type, dimensions=[dimension])
934+
)
931935

932936
# With unknown dimensions, we reigster the massive catch-all union
933937
_NATIVE_STORAGE_TYPES[
@@ -1014,6 +1018,10 @@ def _spec_short_repr(spec, ext_name):
10141018
Encoding.LARGE_WKB: pa.large_binary(),
10151019
}
10161020

1021+
if hasattr(pa, "binary_view"):
1022+
_SERIALIZED_STORAGE_TYPES[Encoding.WKT_VIEW] = pa.string_view()
1023+
_SERIALIZED_STORAGE_TYPES[Encoding.WKB_VIEW] = pa.binary_view()
1024+
10171025
_NATIVE_STORAGE_TYPES = _generate_storage_types()
10181026
_add_union_types_to_native_storage_types()
10191027

@@ -1022,6 +1030,8 @@ def _spec_short_repr(spec, ext_name):
10221030
("large_binary",): Encoding.LARGE_WKB,
10231031
("string",): Encoding.WKT,
10241032
("large_string",): Encoding.LARGE_WKT,
1033+
("binary_view",): Encoding.WKB_VIEW,
1034+
("string_view",): Encoding.WKT_VIEW,
10251035
("struct",): TypeSpec(
10261036
encoding=Encoding.GEOARROW,
10271037
geometry_type=GeometryType.POINT,

geoarrow-types/src/geoarrow/types/type_spec.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,22 @@ def wkb(*, edge_type=None, crs=crs.UNSPECIFIED) -> TypeSpec:
357357
def large_wkb(*, edge_type=None, crs=crs.UNSPECIFIED) -> TypeSpec:
358358
"""Large well-known binary encoding
359359
360-
Create a :class:`TypeSpec` denoting a well-known binary type with
360+
Create a :class:`TypeSpec` denoting a well-known binary type with
361361
64-bit data offsets. See :func:`type_spec` for parameter definitions.
362362
"""
363363
return type_spec(encoding=Encoding.LARGE_WKB, edge_type=edge_type, crs=crs)
364364

365365

366+
def wkb_view(*, edge_type=None, crs=crs.UNSPECIFIED) -> TypeSpec:
367+
"""Well-known binary view encoding
368+
369+
Create a :class:`TypeSpec` denoting a well-known binary type using
370+
binary views as the underlying storage type. See :func:`type_spec`
371+
for parameter definitions.
372+
"""
373+
return type_spec(encoding=Encoding.WKB_VIEW, edge_type=edge_type, crs=crs)
374+
375+
366376
def wkt(*, edge_type=None, crs=crs.UNSPECIFIED) -> TypeSpec:
367377
"""Well-known text encoding
368378
@@ -381,6 +391,16 @@ def large_wkt(*, edge_type=None, crs=crs.UNSPECIFIED) -> TypeSpec:
381391
return type_spec(encoding=Encoding.LARGE_WKT, edge_type=edge_type, crs=crs)
382392

383393

394+
def wkt_view(*, edge_type=None, crs=crs.UNSPECIFIED) -> TypeSpec:
395+
"""Well-known text encoding
396+
397+
Create a :class:`TypeSpec` denoting a well-known text type using
398+
string views as the underlying storage type. See :func:`type_spec`
399+
for parameter definitions.
400+
"""
401+
return type_spec(encoding=Encoding.WKT_VIEW, edge_type=edge_type, crs=crs)
402+
403+
384404
def geoarrow(
385405
*,
386406
geometry_type=None,
@@ -619,6 +639,8 @@ def type_spec(
619639
Encoding.LARGE_WKB: "geoarrow.wkb",
620640
Encoding.WKT: "geoarrow.wkt",
621641
Encoding.LARGE_WKT: "geoarrow.wkt",
642+
Encoding.WKB_VIEW: "geoarrow.wkb",
643+
Encoding.WKT_VIEW: "geoarrow.wkt",
622644
}
623645

624646
_GEOARROW_EXT_NAMES = {

geoarrow-types/tests/test_type_pyarrow.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ def test_multipolygon_array_from_geobuffers():
441441
gt.large_wkt(),
442442
gt.wkb(),
443443
gt.large_wkb(),
444+
gt.wkt_view(),
445+
gt.wkb_view(),
444446
# Geometry types
445447
gt.box(),
446448
gt.point(),

0 commit comments

Comments
 (0)