MySQL 8.4.0
Source Code Documentation
Gis_wkb_vector< T > Class Template Reference

Gis_wkb_vector class template definition. More...

#include <spatial.h>

Inheritance diagram for Gis_wkb_vector< T >:
[legend]

Public Types

typedef T value_type
 
typedef Gis_wkb_vector_const_iterator< T > const_iterator
 
typedef Gis_wkb_vector_iterator< T > iterator
 
typedef size_t size_type
 
typedef const T * const_pointer
 
typedef const T & const_reference
 
typedef T * pointer
 
typedef T & reference
 
typedef ptrdiff_t difference_type
 
typedef Geometry_vector< T > Geo_vector
 
- Public Types inherited from Geometry
enum  wkbType {
  wkb_invalid_type = 0 , wkb_first = 1 , wkb_point = 1 , wkb_linestring = 2 ,
  wkb_polygon = 3 , wkb_multipoint = 4 , wkb_multilinestring = 5 , wkb_multipolygon = 6 ,
  wkb_geometrycollection = 7 , wkb_polygon_inner_rings = 31 , wkb_last = 31
}
 
enum  wkbByteOrder { wkb_xdr = 0 , wkb_ndr = 1 , wkb_invalid }
 
enum  enum_coordinate_reference_system { coord_first = 1 , cartesian = 1 , coord_last = 1 }
 
typedef Geometry *(* create_geom_t) (char *)
 Callback which creates Geometry objects on top of a given placement. More...
 

Private Types

typedef Gis_wkb_vector< T > self
 
typedef ptrdiff_t index_type
 
typedef Geometry base
 

Private Attributes

Geo_vectorm_geo_vect
 The geometry vector of this geometry object's components, each of which is an object of Geometry or its children classes where appropriate. More...
 

Iterator functions.

typedef Gis_wkb_vector< Gis_pointLinestring
 
typedef Gis_wkb_vector< LinestringMulti_linestrings
 
iterator begin ()
 
const_iterator begin () const
 Create a const iterator. More...
 
iterator end ()
 Create an open boundary iterator. More...
 
const_iterator end () const
 Create an open boundary iterator. More...
 
size_type size () const
 Get container size. More...
 
bool empty () const
 
const_reference back () const
 
reference back ()
 
const_reference operator[] (index_type i) const
 
reference operator[] (index_type i)
 
 Gis_wkb_vector (const void *ptr, size_t nbytes, const Geometry::Flags_t &flags, gis::srid_t srid, bool is_bg_adapter=true)
 Constructor. More...
 
 Gis_wkb_vector (const self &v)
 
 Gis_wkb_vector ()
 
 ~Gis_wkb_vector () override
 
void clear_wkb_data ()
 
selfoperator= (const self &rhs)
 Deep assignment from vector 'rhs' to this object. More...
 
void shallow_push (const Geometry *g) override SUPPRESS_UBSAN
 The copy constructors of Geometry classes always do deep copy, but when pushing a Geometry object into its owner's geo.m_geo_vect, we want to do shallow copy because we want all elements in geo.m_geo_vect vector point into locations in the geo.m_ptr buffer. More...
 
Geo_vectorget_geo_vect (bool create_if_null=false)
 
Geo_vectorget_geo_vect () const
 
void set_geo_vect (Geo_vector *ptr)
 
void donate_data () override
 
void set_ptr (void *ptr, size_t len)
 
void clear ()
 Update support We suppose updating a geometry can happen in the following ways: More...
 
size_t get_nbytes_free () const
 Get number of free bytes in the buffer held by m_ptr. More...
 
size_t current_size () const
 Returns payload number of bytes of the topmost geometry holding this geometry, i.e. More...
 
void push_back (const T &val)
 
void resize (size_t sz)
 
void reassemble ()
 Because of resize, a geometry's components may reside not in one chunk, some may in the m_ptr's chunk; others have their own memory and only exist in m_geo_vect vector, not in ptr's chunk. More...
 
bool reverse_coordinates () override
 Reverses the coordinates of a geometry. More...
 
bool validate_coordinate_range (double, bool *, bool *, double *) override
 Check that the coordinates of a geometry is within the valid range. More...
 

Additional Inherited Members

- Public Member Functions inherited from Geometry
virtual ~Geometry ()
 
virtual const Class_infoget_class_info () const
 
virtual uint32 get_data_size () const
 
virtual bool init_from_wkt (Gis_read_stream *trs, String *wkb)
 
virtual uint init_from_wkb (THD *thd, const char *wkb, uint len, wkbByteOrder bo, String *res)
 
virtual bool get_data_as_wkt (String *txt, wkb_parser *wkb) const
 
virtual bool get_mbr (MBR *mbr, wkb_parser *wkb) const
 
bool get_mbr (MBR *mbr)
 
virtual bool dimension (uint32 *dim, wkb_parser *wkb) const
 
bool dimension (uint32 *dim) const
 
wkbType get_type () const
 
enum_coordinate_reference_system get_coordsys () const
 
virtual uint32 feature_dimension () const
 
virtual int get_x (double *) const
 
virtual int get_y (double *) const
 
virtual int geom_length (double *) const
 
virtual int is_closed (int *) const
 
virtual int num_interior_ring (uint32 *) const
 
virtual int num_points (uint32 *) const
 
virtual int num_geometries (uint32 *) const
 
virtual int copy_points (String *) const
 
virtual int start_point (String *) const
 
virtual int end_point (String *) const
 
virtual int exterior_ring (String *) const
 
virtual int point_n (uint32 num, String *result) const
 
virtual int interior_ring_n (uint32 num, String *result) const
 
virtual int geometry_n (uint32 num, String *result) const
 
bool as_wkt (String *wkt, wkb_parser *wkb) const
 
bool as_wkt (String *wkt) const
 
bool as_wkb (String *wkb, bool shallow_copy) const
 Write this geometry's WKB byte string into specified buffer, the SRID is not written into the buffer. More...
 
bool as_geometry (String *wkb, bool shallow_copy) const
 Write this geometry's GEOMETRY byte string into specified buffer, the SRID will be written before the WKB string to form a GEOMETRY byte string. More...
 
void set_data_ptr (const void *data, size_t data_len)
 
void set_data_ptr (const wkb_container *c)
 
void * get_data_ptr () const
 
bool envelope (String *result) const
 
bool envelope (MBR *mbr) const
 
bool is_polygon_ring () const
 
bool is_polygon_outer_ring () const
 
bool is_polygon_inner_ring () const
 
bool has_geom_header_space () const
 
void has_geom_header_space (bool b)
 
bool is_components_no_overlapped () const
 
void set_components_no_overlapped (bool b)
 
void set_props (uint16 flag)
 
uint16 get_props () const
 
void set_srid (gis::srid_t id)
 
gis::srid_t get_srid () const
 
const void * normalize_ring_order ()
 In place normalize polygons' rings, making outer ring CCW and inner rings CW by reversing the ring's points in the WKB buffer inplace. More...
 
 Geometry ()
 
 Geometry (const void *ptr, size_t len, const Flags_t &flags, gis::srid_t srid)
 Constructor used as BG adapter or by default constructors of children classes. More...
 
 Geometry (const Geometry &geo)
 
Geometryoperator= (const Geometry &rhs)
 Assignment operator for Geometry class, assignment operators of children classes calls this to do general assignment. More...
 
void * get_ptr () const
 
char * get_cptr () const
 
ucharget_ucptr () const
 
Geometryget_owner () const
 
void set_owner (Geometry *o)
 
void set_byte_order (Geometry::wkbByteOrder bo)
 
void set_dimension (char dim)
 
void set_geotype (Geometry::wkbType gt)
 
void set_nbytes (size_t n) const
 
void set_ownmem (bool b)
 Set whether this object has its own memory. More...
 
bool get_ownmem () const
 Returns whether this object has its own memory. More...
 
Geometry::wkbByteOrder get_byte_order () const
 
char get_dimension () const
 
Geometry::wkbType get_geotype () const
 
uint32 get_ogc_geotype () const
 Build an OGC standard type value from m_flags.zm and m_flags.geotype. More...
 
size_t get_nbytes () const
 
void set_ptr (const void *ptr)
 
bool is_bg_adapter () const
 Whether the Geometry object is created to be used by Boost Geometry or only by MySQL. More...
 
void set_bg_adapter (bool b) const
 Set whether this object is a BG adapter. More...
 
Flags_t get_flags () const
 
void set_flags (const Flags_t &flags)
 
- Static Public Member Functions inherited from Geometry
static Geometrycreate_by_typeid (Geometry_buffer *buffer, int type_id)
 
static Geometryconstruct (Geometry_buffer *buffer, const char *data, uint32 data_len, bool has_srid=true)
 Construct a Geometry object using GEOMETRY byte string. More...
 
static Geometryconstruct (Geometry_buffer *buffer, const String *str, bool has_srid=true)
 
static Geometrycreate_from_wkt (Geometry_buffer *buffer, Gis_read_stream *trs, String *wkt, bool init_stream=true, bool check_trailing=true)
 Read wkt text from trs, and write little endian wkb encoding into 'wkt', and create a Geometry instance in 'buffer'. More...
 
static Geometrycreate_from_wkb (THD *thd, Geometry_buffer *buffer, const char *wkb, uint32 len, String *res, bool init)
 Read from 'wkb' (which contains WKB encoded in either endianness) the geometry data, and write WKB of returned Geometry object in little endianness into 'res', and also create geometry object on 'buffer' and return it. More...
 
static bool is_valid_opengis_geotype (uint32 gtype)
 Check if a given geometry type is a valid geometry type according to OpenGIS. More...
 
static bool is_valid_geotype (uint32 gtype)
 Check if a given geometry type is a valid internal geometry type. More...
 
static bool is_valid_geotype (Geometry::wkbType gt)
 Check if a given geometry type is a valid internal geometry type. More...
 
static bool is_well_formed (const char *from, size_t length, wkbType type, wkbByteOrder bo)
 Verify that a string is a well-formed GEOMETRY string. More...
 
- Static Public Attributes inherited from Geometry
static const uint32 MAX_GEOM_WKB_LENGTH = 0x3fffffff
 
static const gis::srid_t default_srid = 0
 
static String bad_geometry_data
 
static Class_infoci_collection [wkb_last+1]
 
- Protected Member Functions inherited from Geometry
void append_points (String *txt, uint32 n_points, wkb_parser *wkb, uint32 offset, bool bracket_pt=false) const
 Append N points from packed format to text Before calling this function, caller must have already checked that wkb's buffer is complete and not truncated. More...
 
bool create_point (String *result, wkb_parser *wkb) const
 Create a point from data. More...
 
bool get_mbr_for_points (MBR *mbr, wkb_parser *wkb, uint offset) const
 Get most bounding rectangle (mbr) for X points. More...
 
bool is_length_verified () const
 
void set_length_verified (bool b) const
 
bool polygon_is_wkb_form () const
 In a polygon usable by boost geometry, the m_ptr points to the outer ring object, and m_inn_rings points to the inner rings, thus the polygon's data isn't stored in a single WKB. More...
 
void polygon_is_wkb_form (bool b)
 
bool has_out_of_line_components () const
 If call Gis_wkb_vector<T>::resize() to add a component to X, the geometry may have a geometry not stored inside the WKB buffer of X, hence X has out of line component. More...
 
void has_out_of_line_components (bool b)
 
void clear_wkb_data ()
 
- Static Protected Member Functions inherited from Geometry
static Class_infofind_class (int type_id)
 
static Class_infofind_class (const char *name, size_t len)
 
- Protected Attributes inherited from Geometry
Geometrym_owner
 The topmost (root) geometry object, whose m_ptr is the 1st byte of a wkb memory buffer. More...
 
void * m_ptr
 Pointer to the geometry's wkb data's 1st byte, right after its wkb header if any. More...
 
- Static Protected Attributes inherited from Geometry
static const int POLYGON_OUTER_RING = 0x1
 
static const int POLYGON_INNER_RING = 0x2
 
static const int IS_BOOST_GEOMETRY_ADAPTER = 0x4
 
static const int GEOM_LENGTH_VERIFIED = 0x8
 
static const int HAS_OUT_OF_LINE_COMPONENTS = 0x10
 
static const int POLYGON_IN_WKB_FORM = 0x20
 
static const int HAS_GEOM_HEADER_SPACE = 0x40
 
static const int MULTIPOLYGON_NO_OVERLAPPED_COMPS = 0x80
 

Detailed Description

template<typename T>
class Gis_wkb_vector< T >

Gis_wkb_vector class template definition.

Template Parameters
TVector element type

Member Typedef Documentation

◆ base

template<typename T >
typedef Geometry Gis_wkb_vector< T >::base
private

◆ const_iterator

template<typename T >
typedef Gis_wkb_vector_const_iterator<T> Gis_wkb_vector< T >::const_iterator

◆ const_pointer

template<typename T >
typedef const T* Gis_wkb_vector< T >::const_pointer

◆ const_reference

template<typename T >
typedef const T& Gis_wkb_vector< T >::const_reference

◆ difference_type

template<typename T >
typedef ptrdiff_t Gis_wkb_vector< T >::difference_type

◆ Geo_vector

template<typename T >
typedef Geometry_vector<T> Gis_wkb_vector< T >::Geo_vector

◆ index_type

template<typename T >
typedef ptrdiff_t Gis_wkb_vector< T >::index_type
private

◆ iterator

template<typename T >
typedef Gis_wkb_vector_iterator<T> Gis_wkb_vector< T >::iterator

◆ Linestring

template<typename T >
typedef Gis_wkb_vector<Gis_point> Gis_wkb_vector< T >::Linestring
private

◆ Multi_linestrings

template<typename T >
typedef Gis_wkb_vector<Linestring> Gis_wkb_vector< T >::Multi_linestrings
private

◆ pointer

template<typename T >
typedef T* Gis_wkb_vector< T >::pointer

◆ reference

template<typename T >
typedef T& Gis_wkb_vector< T >::reference

◆ self

template<typename T >
typedef Gis_wkb_vector<T> Gis_wkb_vector< T >::self
private

◆ size_type

template<typename T >
typedef size_t Gis_wkb_vector< T >::size_type

◆ value_type

template<typename T >
typedef T Gis_wkb_vector< T >::value_type

Constructor & Destructor Documentation

◆ Gis_wkb_vector() [1/3]

template<typename T >
Gis_wkb_vector< T >::Gis_wkb_vector ( const void *  ptr,
size_t  nbytes,
const Geometry::Flags_t flags,
gis::srid_t  srid,
bool  is_bg_adapter = true 
)

Constructor.

Parameters
ptrpoints to the geometry's wkb data's 1st byte, right after its wkb header if any.
nbytesthe byte order indicated by ptr's wkb header.
flagsThe geometry's flags
sridThe geometry's SRID
is_bg_adapterWhether this object is created to be used by Boost Geometry, or to be only used in MySQL code.

◆ Gis_wkb_vector() [2/3]

template<typename T >
Gis_wkb_vector< T >::Gis_wkb_vector ( const self v)

◆ Gis_wkb_vector() [3/3]

template<typename T >
Gis_wkb_vector< T >::Gis_wkb_vector ( )
inline

◆ ~Gis_wkb_vector()

template<typename T >
Gis_wkb_vector< T >::~Gis_wkb_vector ( )
inlineoverride

Member Function Documentation

◆ back() [1/2]

template<typename T >
reference Gis_wkb_vector< T >::back ( )
inline

◆ back() [2/2]

template<typename T >
const_reference Gis_wkb_vector< T >::back ( ) const
inline

◆ begin() [1/2]

template<typename T >
iterator Gis_wkb_vector< T >::begin ( void  )
inline

◆ begin() [2/2]

template<typename T >
const_iterator Gis_wkb_vector< T >::begin ( void  ) const
inline

Create a const iterator.

The created iterator can only be used to read its referenced data element. Can only be called when using a const reference to the contaienr object.

◆ clear()

template<typename T >
void Gis_wkb_vector< T >::clear

Update support We suppose updating a geometry can happen in the following ways:

  1. create an empty geo, then append components into it, the geo must be a topmost one; a complex geometry such as a multilinestring can be seen as a tree of geometry components, and the mlstr is the topmost geometry, i.e. the root of the tree, its lstrs are next layer of nodes, their points are the 3rd layer of tree nodes. Only the root owns the wkb buffer, other components point somewhere into the buffer, and can only read the data.

    Polygons are only used by getting its exterior ring or inner rings and then work on that/those rings, never used as a whole.

  2. *itr=value, each geo::m_owner can be used to track the topmost memory owner, and do reallocation to accormodate the value. This is for now not supported, will be if needed.

    So far geometry assignment are only used for point objects in boost geometry, thus only Geometry and Gis_point have operator=, no other classes need so, and thus there is no need for reallocation.

  3. call resize() to append some objects at the end, then assign/append values to the added objects using push_back. Objects added this way are out of line(unless the object is a point), and user need to call reassemble() to make them inline, i.e. stored in its owner's memory. Clear geometry data of this object.

◆ clear_wkb_data()

template<typename T >
void Gis_wkb_vector< T >::clear_wkb_data ( )
inline

◆ current_size()

template<typename T >
size_t Gis_wkb_vector< T >::current_size

Returns payload number of bytes of the topmost geometry holding this geometry, i.e.

the memory owner.

◆ donate_data()

template<typename T >
void Gis_wkb_vector< T >::donate_data ( )
inlineoverridevirtual

Reimplemented from Geometry.

◆ empty()

template<typename T >
bool Gis_wkb_vector< T >::empty ( ) const
inline

◆ end() [1/2]

template<typename T >
iterator Gis_wkb_vector< T >::end ( void  )
inline

Create an open boundary iterator.

Returns
Returns an invalid iterator denoting the position after the last valid element of the container.

◆ end() [2/2]

template<typename T >
const_iterator Gis_wkb_vector< T >::end ( void  ) const
inline

Create an open boundary iterator.

Returns
Returns an invalid const iterator denoting the position after the last valid element of the container.

◆ get_geo_vect() [1/2]

template<typename T >
Geo_vector * Gis_wkb_vector< T >::get_geo_vect ( ) const
inline

◆ get_geo_vect() [2/2]

template<typename T >
Geo_vector * Gis_wkb_vector< T >::get_geo_vect ( bool  create_if_null = false)
inline

◆ get_nbytes_free()

template<typename T >
size_t Gis_wkb_vector< T >::get_nbytes_free

Get number of free bytes in the buffer held by m_ptr.

this object must be an topmost geometry which owns memory.

◆ operator=()

template<typename T >
Gis_wkb_vector< T > & Gis_wkb_vector< T >::operator= ( const self rhs)

Deep assignment from vector 'rhs' to this object.

Parameters
rhsthe Gis_wkb_vector<T> instance to duplicate from.

◆ operator[]() [1/2]

template<typename T >
reference Gis_wkb_vector< T >::operator[] ( index_type  i)
inline

◆ operator[]() [2/2]

template<typename T >
const_reference Gis_wkb_vector< T >::operator[] ( index_type  i) const
inline

◆ push_back()

template<typename T >
void Gis_wkb_vector< T >::push_back ( const T &  val)

◆ reassemble()

template<typename T >
void Gis_wkb_vector< T >::reassemble

Because of resize, a geometry's components may reside not in one chunk, some may in the m_ptr's chunk; others have their own memory and only exist in m_geo_vect vector, not in ptr's chunk.

Also, a constructed polygon's data is always not in a chunk and needs to be so when it's pushed into a multipolygon/geometry collection. Thus in mysql before using the returned geometry, also inside the container classes before using the wkb data or clearing m_geo_vect, we need to make them inline, i.e. reside in one chunk of memory. Can only resize a topmost geometry, thus no recursive reassemling to do for now.

Algorithm:

Step 1. Structure analysis

Scan this geometry's components, see whether each of them has its own memory, if so it's 'out of line', otherwise it's 'inline'. Note down those owning memory in a map M1, for each entry X in the map M1, the component's index in the component vector m_geo_vect is used as key; The inline chunk of memory right before it which may have any number of inline components, and the inline chunk's start and end address pair is used as value of the inserted item X. If there is no inline chunk before the component, X's pointer range is (0, 0). The inline chunk's starting address is well maintained during the scan.

Step 2. Reassembling

Allocate enough memory space (the length is accumulated in step 1) as WKB buffer and call it GBuf here, then copy the WKB of inline and out-of-line geometries into GBuf in original order: Go through the map by index order, for each item, copy the WKB chunk before it into the WKB buffer, then copy this out-of-line geometry's WKB into GBuf.

Special treatment of polygon: we have to pack its value and store their WKB separately into a map GP in step 1, and in step 2 for a polygon, get its WKB from GP, and at the end release WKB memory buffers held by items of GP.

◆ resize()

template<typename T >
void Gis_wkb_vector< T >::resize ( size_t  sz)

◆ reverse_coordinates()

template<typename T >
bool Gis_wkb_vector< T >::reverse_coordinates ( )
inlineoverridevirtual

Reverses the coordinates of a geometry.

Switches the coordinates of the wkb string pointed to by the Geometry. Ex: Used on a POINT(5,2), the result would be POINT(2, 5).

Return values
falsecoordinate reversal was successful
truecoordinate reversal was unsuccessful

Implements Geometry.

◆ set_geo_vect()

template<typename T >
void Gis_wkb_vector< T >::set_geo_vect ( Geo_vector ptr)
inline

◆ set_ptr()

template<typename T >
void Gis_wkb_vector< T >::set_ptr ( void *  ptr,
size_t  len 
)

◆ shallow_push()

template<typename T >
void Gis_wkb_vector< T >::shallow_push ( const Geometry g)
overridevirtual

The copy constructors of Geometry classes always do deep copy, but when pushing a Geometry object into its owner's geo.m_geo_vect, we want to do shallow copy because we want all elements in geo.m_geo_vect vector point into locations in the geo.m_ptr buffer.

In such situations call this function.

Parameters
gThe Geometry object to push into vec.

Reimplemented from Geometry.

◆ size()

template<typename T >
size_type Gis_wkb_vector< T >::size ( ) const
inline

Get container size.

Returns
Return the number of elements in this container.

◆ validate_coordinate_range()

template<typename T >
bool Gis_wkb_vector< T >::validate_coordinate_range ( double  srs_angular_unit,
bool *  long_out_of_range,
bool *  lat_out_of_range,
double *  out_of_range_value 
)
inlineoverridevirtual

Check that the coordinates of a geometry is within the valid range.

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

Parameters
[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, or an error occurred during range checking.

Implements Geometry.

Member Data Documentation

◆ m_geo_vect

template<typename T >
Geo_vector* Gis_wkb_vector< T >::m_geo_vect
private

The geometry vector of this geometry object's components, each of which is an object of Geometry or its children classes where appropriate.


The documentation for this class was generated from the following files: