MySQL 8.1.0
Source Code Documentation
wkb.h
Go to the documentation of this file.
1#ifndef SQL_GIS_WKB_H_INCLUDED
2#define SQL_GIS_WKB_H_INCLUDED
3
4// Copyright (c) 2017, 2023, Oracle and/or its affiliates.
5//
6// This program is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License, version 2.0,
8// as published by the Free Software Foundation.
9//
10// This program is also distributed with certain software (including
11// but not limited to OpenSSL) that is licensed under separate terms,
12// as designated in a particular file or component or in included license
13// documentation. The authors of MySQL hereby grant you an additional
14// permission to link the program and your derivative works with the
15// separately licensed software that they have included with MySQL.
16//
17// This program is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU General Public License, version 2.0, for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with this program; if not, write to the Free Software
24// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25
26/// @file
27///
28/// This file declares the interface of the WKB parser for geometries and the
29/// parser for the internal geometry representation.
30
31#include <memory> // std::unique_ptr
32
33#include "sql/gis/geometries.h"
34#include "sql/gis/srid.h"
35
36class THD;
37class String;
38namespace dd {
39class Spatial_reference_system;
40}
41
42namespace gis {
43
44/// Parses an SRID from a little-endian string.
45///
46/// @param[in] str The string.
47/// @param[in] length Length of the string.
48/// @param[out] srid The SRID read from the string.
49///
50/// @retval false Success.
51/// @retval true Error. my_error() has not been called.
52bool parse_srid(const char *str, std::size_t length, srid_t *srid);
53
54///
55/// Parses a geometry WKB string and constructs a geometry object.
56///
57/// The geometry is allocated on the heap and ownership is transferred to the
58/// caller.
59///
60/// If ignore_axis_order is true, the string is assumed to be on the geometry
61/// storage format, not general WKB. The storage format differs from ordinary
62/// WKB by having a fixed x=longitude, y=latitude mapping.
63///
64/// @warning This function checks if there are so many nested levels of geometry
65/// collections that the stack will be exhausted. If that happens, my_error is
66/// called and the function exits with no geometry value. However, if thd is
67/// nullptr, this check is disabled, and the caller is responsible for checking
68/// that there is enough stack to parse the WKB string.
69///
70/// @param[in] thd Thread handle.
71/// @param srs The SRS of the geometry.
72/// @param wkb The WKB string.
73/// @param length Length of the WKB string.
74/// @param ignore_axis_order Ignore SRS axis order and assume it's always
75/// long-lat.
76///
77/// @return The geometry. If an error occurred, the return value is a null
78/// pointer. In case of stack overrun, my_error has been called.
79std::unique_ptr<Geometry> parse_wkb(THD *thd,
81 const char *wkb, std::size_t length,
82 bool ignore_axis_order = false);
83
84/// Parses a little-endian geometry string (SRID + WKB).
85///
86/// The geometry is allocated on the heap and ownership is transferred to the
87/// caller.
88///
89/// @param[in] thd Thread handle
90/// @param[in] func_name The function name to use in error messages.
91/// @param[in] str The geometry string.
92/// @param[out] srs The spatial reference system of the geometry.
93/// @param[out] geometry The geometry.
94/// @param[in] treat_unknown_srid_as_cartesian Whether to treat unknown
95/// SRIDs as Cartesian. If false, raise an error if the SRID is unknown.
96///
97/// @retval false Success.
98/// @retval true Error. my_error() has been called.
99bool parse_geometry(THD *thd, const char *func_name, const String *str,
101 std::unique_ptr<Geometry> *geometry,
102 bool treat_unknown_srid_as_cartesian = false);
103
104/// Writes a little-endian geometry string (SRID + WKB).
105///
106/// @param[in] srs The SRS of the geometry.
107/// @param[in] geometry The geometry.
108/// @param[out] str The string to write the geometry to.
109///
110/// @retval false Success.
111/// @retval true Error. my_error() has been called.
112bool write_geometry(const dd::Spatial_reference_system *srs, Geometry &geometry,
113 String *str);
114
115} // namespace gis
116
117#endif // SQL_GIS_WKB_H_INCLUDED
Definition: spatial.h:212
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:166
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
Definition: spatial_reference_system.h:52
This file declares the geometry class hierarchy used by the server as the internal representation of ...
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1063
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
Definition: area.cc:46
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
bool parse_geometry(THD *thd, const char *func_name, const String *str, const dd::Spatial_reference_system **srs, std::unique_ptr< Geometry > *geometry, bool treat_unknown_srid_as_cartesian)
Parses a little-endian geometry string (SRID + WKB).
Definition: wkb.cc:436
bool parse_srid(const char *str, std::size_t length, srid_t *srid)
Parses an SRID from a little-endian string.
Definition: wkb.cc:428
bool write_geometry(const dd::Spatial_reference_system *srs, Geometry &geometry, String *str)
Writes a little-endian geometry string (SRID + WKB).
Definition: wkb.cc:498
std::unique_ptr< Geometry > parse_wkb(THD *thd, const dd::Spatial_reference_system *srs, const char *wkb, std::size_t length, bool ignore_axis_order)
Parses a geometry WKB string and constructs a geometry object.
Definition: wkb.cc:383
std::uint32_t srid_t
A spatial reference system ID (SRID).
Definition: srid.h:32