MySQL 9.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, 2024, 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 designed to work 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 either included with
16// the program or referenced in the documentation.
17//
18// This program is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License, version 2.0, for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with this program; if not, write to the Free Software
25// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26
27/// @file
28///
29/// This file declares the interface of the WKB parser for geometries and the
30/// parser for the internal geometry representation.
31
32#include <memory> // std::unique_ptr
33
34#include "sql/gis/geometries.h"
35#include "sql/gis/srid.h"
36
37class THD;
38class String;
39namespace dd {
40class Spatial_reference_system;
41}
42
43namespace gis {
44
45/// Parses an SRID from a little-endian string.
46///
47/// @param[in] str The string.
48/// @param[in] length Length of the string.
49/// @param[out] srid The SRID read from the string.
50///
51/// @retval false Success.
52/// @retval true Error. my_error() has not been called.
53bool parse_srid(const char *str, std::size_t length, srid_t *srid);
54
55///
56/// Parses a geometry WKB string and constructs a geometry object.
57///
58/// The geometry is allocated on the heap and ownership is transferred to the
59/// caller.
60///
61/// If ignore_axis_order is true, the string is assumed to be on the geometry
62/// storage format, not general WKB. The storage format differs from ordinary
63/// WKB by having a fixed x=longitude, y=latitude mapping.
64///
65/// @warning This function checks if there are so many nested levels of geometry
66/// collections that the stack will be exhausted. If that happens, my_error is
67/// called and the function exits with no geometry value. However, if thd is
68/// nullptr, this check is disabled, and the caller is responsible for checking
69/// that there is enough stack to parse the WKB string.
70///
71/// @param[in] thd Thread handle.
72/// @param srs The SRS of the geometry.
73/// @param wkb The WKB string.
74/// @param length Length of the WKB string.
75/// @param ignore_axis_order Ignore SRS axis order and assume it's always
76/// long-lat.
77///
78/// @return The geometry. If an error occurred, the return value is a null
79/// pointer. In case of stack overrun, my_error has been called.
80std::unique_ptr<Geometry> parse_wkb(THD *thd,
82 const char *wkb, std::size_t length,
83 bool ignore_axis_order = false);
84
85/// Parses a little-endian geometry string (SRID + WKB).
86///
87/// The geometry is allocated on the heap and ownership is transferred to the
88/// caller.
89///
90/// @param[in] thd Thread handle
91/// @param[in] func_name The function name to use in error messages.
92/// @param[in] str The geometry string.
93/// @param[out] srs The spatial reference system of the geometry.
94/// @param[out] geometry The geometry.
95/// @param[in] treat_unknown_srid_as_cartesian Whether to treat unknown
96/// SRIDs as Cartesian. If false, raise an error if the SRID is unknown.
97///
98/// @retval false Success.
99/// @retval true Error. my_error() has been called.
100bool parse_geometry(THD *thd, const char *func_name, const String *str,
102 std::unique_ptr<Geometry> *geometry,
103 bool treat_unknown_srid_as_cartesian = false);
104
105/// Writes a little-endian geometry string (SRID + WKB).
106///
107/// @param[in] srs The SRS of the geometry.
108/// @param[in] geometry The geometry.
109/// @param[out] str The string to write the geometry to.
110///
111/// @retval false Success.
112/// @retval true Error. my_error() has been called.
113bool write_geometry(const dd::Spatial_reference_system *srs, Geometry &geometry,
114 String *str);
115
116} // namespace gis
117
118#endif // SQL_GIS_WKB_H_INCLUDED
Definition: spatial.h:213
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: spatial_reference_system.h:53
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:1105
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
Definition: area.cc:47
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:76
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:437
bool parse_srid(const char *str, std::size_t length, srid_t *srid)
Parses an SRID from a little-endian string.
Definition: wkb.cc:429
bool write_geometry(const dd::Spatial_reference_system *srs, Geometry &geometry, String *str)
Writes a little-endian geometry string (SRID + WKB).
Definition: wkb.cc:499
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:384
std::uint32_t srid_t
A spatial reference system ID (SRID).
Definition: srid.h:33