MySQL 9.1.0
Source Code Documentation
|
This file implements the set of functions that storage engines can call to do geometrical operations. More...
#include "sql/gis/rtree_support.h"
#include <algorithm>
#include <cmath>
#include <limits>
#include <boost/geometry.hpp>
#include "my_byteorder.h"
#include "my_inttypes.h"
#include "sql/current_thd.h"
#include "sql/dd/cache/dictionary_client.h"
#include "sql/dd/types/spatial_reference_system.h"
#include "sql/gis/box.h"
#include "sql/gis/box_traits.h"
#include "sql/gis/covered_by_functor.h"
#include "sql/gis/disjoint_functor.h"
#include "sql/gis/equals_functor.h"
#include "sql/gis/geometries.h"
#include "sql/gis/geometries_cs.h"
#include "sql/gis/intersects_functor.h"
#include "sql/gis/mbr_utils.h"
#include "sql/gis/srid.h"
#include "sql/gis/wkb.h"
#include "sql/spatial.h"
#include "sql/sql_class.h"
#include "sql/srs_fetcher.h"
#include "template_utils.h"
Functions | |
dd::Spatial_reference_system * | fetch_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... | |
This file implements the set of functions that storage engines can call to do geometrical operations.
double compute_area | ( | const dd::Spatial_reference_system * | srs, |
const double * | a, | ||
int | n_dim | ||
) |
Computes the area of an MBR.
[in] | srs | Spatial reference system. |
[in] | a | The MBR. |
[in] | n_dim | Number of dimensions. Must be 2. |
dd::Spatial_reference_system * fetch_srs | ( | gis::srid_t | srid | ) |
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.
[in] | srid | The spatial reference system ID to look up. |
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.
The SRID of the SRS parameter must match the SRID stored in the first four bytes of the geometry string.
[in] | srs | Spatial reference system. |
[in] | store | The geometry. |
[in] | size | Number of bytes in the geometry string. |
[in] | n_dims | Number of dimensions. Must be 2. |
[out] | mbr | The computed MBR. |
[out] | srid | SRID of the geometry |
0 | The geometry is valid. |
-1 | The geometry is invalid. |
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.
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.
[in] | srs | Spatial reference system. |
[in] | a | The first MBR. |
[in] | b | The second MBR. |
true | MBR a contains MBR b. |
false | MBR a doesn't contain MBR b. |
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.
true | The MBRs are disjoint. |
false | The MBRs intersect each other. |
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.
[in] | srs | Spatial reference system. |
[in] | a | The first MBR. |
[in] | b | The second MBR. |
true | The two MBRs are equal. |
false | The two MBRs aren't equal. |
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.
[in] | srs | Spatial reference system. |
[in] | a | The first MBR. |
[in] | b | The 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.
true | The MBRs intersect each other. |
false | The MBRs are disjoint. |
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.
MBR format: a[0] = xmin, a[1] = xmax, a[2] = ymin, a[3] = ymax. Same for b.
[in] | srs | Spatial reference system. |
[in,out] | a | The first MBR, where the joined result will be. |
[in] | b | The second MBR. |
[in] | n_dim | Number of dimensions. Must be 2. |
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.
[in] | srs | Spatial reference system. |
[in] | a | The first MBR. |
[in] | b | The second MBR. |
[in] | n_dim | Number of dimensions. Must be 2. |
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.
[in] | srs | Spatial reference system. |
[in] | a | The first MBR. |
[in] | b | The second MBR. |
true | MBR a is within MBR b. |
false | MBR a isn't within MBR b. |
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).
[in] | srs | Spatial reference system. |
[in] | mbr_a | First MBR. |
[in] | mbr_b | Second MBR. |
[in] | mbr_len | MBR length in bytes. Must be 4 * sizeof(double). |
[out] | ab_area | The total area of MBRs a and b combined into one MBR. |
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.
[in] | srs | Spatial reference system. |
[in] | mbr_a | First MBR. |
[in] | mbr_b | Second MBR. |
[in] | mbr_len | MBR length in bytes. Must be 4 * sizeof(double). |