MySQL 8.3.0
Source Code Documentation
rtree_support.h File Reference

This file declares a set of functions that storage engines can call to do geometrical operations. More...

#include "my_inttypes.h"
#include "sql/gis/srid.h"

Go to the source code of this file.

Classes

struct  rtr_mbr
 In memory representation of a minimum bounding rectangle. More...
 

Namespaces

namespace  dd
 The version of the current data dictionary table definitions.
 

Typedefs

typedef struct rtr_mbr rtr_mbr_t
 In memory representation of a minimum bounding rectangle. More...
 

Functions

dd::Spatial_reference_systemfetch_srs (gis::srid_t srid)
 Fetches a copy of the dictionary entry for a spatial reference system. More...
 
bool mbr_contain_cmp (const dd::Spatial_reference_system *srs, rtr_mbr_t *a, rtr_mbr_t *b)
 Checks if one MBR covers another MBR. More...
 
bool mbr_equal_cmp (const dd::Spatial_reference_system *srs, rtr_mbr_t *a, rtr_mbr_t *b)
 Checks if two MBRs are equal. More...
 
bool mbr_intersect_cmp (const dd::Spatial_reference_system *srs, rtr_mbr_t *a, rtr_mbr_t *b)
 Checks if two MBRs intersect each other. More...
 
bool mbr_disjoint_cmp (const dd::Spatial_reference_system *srs, rtr_mbr_t *a, rtr_mbr_t *b)
 Checks if two MBRs are disjoint. More...
 
bool mbr_within_cmp (const dd::Spatial_reference_system *srs, rtr_mbr_t *a, rtr_mbr_t *b)
 Checks if one MBR is covered by another MBR. More...
 
void mbr_join (const dd::Spatial_reference_system *srs, double *a, const double *b, int n_dim)
 Expands an MBR to also cover another MBR. More...
 
double mbr_join_area (const dd::Spatial_reference_system *srs, const double *a, const double *b, int n_dim)
 Computes the combined area of two MBRs. More...
 
double compute_area (const dd::Spatial_reference_system *srs, const double *a, int n_dim)
 Computes the area of an MBR. More...
 
int get_mbr_from_store (const dd::Spatial_reference_system *srs, const uchar *store, uint size, uint n_dims, double *mbr, gis::srid_t *srid)
 Computes the MBR of a geometry. More...
 
double rtree_area_increase (const dd::Spatial_reference_system *srs, const uchar *mbr_a, const uchar *mbr_b, int mbr_len, double *ab_area)
 Computes the extra area covered if an MBR is expanded to cover another MBR. More...
 
double rtree_area_overlapping (const dd::Spatial_reference_system *srs, const uchar *mbr_a, const uchar *mbr_b, int mbr_len)
 Calculates the overlapping area between two MBRs. More...
 

Detailed Description

This file declares a set of functions that storage engines can call to do geometrical operations.

Typedef Documentation

◆ rtr_mbr_t

typedef struct rtr_mbr rtr_mbr_t

In memory representation of a minimum bounding rectangle.

Function Documentation

◆ compute_area()

double compute_area ( const dd::Spatial_reference_system srs,
const double *  a,
int  n_dim 
)

Computes the area of an MBR.

Note
The function takes a dimension parameter, but currently only supports 2d MBRs.
Parameters
[in]srsSpatial reference system.
[in]aThe MBR.
[in]n_dimNumber of dimensions. Must be 2.
Returns
Are of the MBR.

◆ fetch_srs()

Fetches a copy of the dictionary entry for a spatial reference system.

Spatial reference dictionary cache objects have a limited lifetime, typically until the end of a transaction. This function returns a clone of the dictionary object so that it is valid also after the transaction has ended. This is necessary since InnoDB may do index operations after the transaction has ended.

Parameters
[in]sridThe spatial reference system ID to look up.
Returns
The spatial reference system dictionary entry, or nullptr.

◆ get_mbr_from_store()

int get_mbr_from_store ( const dd::Spatial_reference_system srs,
const uchar store,
uint  size,
uint  n_dims,
double *  mbr,
gis::srid_t srid 
)

Computes the MBR of a geometry.

If the geometry is empty, a box that covers the entire domain is returned.

The geometry is expected to be on the storage format (SRID + WKB). The caller is expected to provide an output buffer that is large enough.

Note
The function takes a dimension parameter, but currently only supports 2d MBRs.

The SRID of the SRS parameter must match the SRID stored in the first four bytes of the geometry string.

Parameters
[in]srsSpatial reference system.
[in]storeThe geometry.
[in]sizeNumber of bytes in the geometry string.
[in]n_dimsNumber of dimensions. Must be 2.
[out]mbrThe computed MBR.
[out]sridSRID of the geometry
Return values
0The geometry is valid.
-1The geometry is invalid.

◆ mbr_contain_cmp()

bool mbr_contain_cmp ( const dd::Spatial_reference_system srs,
rtr_mbr_t a,
rtr_mbr_t b 
)

Checks if one MBR covers another MBR.

Warning
Despite the name, this function computes the covers relation, not contains.

For both MBRs, the coordinates of the MBR's minimum corners must be smaller than or equal to the corresponding coordinates of the maximum corner.

Parameters
[in]srsSpatial reference system.
[in]aThe first MBR.
[in]bThe second MBR.
Return values
trueMBR a contains MBR b.
falseMBR a doesn't contain MBR b.

◆ mbr_disjoint_cmp()

bool mbr_disjoint_cmp ( const dd::Spatial_reference_system srs,
rtr_mbr_t a,
rtr_mbr_t b 
)

Checks if two MBRs are disjoint.

For both MBRs, the coordinates of the MBR's minimum corners must be smaller than or equal to the corresponding coordinates of the maximum corner.

Return values
trueThe MBRs are disjoint.
falseThe MBRs intersect each other.

◆ mbr_equal_cmp()

bool mbr_equal_cmp ( const dd::Spatial_reference_system srs,
rtr_mbr_t a,
rtr_mbr_t b 
)

Checks if two MBRs are equal.

For both MBRs, the coordinates of the MBR's minimum corners must be smaller than or equal to the corresponding coordinates of the maximum corner.

Parameters
[in]srsSpatial reference system.
[in]aThe first MBR.
[in]bThe second MBR.
Return values
trueThe two MBRs are equal.
falseThe two MBRs aren't equal.

◆ mbr_intersect_cmp()

bool mbr_intersect_cmp ( const dd::Spatial_reference_system srs,
rtr_mbr_t a,
rtr_mbr_t b 
)

Checks if two MBRs intersect each other.

Parameters
[in]srsSpatial reference system.
[in]aThe first MBR.
[in]bThe second MBR.

For both MBRs, the coordinates of the MBR's minimum corners must be smaller than or equal to the corresponding coordinates of the maximum corner.

Return values
trueThe MBRs intersect each other.
falseThe MBRs are disjoint.

◆ mbr_join()

void mbr_join ( const dd::Spatial_reference_system srs,
double *  a,
const double *  b,
int  n_dim 
)

Expands an MBR to also cover another MBR.

Note
The function takes a dimension parameter, but currently only supports 2d MBRs.

MBR format: a[0] = xmin, a[1] = xmax, a[2] = ymin, a[3] = ymax. Same for b.

Parameters
[in]srsSpatial reference system.
[in,out]aThe first MBR, where the joined result will be.
[in]bThe second MBR.
[in]n_dimNumber of dimensions. Must be 2.

◆ mbr_join_area()

double mbr_join_area ( const dd::Spatial_reference_system srs,
const double *  a,
const double *  b,
int  n_dim 
)

Computes the combined area of two MBRs.

The MBRs may overlap.

Note
The function takes a dimension parameter, but currently only supports 2d MBRs.
Parameters
[in]srsSpatial reference system.
[in]aThe first MBR.
[in]bThe second MBR.
[in]n_dimNumber of dimensions. Must be 2.
Returns
The area of MBR a expanded by MBR b.

◆ mbr_within_cmp()

bool mbr_within_cmp ( const dd::Spatial_reference_system srs,
rtr_mbr_t a,
rtr_mbr_t b 
)

Checks if one MBR is covered by another MBR.

Warning
Despite the name, this function computes the covered_by relation, not within.
Note
If the minimum corner coordinates are larger than the corresponding coordinates of the maximum corner, and if not all a and b coordinates are the same, the function returns the inverse result, i.e., return true if a is not covered by b.
Parameters
[in]srsSpatial reference system.
[in]aThe first MBR.
[in]bThe second MBR.
Return values
trueMBR a is within MBR b.
falseMBR a isn't within MBR b.

◆ rtree_area_increase()

double rtree_area_increase ( const dd::Spatial_reference_system srs,
const uchar mbr_a,
const uchar mbr_b,
int  mbr_len,
double *  ab_area 
)

Computes the extra area covered if an MBR is expanded to cover another MBR.

The formula is area(a + b) - area(a). This is generally different from area(b). If MBR b overlaps MBR a, area(a+b) - area(a) < area(b). If they are far apart, area(a+b) - area(a) > area(b).

Note
If MBRs a and b are far apart, the function may return Inf.
Parameters
[in]srsSpatial reference system.
[in]mbr_aFirst MBR.
[in]mbr_bSecond MBR.
[in]mbr_lenMBR length in bytes. Must be 4 * sizeof(double).
[out]ab_areaThe total area of MBRs a and b combined into one MBR.
Returns
The increase in area when expanding from MBR a to also cover MBR b.

◆ rtree_area_overlapping()

double rtree_area_overlapping ( const dd::Spatial_reference_system srs,
const uchar mbr_a,
const uchar mbr_b,
int  mbr_len 
)

Calculates the overlapping area between two MBRs.

Parameters
[in]srsSpatial reference system.
[in]mbr_aFirst MBR.
[in]mbr_bSecond MBR.
[in]mbr_lenMBR length in bytes. Must be 4 * sizeof(double).
Returns
The area of the overlapping region.