iceberg-cpp
Loading...
Searching...
No Matches
geospatial.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
24
25#include <cstdint>
26#include <optional>
27#include <span>
28#include <vector>
29
31#include "iceberg/result.h"
32#include "iceberg/type_fwd.h"
33
34namespace iceberg {
35
37class ICEBERG_EXPORT GeospatialBound {
38 public:
40 static GeospatialBound XY(double x, double y);
42 static GeospatialBound XYZ(double x, double y, double z);
44 static GeospatialBound XYM(double x, double y, double m);
46 static GeospatialBound XYZM(double x, double y, double z, double m);
47
49 double x() const { return x_; }
51 double y() const { return y_; }
53 const std::optional<double>& z() const { return z_; }
55 const std::optional<double>& m() const { return m_; }
56
58 static Result<GeospatialBound> Deserialize(std::span<const uint8_t> bytes);
60 std::vector<uint8_t> Serialize() const;
61
62 friend bool operator==(const GeospatialBound&, const GeospatialBound&) = default;
63
64 private:
65 GeospatialBound(double x, double y, std::optional<double> z, std::optional<double> m);
66
67 double x_;
68 double y_;
69 std::optional<double> z_;
70 std::optional<double> m_;
71};
72
74class ICEBERG_EXPORT BoundingBox {
75 public:
78
80 const GeospatialBound& lower() const { return lower_; }
82 const GeospatialBound& upper() const { return upper_; }
83
85 static Result<BoundingBox> Deserialize(std::span<const uint8_t> lower,
86 std::span<const uint8_t> upper);
88 static Result<BoundingBox> Deserialize(std::span<const uint8_t> bytes);
90 std::vector<uint8_t> Serialize() const;
91
92 friend bool operator==(const BoundingBox&, const BoundingBox&) = default;
93
94 private:
95 GeospatialBound lower_;
96 GeospatialBound upper_;
97};
98
102ICEBERG_EXPORT Result<bool> GeospatialBoundsIntersect(const Type& type,
103 const BoundingBox& lhs,
104 const BoundingBox& rhs);
105
106} // namespace iceberg
A pair of lower and upper geospatial column bounds.
Definition geospatial.h:74
static Result< BoundingBox > Deserialize(std::span< const uint8_t > lower, std::span< const uint8_t > upper)
Decode a bounding box from separate lower and upper encodings.
const GeospatialBound & lower() const
Return the lower bound.
Definition geospatial.h:80
const GeospatialBound & upper() const
Return the upper bound.
Definition geospatial.h:82
BoundingBox(GeospatialBound lower, GeospatialBound upper)
Create a bounding box from lower and upper bounds.
static Result< BoundingBox > Deserialize(std::span< const uint8_t > bytes)
Decode a bounding box from Iceberg's combined encoding.
std::vector< uint8_t > Serialize() const
Encode this bounding box using Iceberg's combined encoding.
A point used as a lower or upper geospatial column bound.
Definition geospatial.h:37
double y() const
Return the Y coordinate.
Definition geospatial.h:51
double x() const
Return the X coordinate.
Definition geospatial.h:49
static GeospatialBound XYZM(double x, double y, double z, double m)
Create a bound with Z and M coordinates.
static GeospatialBound XYM(double x, double y, double m)
Create a bound with an M coordinate.
const std::optional< double > & z() const
Return the optional Z coordinate.
Definition geospatial.h:53
static GeospatialBound XY(double x, double y)
Create a two-dimensional bound.
static GeospatialBound XYZ(double x, double y, double z)
Create a bound with a Z coordinate.
std::vector< uint8_t > Serialize() const
Encode this bound using little-endian encoding.
const std::optional< double > & m() const
Return the optional M coordinate.
Definition geospatial.h:55
static Result< GeospatialBound > Deserialize(std::span< const uint8_t > bytes)
Decode a little-endian geospatial bound.
Interface for a data type for a field.
Definition type.h:44
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
std::expected< T, E > Result
Result alias.
Definition result.h:88
ICEBERG_EXPORT Result< bool > GeospatialBoundsIntersect(const Type &type, const BoundingBox &lhs, const BoundingBox &rhs)
Check whether two bounding boxes intersect for an Iceberg geospatial type.
Define Result, Status, and error helpers.