GDAL

ogrlayerarrow.h
1/******************************************************************************
2 *
3 * Project: OpenGIS Simple Features Reference Implementation
4 * Purpose: Parts of OGRLayer dealing with Arrow C interface
5 * Author: Even Rouault, <even dot rouault at spatialys.com>
6 *
7 ******************************************************************************
8 * Copyright (c) 2023, Even Rouault <even dot rouault at spatialys.com>
9 *
10 * SPDX-License-Identifier: MIT
11 ****************************************************************************/
12
13#ifndef OGRLAYERARROW_H_DEFINED
14#define OGRLAYERARROW_H_DEFINED
15
16#include "cpl_port.h"
17
18#include <map>
19#include <string>
20
21#include "ogr_recordbatch.h"
22
23 constexpr const char *ARROW_EXTENSION_NAME_KEY = "ARROW:extension:name";
24 constexpr const char *ARROW_EXTENSION_METADATA_KEY = "ARROW:extension:metadata";
25 constexpr const char *EXTENSION_NAME_OGC_WKB = "ogc.wkb";
26 constexpr const char *EXTENSION_NAME_GEOARROW_WKB = "geoarrow.wkb";
27 constexpr const char *EXTENSION_NAME_ARROW_JSON = "arrow.json";
28
29std::map<std::string, std::string>
30 CPL_DLL OGRParseArrowMetadata(const char *pabyMetadata);
31
32 bool CPL_DLL OGRCloneArrowArray(const struct ArrowSchema *schema,
33 const struct ArrowArray *array,
34 struct ArrowArray *out_array);
35
36 bool CPL_DLL OGRCloneArrowSchema(const struct ArrowSchema *schema,
37 struct ArrowSchema *out_schema);
38
40 class OGRArrowArrayStream
41{
42 public:
44 inline OGRArrowArrayStream()
45 {
46 memset(&m_stream, 0, sizeof(m_stream));
47 }
48
50 inline ~OGRArrowArrayStream()
51 {
52 clear();
53 }
54
56 // cppcheck-suppress functionStatic
57 inline void clear()
58 {
59 if (m_stream.release)
60 {
61 m_stream.release(&m_stream);
62 m_stream.release = nullptr;
63 }
64 }
65
67 inline ArrowArrayStream *get()
68 {
69 return &m_stream;
70 }
71
73 // cppcheck-suppress functionStatic
74 inline int get_schema(struct ArrowSchema *schema)
75 {
76 return m_stream.get_schema(&m_stream, schema);
77 }
78
80 // cppcheck-suppress functionStatic
81 inline int get_next(struct ArrowArray *array)
82 {
83 return m_stream.get_next(&m_stream, array);
84 }
85
87 inline OGRArrowArrayStream &operator=(OGRArrowArrayStream &&other)
88 {
89 if (this != &other)
90 {
91 clear();
92 memcpy(&m_stream, &(other.m_stream), sizeof(m_stream));
93 memset(&(other.m_stream), 0, sizeof(m_stream));
94 }
95 return *this;
96 }
97
98 private:
99 struct ArrowArrayStream m_stream
100 {
101 };
102
103 OGRArrowArrayStream(const OGRArrowArrayStream &) = delete;
104 OGRArrowArrayStream(OGRArrowArrayStream &&) = delete;
105 OGRArrowArrayStream &operator=(const OGRArrowArrayStream &) = delete;
106};
107
108#endif // OGRLAYERARROW_H_DEFINED
OGRArrowArrayStream
C++ wrapper on top of ArrowArrayStream.
Definition ogrlayerarrow.h:41
OGRArrowArrayStream::get
ArrowArrayStream * get()
Return the raw ArrowArrayStream*.
Definition ogrlayerarrow.h:67
OGRArrowArrayStream::get_next
int get_next(struct ArrowArray *array)
Get the next ArrowArray batch.
Definition ogrlayerarrow.h:81
OGRArrowArrayStream::get_schema
int get_schema(struct ArrowSchema *schema)
Get the schema.
Definition ogrlayerarrow.h:74
OGRArrowArrayStream::operator=
OGRArrowArrayStream & operator=(OGRArrowArrayStream &&other)
Move assignment operator.
Definition ogrlayerarrow.h:87
OGRArrowArrayStream::OGRArrowArrayStream
OGRArrowArrayStream()
Constructor: instantiate an empty ArrowArrayStream
Definition ogrlayerarrow.h:44
OGRArrowArrayStream::clear
void clear()
Call release() on the ArrowArrayStream if not already done.
Definition ogrlayerarrow.h:57
OGRArrowArrayStream::~OGRArrowArrayStream
~OGRArrowArrayStream()
Destructor: call release() on the ArrowArrayStream if not already done.
Definition ogrlayerarrow.h:50
cpl_port.h
Core portability definitions for CPL.