MySQL 8.4.3
Source Code Documentation
spatial.cc File Reference
#include "sql/spatial.h"
#include <assert.h>
#include <algorithm>
#include <cmath>
#include <map>
#include <memory>
#include <new>
#include <type_traits>
#include <utility>
#include "m_string.h"
#include "my_byteorder.h"
#include "my_macros.h"
#include "my_sys.h"
#include "myisampack.h"
#include "mysql/strings/m_ctype.h"
#include "mysqld_error.h"
#include "prealloced_array.h"
#include "sql/check_stack.h"
#include "sql/current_thd.h"
#include "sql/gis/srid.h"
#include "sql/gis_bg_traits.h"
#include "sql/gstream.h"
#include "sql/psi_memory_key.h"
#include "sql/sql_const.h"
#include "sql_string.h"
#include "string_with_len.h"
#include "template_utils.h"
#include "unsafe_string_append.h"

Classes

class  Geometry_well_formed_checker
 WKB scanner event handler that checks if the WKB string is well formed. More...
 
class  GeomColl_component_counter
 
class  Stepper_base
 Base class of all WKB parsers, which parse different types of geometries properly. More...
 
class  Point_stepper
 For iterating points inside multipoint and linestring. More...
 
class  Linestring_stepper
 For iterating linestrings inside multilinestring and polygon. More...
 
class  Polygon_stepper
 For iterating polygons inside multipolygon or geometry collection. More...
 

Macros

#define MAX_DIGITS_IN_DOUBLE   25
 

Functions

void * gis_wkb_alloc (size_t sz)
 
void * gis_wkb_realloc (void *p, size_t sz)
 
static Geometrycreate_point (char *buffer)
 
static Geometrycreate_linestring (char *buffer)
 
static Geometrycreate_polygon (char *buffer)
 
static Geometrycreate_multipoint (char *buffer)
 
static Geometrycreate_multipolygon (char *buffer)
 
static Geometrycreate_multilinestring (char *buffer)
 
static Geometrycreate_geometrycollection (char *buffer)
 
static bool is_subtype_of (Geometry::wkbType sub, Geometry::wkbType super)
 Check if geometry type sub is a subtype of super. More...
 
static double wkb_get_double (const char *ptr, Geometry::wkbByteOrder bo)
 
static bool check_coordinate_range (double x, double y, double srs_angular_unit, bool *long_out_of_range, bool *lat_out_of_range, double *out_of_range_value)
 Check that a pair of geographic coordinates are within the valid range. More...
 
static uint32 wkb_get_uint (const char *ptr, Geometry::wkbByteOrder bo)
 
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...
 
double coord_val (const char *p, int i, int x)
 
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. More...
 
const char * get_packed_ptr (Geometry *geo0)
 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 *geo0)
 
static Gis_polygon::inner_container_typeinner_rings (const Geometry *g) SUPPRESS_UBSAN
 Get inner rings object from a geometry. More...
 
static void set_inner_rings (Geometry *g, Gis_polygon::inner_container_type *inns) SUPPRESS_UBSAN
 Set inner rings object to a geometry. More...
 
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. More...
 

Variables

static Geometry::Class_info ** ci_collection_end
 
static Geometry::Class_info point_class ("POINT", Geometry::wkb_point, create_point)
 
static Geometry::Class_info linestring_class ("LINESTRING", Geometry::wkb_linestring, create_linestring)
 
static Geometry::Class_info polygon_class ("POLYGON", Geometry::wkb_polygon, create_polygon)
 
static Geometry::Class_info multipoint_class ("MULTIPOINT", Geometry::wkb_multipoint, create_multipoint)
 
static Geometry::Class_info multilinestring_class ("MULTILINESTRING", Geometry::wkb_multilinestring, create_multilinestring)
 
static Geometry::Class_info multipolygon_class ("MULTIPOLYGON", Geometry::wkb_multipolygon, create_multipolygon)
 
static Geometry::Class_info geometrycollection_class ("GEOMCOLLECTION", Geometry::wkb_geometrycollection, create_geometrycollection)
 

Macro Definition Documentation

◆ MAX_DIGITS_IN_DOUBLE

#define MAX_DIGITS_IN_DOUBLE   25

Function Documentation

◆ check_coordinate_range()

static bool check_coordinate_range ( double  x,
double  y,
double  srs_angular_unit,
bool *  long_out_of_range,
bool *  lat_out_of_range,
double *  out_of_range_value 
)
static

Check that a pair of geographic coordinates are within the valid range.

Checks if the coordinates are within the allowed range for geographic coordinates. Valid range for longitude and latitude coordinates in geographic spatial reference systems are (-180, 180) and [-90, 90] degrees, respectively.

Parameters
[in]xLongitude coordinate.
[in]yLatitude coordinate.
[in]srs_angular_unitUnit to radians conversion factor.
[out]long_out_of_rangeLongitude is out of range.
[out]lat_out_of_rangeLatitude is out of range.
[out]out_of_range_valueThe value that is out of range.
Return values
falseCoordinates are within allowed range.
trueCoordinates are not within allowed range.

◆ coord_val()

double coord_val ( const char *  p,
int  i,
int  x 
)
inline

◆ create_geometrycollection()

static Geometry * create_geometrycollection ( char *  buffer)
inlinestatic

◆ create_linestring()

static Geometry * create_linestring ( char *  buffer)
inlinestatic

◆ create_multilinestring()

static Geometry * create_multilinestring ( char *  buffer)
inlinestatic

◆ create_multipoint()

static Geometry * create_multipoint ( char *  buffer)
inlinestatic

◆ create_multipolygon()

static Geometry * create_multipolygon ( char *  buffer)
inlinestatic

◆ create_point()

static Geometry * create_point ( char *  buffer)
inlinestatic

◆ create_polygon()

static Geometry * create_polygon ( char *  buffer)
inlinestatic

◆ 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.

◆ gis_wkb_alloc()

void * gis_wkb_alloc ( size_t  sz)

◆ gis_wkb_realloc()

void * gis_wkb_realloc ( void *  p,
size_t  sz 
)

◆ inner_rings()

static Gis_polygon::inner_container_type * inner_rings ( const Geometry g)
inlinestatic

Get inner rings object from a geometry.

Internally check that the argument is a polygon. This function is intended as a helper function and is called where we don't convert to a polygon pointer although it is a polygon.

Parameters
ga geometry that must be a polygon.
Returns
the polygon's inner rings object.

◆ is_subtype_of()

static bool is_subtype_of ( Geometry::wkbType  sub,
Geometry::wkbType  super 
)
inlinestatic

Check if geometry type sub is a subtype of super.

Since Geometry::wkbType can't represent the geometry type, the superclass of all geometry types, this function can't check that. The supertype has to be a subtype of geometry.

Parameters
subThe type to check
superThe supertype
Returns
True if t1 is a subtype of t2

◆ own_rings()

void own_rings ( Geometry geo0)

◆ 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_inner_rings()

static void set_inner_rings ( Geometry g,
Gis_polygon::inner_container_type inns 
)
inlinestatic

Set inner rings object to a geometry.

Internally check that the argument is a polygon. This function is intended as a helper function and is called where we don't convert to a polygon pointer although it is a polygon.

Parameters
ga geometry that must be a polygon.
innsThe interior rings

◆ wkb_get_double()

static double wkb_get_double ( const char *  ptr,
Geometry::wkbByteOrder  bo 
)
static

◆ wkb_get_uint()

static uint32 wkb_get_uint ( const char *  ptr,
Geometry::wkbByteOrder  bo 
)
static

◆ 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

Variable Documentation

◆ ci_collection_end

Geometry::Class_info** ci_collection_end
static
Initial value:
=
static Class_info * ci_collection[wkb_last+1]
Definition: spatial.h:639
@ wkb_last
Definition: spatial.h:309

◆ geometrycollection_class

Geometry::Class_info geometrycollection_class("GEOMCOLLECTION", Geometry::wkb_geometrycollection, create_geometrycollection) ( "GEOMCOLLECTION"  ,
Geometry::wkb_geometrycollection  ,
create_geometrycollection   
)
static

◆ linestring_class

Geometry::Class_info linestring_class("LINESTRING", Geometry::wkb_linestring, create_linestring) ( "LINESTRING"  ,
Geometry::wkb_linestring  ,
create_linestring   
)
static

◆ multilinestring_class

Geometry::Class_info multilinestring_class("MULTILINESTRING", Geometry::wkb_multilinestring, create_multilinestring) ( "MULTILINESTRING"  ,
Geometry::wkb_multilinestring  ,
create_multilinestring   
)
static

◆ multipoint_class

Geometry::Class_info multipoint_class("MULTIPOINT", Geometry::wkb_multipoint, create_multipoint) ( "MULTIPOINT"  ,
Geometry::wkb_multipoint  ,
create_multipoint   
)
static

◆ multipolygon_class

Geometry::Class_info multipolygon_class("MULTIPOLYGON", Geometry::wkb_multipolygon, create_multipolygon) ( "MULTIPOLYGON"  ,
Geometry::wkb_multipolygon  ,
create_multipolygon   
)
static

◆ point_class

Geometry::Class_info point_class("POINT", Geometry::wkb_point, create_point) ( "POINT"  ,
Geometry::wkb_point  ,
create_point   
)
static

◆ polygon_class

Geometry::Class_info polygon_class("POLYGON", Geometry::wkb_polygon, create_polygon) ( "POLYGON"  ,
Geometry::wkb_polygon  ,
create_polygon   
)
static