MySQL 8.4.0
Source Code Documentation
spatial.h File Reference
#include <assert.h>
#include <float.h>
#include <string.h>
#include <sys/types.h>
#include <algorithm>
#include <cstddef>
#include <iterator>
#include "lex_string.h"
#include "my_byteorder.h"
#include "my_compiler.h"
#include "my_inttypes.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql/service_mysql_alloc.h"
#include "sql/gis/srid.h"
#include "sql/inplace_vector.h"
#include "sql_string.h"
#include "unsafe_string_append.h"

Go to the source code of this file.

Classes

class  point_xy
 Point with coordinates X and Y. More...
 
struct  wkb_header_st
 
struct  MBR
 
class  Geometry
 
class  Geometry::wkb_container
 Constant storage for WKB. More...
 
class  Geometry::wkb_parser
 WKB parser, designed to traverse through WKB data from beginning of the buffer towards the end using a set of scan_xxx(), get_xxx() and skip_xxx() routines, with safety tests to avoid going beyond the buffer end. More...
 
class  Geometry::Class_info
 
class  Geometry::Flags_t
 Highest byte is stores byte order, dimension, nomem and geotype as follows: bo: byte order, 1 for little endian(ndr), 0 for big endian(xdr); Currently it must be always wkb_ndr since it is MySQL's portable geometry format. More...
 
class  Gis_point
 
class  Gis_wkb_vector_const_iterator< T >
 Gis_wkb_vector_const_iterator is const_iterator class for Gis_wkb_vector, and base class of Gis_wkb_vector_iterator – iterator class for Gis_wkb_vector. More...
 
class  Gis_wkb_vector_iterator< T >
 This class is the iterator class for Gis_wkb_vector, its instances can be used to mutate their referenced data element. More...
 
class  Geometry_vector< T >
 Geometry vector class. More...
 
class  Gis_wkb_vector< T >
 Gis_wkb_vector class template definition. More...
 
class  Gis_line_string
 
class  Gis_polygon_ring
 
class  Gis_polygon
 
class  Gis_multi_point
 
class  Gis_multi_line_string
 
class  Gis_multi_polygon
 
class  Gis_geometry_collection
 
struct  Geometry_buffer
 Gis_polygon objects and Gis_wkb_vector<> objects are of same size, and Gis_point and Geometry objects are smaller. More...
 
class  WKB_scanner_event_handler
 

Typedefs

typedef struct wkb_header_st wkb_header
 

Functions

void * gis_wkb_alloc (size_t sz)
 
void * gis_wkb_fixed_alloc (size_t sz)
 
void * gis_wkb_realloc (void *p, size_t sz)
 
void gis_wkb_free (void *p)
 
void gis_wkb_raw_free (void *p)
 
Geometry::wkbByteOrder get_byte_order (const void *p0)
 
void set_byte_order (void *p0, Geometry::wkbByteOrder bo)
 
Geometry::wkbType get_wkb_geotype (const void *p0)
 Get wkbType value from WKB, the WKB is always little endian, so need platform specific conversion. More...
 
char * write_wkb_header (void *p0, Geometry::wkbType geotype)
 
char * write_wkb_header (void *p0, Geometry::wkbType geotype, uint32 obj_count)
 
char * write_geometry_header (void *p0, gis::srid_t srid, Geometry::wkbType geotype)
 
char * write_geometry_header (void *p0, gis::srid_t srid, Geometry::wkbType geotype, uint32 obj_count)
 
void write_wkb_header (String *str, Geometry::wkbType geotype)
 
void write_wkb_header (String *str, Geometry::wkbType geotype, uint32 obj_count)
 
void write_geometry_header (String *str, gis::srid_t srid, Geometry::wkbType geotype)
 
void write_geometry_header (String *str, gis::srid_t srid, Geometry::wkbType geotype, uint32 obj_count)
 
template<typename T >
Gis_wkb_vector_const_iterator< T > operator+ (typename Gis_wkb_vector_const_iterator< T >::difference_type n, const Gis_wkb_vector_const_iterator< T > &itr)
 
template<typename T >
Gis_wkb_vector_iterator< T > operator+ (typename Gis_wkb_vector_iterator< T >::difference_type n, const Gis_wkb_vector_iterator< T > &itr)
 
void * get_packed_ptr (const Geometry *geo, size_t *pnbytes)
 Packup a polygon's outer ring and inner rings into a single chunk of memory as result. More...
 
const char * get_packed_ptr (Geometry *geo)
 Get a polygon's WKB string's starting address. More...
 
bool polygon_is_packed (Geometry *plgn, Geometry *mplgn)
 Check whether plgn is packed into its owner mplgn's WKB buffer. More...
 
void own_rings (Geometry *geo)
 
void parse_wkb_data (Geometry *geom, const char *p, size_t num_geoms=0)
 Parse the wkb buffer to build the component vector m_geo_vect for geom. More...
 
Gis_polygon_ringouter_ring (const Geometry *g)
 
const char * wkb_scanner (THD *thd, const char *wkb, uint32 *len, uint32 geotype, bool has_hdr, WKB_scanner_event_handler *handler)
 Scan WKB byte string and notify WKB events by calling registered callbacks. More...
 

Variables

const uint GEOM_DIM = 2
 
const uint SRID_SIZE = 4
 
const uint SIZEOF_STORED_DOUBLE = 8
 
const uint POINT_DATA_SIZE = (SIZEOF_STORED_DOUBLE * 2)
 
const uint WKB_HEADER_SIZE = (1 + 4)
 
const uint GEOM_HEADER_SIZE = (SRID_SIZE + WKB_HEADER_SIZE)
 
const uint32 GET_SIZE_ERROR = 0xFFFFFFFFU
 

Typedef Documentation

◆ wkb_header

typedef struct wkb_header_st wkb_header

Function Documentation

◆ get_byte_order()

Geometry::wkbByteOrder get_byte_order ( const void *  p0)
inline

◆ get_packed_ptr() [1/2]

void * get_packed_ptr ( const Geometry geo0,
size_t *  pnbytes 
)

Packup a polygon's outer ring and inner rings into a single chunk of memory as result.

nbytes returns the number of bytes in WKB data. The returned WKB has no WKB header. Never call get_ptr to obtain a polygon's WKB data.

Parameters
geo0The polygon whose WKB data we want to pack up.
[out]pnbytesTakes back the number of bytes of the packed WKB string.
Returns
The address of the packed WKB string buffer.

◆ get_packed_ptr() [2/2]

const char * get_packed_ptr ( Geometry geo0)

Get a polygon's WKB string's starting address.

The polygon is already packed so that its outer ring and inner rings point to different locations of a continuous chunk of WKB buffer.

Parameters
geo0The already packed polygon, we want to get its data address.
Returns
The WKB string starting address, right after the WKB header if any.

◆ get_wkb_geotype()

Geometry::wkbType get_wkb_geotype ( const void *  p0)
inline

Get wkbType value from WKB, the WKB is always little endian, so need platform specific conversion.

Parameters
p0WKB geometry type field address.
Returns
geometry type.

◆ gis_wkb_alloc()

void * gis_wkb_alloc ( size_t  sz)

◆ gis_wkb_fixed_alloc()

void * gis_wkb_fixed_alloc ( size_t  sz)
inline

◆ gis_wkb_free()

void gis_wkb_free ( void *  p)
inline

◆ gis_wkb_raw_free()

void gis_wkb_raw_free ( void *  p)
inline

◆ gis_wkb_realloc()

void * gis_wkb_realloc ( void *  p,
size_t  sz 
)

◆ operator+() [1/2]

template<typename T >
Gis_wkb_vector_const_iterator< T > operator+ ( typename Gis_wkb_vector_const_iterator< T >::difference_type  n,
const Gis_wkb_vector_const_iterator< T > &  itr 
)

◆ operator+() [2/2]

template<typename T >
Gis_wkb_vector_iterator< T > operator+ ( typename Gis_wkb_vector_iterator< T >::difference_type  n,
const Gis_wkb_vector_iterator< T > &  itr 
)

◆ outer_ring()

Gis_polygon_ring * outer_ring ( const Geometry g)
inline

◆ own_rings()

void own_rings ( Geometry geo)

◆ parse_wkb_data()

void parse_wkb_data ( Geometry geom,
const char *  p,
size_t  num_geoms 
)

Parse the wkb buffer to build the component vector m_geo_vect for geom.

Set each geometry's wkb pointer into the Geometry objects inside m_geo_vect. Make it a standalone function in order to be able to access classes defined after class template Gis_wkb_vector.

Parameters
geomthe geometry to analyze and parse.
ppoints to the geometry's wkb data's 1st byte, right after its wkb header if any.
num_geomsnumber of following geometries, to be used only when parsing the WKB of a polygon's inner rings because there is no WKB header for the inner rings only.

◆ polygon_is_packed()

bool polygon_is_packed ( Geometry plgn,
Geometry mplgn 
)

Check whether plgn is packed into its owner mplgn's WKB buffer.

Parameters
plgnthe polygon to be checked
mplgnthe multipolygon, owner/holder of plgn.
Returns
true if plgn is packed into mplgn, false otherwise.

◆ set_byte_order()

void set_byte_order ( void *  p0,
Geometry::wkbByteOrder  bo 
)
inline

◆ wkb_scanner()

const char * wkb_scanner ( THD thd,
const char *  wkb,
uint32 len,
uint32  geotype,
bool  has_hdr,
WKB_scanner_event_handler handler 
)

Scan WKB byte string and notify WKB events by calling registered callbacks.

Parameters
wkba little endian WKB byte string of 'len' bytes, with or without WKB header.
[in]thdThread context.
[in,out]lenremaining number of bytes of the wkb string.
geotypethe type of the geometry to be scanned.
has_hdrwhether the 'wkb' point to a WKB header or right after the header. If it is true, the 'geotype' should be the same as the type in the header; otherwise, and we will use the type specified in WKB header.
handlerthe registered WKB_scanner_event_handler object to be notified.
Returns
the next byte after last valid geometry just scanned, or NULL on error

◆ write_geometry_header() [1/4]

void write_geometry_header ( String str,
gis::srid_t  srid,
Geometry::wkbType  geotype 
)
inline

◆ write_geometry_header() [2/4]

void write_geometry_header ( String str,
gis::srid_t  srid,
Geometry::wkbType  geotype,
uint32  obj_count 
)
inline

◆ write_geometry_header() [3/4]

char * write_geometry_header ( void *  p0,
gis::srid_t  srid,
Geometry::wkbType  geotype 
)
inline

◆ write_geometry_header() [4/4]

char * write_geometry_header ( void *  p0,
gis::srid_t  srid,
Geometry::wkbType  geotype,
uint32  obj_count 
)
inline

◆ write_wkb_header() [1/4]

void write_wkb_header ( String str,
Geometry::wkbType  geotype 
)
inline

◆ write_wkb_header() [2/4]

void write_wkb_header ( String str,
Geometry::wkbType  geotype,
uint32  obj_count 
)
inline

◆ write_wkb_header() [3/4]

char * write_wkb_header ( void *  p0,
Geometry::wkbType  geotype 
)
inline

◆ write_wkb_header() [4/4]

char * write_wkb_header ( void *  p0,
Geometry::wkbType  geotype,
uint32  obj_count 
)
inline

Variable Documentation

◆ GEOM_DIM

const uint GEOM_DIM = 2

◆ GEOM_HEADER_SIZE

const uint GEOM_HEADER_SIZE = (SRID_SIZE + WKB_HEADER_SIZE)

◆ GET_SIZE_ERROR

const uint32 GET_SIZE_ERROR = 0xFFFFFFFFU

◆ POINT_DATA_SIZE

const uint POINT_DATA_SIZE = (SIZEOF_STORED_DOUBLE * 2)

◆ SIZEOF_STORED_DOUBLE

const uint SIZEOF_STORED_DOUBLE = 8

◆ SRID_SIZE

const uint SRID_SIZE = 4

◆ WKB_HEADER_SIZE

const uint WKB_HEADER_SIZE = (1 + 4)