GIF89a=( �' 7IAXKgNgYvYx\%wh&h}t�h%�s%x�}9�R��&�0%� (�.��5�SD��&�a)�x5��;ͣ*ȡ&ղ)ׯ7׵<ѻ4�3�H֧KͯT��Y�aq��q��F� !� ' !� NETSCAPE2.0 , =( ��pH,�Ȥr�l:xШtJ�Z�جv��z��xL.:��z�n���|N�����~�������& !�0`9R�}��"�"a:S�~x��������g���E�������R���E����B�� ��ȸ��D���"�Ů� �H��L��D٫D�B�����D���T���H �G��A R�ڐ |�� ٭&��E8�S�kG�A�px�a��� R2XB��E8I���6X�:vT)�~��q�賥��"F~%x� � 4#Z�0O|-4Bs�X:= Q� Sal��yXJ`GȦ|s h��K3l7�B|�$'7Jީܪ0!��D�n=�P� ����0`�R�lj����v>���5 �.69�ϸd�����nlv�9��f{���Pbx �l5}�p� ��� �3a���I�O����!ܾ���i��9��#��)p�a ޽ �{�)vm��%D~ 6f��s}Œ�D�W E�`!� �&L8x� �ܝ{)x`X/>�}m��R�*|`D�=�_ ^�5 !_&'a�O�7�c��`DCx`�¥�9�Y�F���`?��"� �n@`�} lď��@4>�d S �v�xN��"@~d��=�g�s~G��� ���ud &p8Q�)ƫlXD����A~H�ySun�j���k*D�LH�] ��C"J��Xb~ʪwSt}6K,��q�S:9ت:���l�@�`�� �.۬�t9�S�[:��=`9N����{¿�A !R�:���6��x�0�_ �;������^���#����!����U���;0L1�����p% A��U̬ݵ��%�S��!���~`�G���� ���=4�np�3���������u�u�ٮ|%2�I��r�#0��J``8�@S@5� ���^`8E�]�.�S���7 � �0�j S�D� z���i�S�����!���l��w9*�D�I�nEX��� &A�Go�Qf��F��;���}�J����F5��Q|���X��T��y���]� o ��C=��:���PB@ D׽S�(>�C�x}`��xJЬ�۠��p+eE0`�}`A �/NE�� �9@��� H�7�!%B0`�l*��!8 2�%� �:�1�0E��ux%nP1�!�C)�P81l�ɸF#Ƭ{����B0>�� �b�`��O3��()yRpb��E.ZD8�H@% �Rx+%���c� ���f��b�d�`F�"8�XH"��-�|1�6iI, 2�$+](A*j� QT�o0.�U�`�R�}`�SN����yae�����b��o~ S)�y�@��3 �tT�0�&�+~L�f"�-|�~��>!�v��~�\Q1)}@�}h#aP72�"�$ !� " , =( &7IAXG]KgNgYvYxR"k\%w]'}h}t�h%�g+�s%r.m3ax3�x�}9��&��+�!7�0%� (�.�SD��&��;�"&ײ)׻4��6�K� �@pH,�Ȥr�l:xШtJ�Z�جv��z��xL.:��z�n���|N�����~�������& !�0`9R�}��"�"a:S�~x��������g �� E �� �������E �´��C���ǶR��D��"Ʒ�ʱH��M��GڬD�B����D��T����G���C�C� l&�~:'�tU�6ɹ#��)�'�.6�&��Ȼ K(8p0N�?!�2"��NIJX>R��OM '��2�*x�>#n� �@<[:�I�f ��T���Cdb��[�}E�5MBo��@�`@��tW-3 �x�B���jI�&E�9[T&$��ﯧ&"s��ȳ����dc�UUρ#���ldj?����`\}���u|3'�R]�6 �S#�!�FKL�*N E���`$�:e�YD�q�.�촁�s \-�jA 9�����-��M[�x(�s��x�|���p��}k�T�DpE@W� ��]k`1� ���Yb ��0l��*n0��"~zBd�~u�7�0Bl��0-�x~|U�U0 �h�*HS�|��e"#"?vp�i`e6^�+q��`m8 #V�� ��VS|`��"m"сSn|@:U���~`pb�G�ED����2F�I�? >�x� R� ��%~jx��<�a�9ij�2�D��&: Z`�]w���:�6��B�7eFJ|�ҧ�,���FǮcS�ʶ+B�,�ܺN���>PAD�HD��~���n��}�#�� Q��S���2�X�{�k�lQ�2�����w�|2� h9��G�,m���3��6-��E�L��I�³*K���q�`DwV�QXS��peS��� qܧTS����R�u �<�a�*At�lmE� � ��N[P1�ۦ��$��@`��Dpy�yXvCAy�B`}D� 0QwG#� �a[^�� $���Ǧ{L�"[��K�g�;�S~��GX.�goT.��ư��x���?1z��x~:�g�|�L� ��S`��0S]P�^p F<""�?!,�!N4&P� ����:T�@h�9%t��:�-~�I<`�9p I&.)^ 40D#p@�j4�ج:�01��rܼF2oW�#Z ;$Q q  �K��Nl#29 !F@�Bh�ᏬL!XF�LHKh�.�hE&J�G��<"WN!�����Y@� >R~19J"�2,/ &.GXB%�R�9B6�W]���W�I�$��9�RE8Y� ��"�A5�Q.axB�&ة�J�! �t)K%tS-�JF b�NMxL��)�R��"���6O!TH�H� 0 !� ) , =( &AXKgNgYvYxR"k\%wh&h}h%�g+�s%r.x3�x�}9��&��+�R,�!7�0%� (�.��5��&�a)��;�"&ף*Ȳ)ׯ7׻4�3��6�H֧KͻH�T��Y��q��h� ��pH,�Ȥr�l:xШtJ�Z�جv��z��xL.:��z�n���|N�����~�������& !�0`9R�}��"�"a:S�~x��������g �� E$����� � ����$E$��"��D� � ������R��C��� E ��H�M��G�D� �B��ϾD��a��`1r��Ӑ�� �o~�zU!L�C'�yW�UGt����ll�0���uG�)A�s[��x� �xO%��X2�  P�n:R/��aHae+�Dm?# ǣ6�8�J�x�Di�M���j���5oQ7�- <! *�l��R2r/a!l)d� A"�E���� &� ;��c �%����b��pe~C"B���H�eF2��`8qb�t_`ur`e� w�u3��Pv�h""�`�Íx�LĹ��3� �~ֺ�:���MDfJ� �۵�W�%�S�X �؁)�@��:E��w�u�Sxb8y\m�zS��Zb�E�L��w!y(>�"w�=�|��s�d �C�W)H�cC$�L �7r.�\{)@�`@ �X�$PD `aaG:���O�72E�amn]�"Rc�x�R� &dR8`g��i�xLR!�P &d����T���i�|�_ � Qi�#�`g:��:noM� :V �)p����W&a=�e�k� j���1߲s�x�W�jal|0��B0�, \j۴:6���C ��W��|��9���zĸV {�;��n��V�m�I��.��PN� ����C��+��By�ѾHŸ:��� 7�Y�FTk�SaoaY$D�S���29R�kt� ��f� ��:��Sp�3�I��DZ� �9���g��u�*3)O��[_hv ,���Et x�BH� �[��64M@�S�M7d�l�ܶ5-��U܍��z�R3Ԭ3~ ��P��5�g: ���kN�&0�j4���#{��3S�2�K�'ợl���2K{� {۶?~m𸧠�I�nE�='����^���_�=��~�#O���'���o..�Y�n��CSO��a��K��o,���b�����{�C�� "�{�K ��w��Ozdը�:$ ���v�] A#� ���a�z)Rx׿ƥ�d``�w-�y�f�K!����|��P��=�`�(f��'Pa ��BJa%��f�%`�}F����6>��`G"�}�=�!o`�^FP�ةQ�C���`(�}\�ݮ ��$<��n@dĠE#��U�I�!� #l��9`k���'Rr��Z�NB�MF �[�+9���-�wj���8�r� ,V�h"�|�S=�G_��"E� 0i*%̲��da0mVk�):;&6p>�jK ��# �D�:�c?:R Ӭf��I-�"�<�="��7�3S��c2RW ,�8(T"P0F¡Jh�" ; 403WebShell
403Webshell
Server IP : 173.249.157.85  /  Your IP : 3.138.109.3
Web Server : Apache
System : Linux server.frogzhost.com 3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 25 17:23:54 UTC 2020 x86_64
User : econtech ( 1005)
PHP Version : 7.3.33
Disable Function : NONE
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/include/mysql/server/private/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/include/mysql/server/private//item_geofunc.h
#ifndef ITEM_GEOFUNC_INCLUDED
#define ITEM_GEOFUNC_INCLUDED

/* Copyright (c) 2000, 2016 Oracle and/or its affiliates.
   Copyright (C) 2011, 2021, MariaDB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1335  USA */


/* This file defines all spatial functions */

#ifdef HAVE_SPATIAL

#ifdef USE_PRAGMA_INTERFACE
#pragma interface			/* gcc class implementation */
#endif

#include "gcalc_slicescan.h"
#include "gcalc_tools.h"

class Item_geometry_func: public Item_str_func
{
public:
  Item_geometry_func(THD *thd): Item_str_func(thd) {}
  Item_geometry_func(THD *thd, Item *a): Item_str_func(thd, a) {}
  Item_geometry_func(THD *thd, Item *a, Item *b): Item_str_func(thd, a, b) {}
  Item_geometry_func(THD *thd, Item *a, Item *b, Item *c):
    Item_str_func(thd, a, b, c) {}
  Item_geometry_func(THD *thd, List<Item> &list): Item_str_func(thd, list) {}
  bool fix_length_and_dec();
  const Type_handler *type_handler() const { return &type_handler_geometry; }
};


/*
  Functions returning REAL measurements of a single GEOMETRY argument
*/
class Item_real_func_args_geometry: public Item_real_func
{
protected:
  String value;
  bool check_arguments() const
  {
    DBUG_ASSERT(arg_count == 1);
    return args[0]->check_type_or_binary(func_name(), &type_handler_geometry);
  }
public:
  Item_real_func_args_geometry(THD *thd, Item *a)
   :Item_real_func(thd, a) {}
};


/*
  Functions returning INT measurements of a single GEOMETRY argument
*/
class Item_long_func_args_geometry: public Item_long_func
{
  bool check_arguments() const
  {
    DBUG_ASSERT(arg_count == 1);
    return args[0]->check_type_or_binary(func_name(), &type_handler_geometry);
  }
protected:
  String value;
public:
  Item_long_func_args_geometry(THD *thd, Item *a)
   :Item_long_func(thd, a) {}
};


/*
  Functions returning BOOL measurements of a single GEOMETRY argument
*/
class Item_bool_func_args_geometry: public Item_bool_func
{
protected:
  String value;
  bool check_arguments() const
  {
    DBUG_ASSERT(arg_count == 1);
    return args[0]->check_type_or_binary(func_name(), &type_handler_geometry);
  }
public:
  Item_bool_func_args_geometry(THD *thd, Item *a)
   :Item_bool_func(thd, a) {}
};


/*
  Functions returning ASCII string measurements of a single GEOMETRY argument
*/
class Item_str_ascii_func_args_geometry: public Item_str_ascii_func
{
protected:
  bool check_arguments() const
  {
    DBUG_ASSERT(arg_count >= 1);
    return args[0]->check_type_or_binary(func_name(), &type_handler_geometry);
  }
public:
  Item_str_ascii_func_args_geometry(THD *thd, Item *a)
   :Item_str_ascii_func(thd, a) {}
  Item_str_ascii_func_args_geometry(THD *thd, Item *a, Item *b)
   :Item_str_ascii_func(thd, a, b) {}
  Item_str_ascii_func_args_geometry(THD *thd, Item *a, Item *b, Item *c)
   :Item_str_ascii_func(thd, a, b, c) {}
};


/*
  Functions returning binary string measurements of a single GEOMETRY argument
*/
class Item_binary_func_args_geometry: public Item_str_func
{
protected:
  bool check_arguments() const
  {
    DBUG_ASSERT(arg_count >= 1);
    return args[0]->check_type_or_binary(func_name(), &type_handler_geometry);
  }
public:
  Item_binary_func_args_geometry(THD *thd, Item *a)
   :Item_str_func(thd, a) {}
};


/*
  Functions returning GEOMETRY measurements of a single GEOEMETRY argument
*/
class Item_geometry_func_args_geometry: public Item_geometry_func
{
protected:
  bool check_arguments() const
  {
    DBUG_ASSERT(arg_count >= 1);
    return args[0]->check_type_or_binary(func_name(), &type_handler_geometry);
  }
public:
  Item_geometry_func_args_geometry(THD *thd, Item *a)
   :Item_geometry_func(thd, a) {}
  Item_geometry_func_args_geometry(THD *thd, Item *a, Item *b)
   :Item_geometry_func(thd, a, b) {}
};


/*
  Functions returning REAL result relationships between two GEOMETRY arguments
*/
class Item_real_func_args_geometry_geometry: public Item_real_func
{
protected:
  bool check_arguments() const
  {
    DBUG_ASSERT(arg_count >= 2);
    return check_argument_types_or_binary(&type_handler_geometry, 0, 2);
  }
public:
  Item_real_func_args_geometry_geometry(THD *thd, Item *a, Item *b)
   :Item_real_func(thd, a, b) {}
};


/*
  Functions returning BOOL result relationships between two GEOMETRY arguments
*/
class Item_bool_func_args_geometry_geometry: public Item_bool_func
{
protected:
  String value;
  bool check_arguments() const
  {
    DBUG_ASSERT(arg_count >= 2);
    return check_argument_types_or_binary(&type_handler_geometry, 0, 2);
  }
public:
  Item_bool_func_args_geometry_geometry(THD *thd, Item *a, Item *b, Item *c)
   :Item_bool_func(thd, a, b, c) {}
};


class Item_func_geometry_from_text: public Item_geometry_func
{
  bool check_arguments() const
  {
    return args[0]->check_type_general_purpose_string(func_name()) ||
           check_argument_types_can_return_int(1, MY_MIN(2, arg_count));
  }
public:
  Item_func_geometry_from_text(THD *thd, Item *a): Item_geometry_func(thd, a) {}
  Item_func_geometry_from_text(THD *thd, Item *a, Item *srid):
    Item_geometry_func(thd, a, srid) {}
  const char *func_name() const { return "st_geometryfromtext"; }
  String *val_str(String *);
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_geometry_from_text>(thd, this); }
};

class Item_func_geometry_from_wkb: public Item_geometry_func
{
  bool check_arguments() const
  {
    return args[0]->check_type_or_binary(func_name(), &type_handler_geometry) ||
           check_argument_types_can_return_int(1, MY_MIN(2, arg_count));
  }
public:
  Item_func_geometry_from_wkb(THD *thd, Item *a): Item_geometry_func(thd, a) {}
  Item_func_geometry_from_wkb(THD *thd, Item *a, Item *srid):
    Item_geometry_func(thd, a, srid) {}
  const char *func_name() const { return "st_geometryfromwkb"; }
  String *val_str(String *);
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_geometry_from_wkb>(thd, this); }
};


class Item_func_geometry_from_json: public Item_geometry_func
{
  String tmp_js;
  bool check_arguments() const
  {
    // TODO: check with Alexey, for better args[1] and args[2] type control
    return args[0]->check_type_general_purpose_string(func_name()) ||
           check_argument_types_traditional_scalar(1, MY_MIN(3, arg_count));
  }
public:
  Item_func_geometry_from_json(THD *thd, Item *js): Item_geometry_func(thd, js) {}
  Item_func_geometry_from_json(THD *thd, Item *js, Item *opt):
    Item_geometry_func(thd, js, opt) {}
  Item_func_geometry_from_json(THD *thd, Item *js, Item *opt, Item *srid):
    Item_geometry_func(thd, js, opt, srid) {}
  const char *func_name() const { return "st_geomfromgeojson"; }
  String *val_str(String *);
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_geometry_from_json>(thd, this); }
};


class Item_func_as_wkt: public Item_str_ascii_func_args_geometry
{
public:
  Item_func_as_wkt(THD *thd, Item *a)
   :Item_str_ascii_func_args_geometry(thd, a) {}
  const char *func_name() const { return "st_astext"; }
  String *val_str_ascii(String *);
  bool fix_length_and_dec();
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_as_wkt>(thd, this); }
};

class Item_func_as_wkb: public Item_binary_func_args_geometry
{
public:
  Item_func_as_wkb(THD *thd, Item *a)
   :Item_binary_func_args_geometry(thd, a) {}
  const char *func_name() const { return "st_aswkb"; }
  String *val_str(String *);
  const Type_handler *type_handler() const { return &type_handler_long_blob; }
  bool fix_length_and_dec()
  {
    collation.set(&my_charset_bin);
    decimals=0;
    max_length= (uint32) UINT_MAX32;
    maybe_null= 1;
    return FALSE;
  }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_as_wkb>(thd, this); }
};


class Item_func_as_geojson: public Item_str_ascii_func_args_geometry
{
  bool check_arguments() const
  {
    // TODO: check with Alexey, for better args[1] and args[2] type control
    return Item_str_ascii_func_args_geometry::check_arguments() ||
           check_argument_types_traditional_scalar(1, MY_MIN(3, arg_count));
  }
public:
  Item_func_as_geojson(THD *thd, Item *js)
   :Item_str_ascii_func_args_geometry(thd, js) {}
  Item_func_as_geojson(THD *thd, Item *js, Item *max_dec_digits)
   :Item_str_ascii_func_args_geometry(thd, js, max_dec_digits) {}
  Item_func_as_geojson(THD *thd, Item *js, Item *max_dec_digits, Item *opt)
   :Item_str_ascii_func_args_geometry(thd, js, max_dec_digits, opt) {}
  const char *func_name() const { return "st_asgeojson"; }
  bool fix_length_and_dec();
  String *val_str_ascii(String *);
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_as_geojson>(thd, this); }
};


class Item_func_geometry_type: public Item_str_ascii_func_args_geometry
{
public:
  Item_func_geometry_type(THD *thd, Item *a)
   :Item_str_ascii_func_args_geometry(thd, a) {}
  String *val_str_ascii(String *);
  const char *func_name() const { return "st_geometrytype"; }
  bool fix_length_and_dec()
  {
    // "GeometryCollection" is the longest
    fix_length_and_charset(20, default_charset());
    maybe_null= 1;
    return FALSE;
  };
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_geometry_type>(thd, this); }
};


// #define HEAVY_CONVEX_HULL
class Item_func_convexhull: public Item_geometry_func_args_geometry
{
  class ch_node: public Gcalc_dyn_list::Item
  {
  public:
    const Gcalc_heap::Info *pi;
    ch_node *prev;
    Gcalc_dyn_list::Item *next;
    ch_node *get_next() { return (ch_node *) next; }
  };

  Gcalc_heap collector;
  Gcalc_function func;
  Gcalc_dyn_list res_heap;

  Gcalc_result_receiver res_receiver;
  String tmp_value;
#ifdef HEAVY_CONVEX_HULL
  Gcalc_scan_iterator scan_it;
#endif /*HEAVY_CONVEX_HULL*/
  ch_node *new_ch_node() { return (ch_node *) res_heap.new_item(); }
  int add_node_to_line(ch_node **p_cur, int dir, const Gcalc_heap::Info *pi);
public:
  Item_func_convexhull(THD *thd, Item *a)
   :Item_geometry_func_args_geometry(thd, a),
    res_heap(8192, sizeof(ch_node))
    {}
  const char *func_name() const { return "st_convexhull"; }
  String *val_str(String *);
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_convexhull>(thd, this); }
};


class Item_func_centroid: public Item_geometry_func_args_geometry
{
public:
  Item_func_centroid(THD *thd, Item *a)
   :Item_geometry_func_args_geometry(thd, a) {}
  const char *func_name() const { return "st_centroid"; }
  String *val_str(String *);
  Field::geometry_type get_geometry_type() const;
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_centroid>(thd, this); }
};

class Item_func_envelope: public Item_geometry_func_args_geometry
{
public:
  Item_func_envelope(THD *thd, Item *a)
   :Item_geometry_func_args_geometry(thd, a) {}
  const char *func_name() const { return "st_envelope"; }
  String *val_str(String *);
  Field::geometry_type get_geometry_type() const;
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_envelope>(thd, this); }
};


class Item_func_boundary: public Item_geometry_func_args_geometry
{
  class Transporter : public Gcalc_shape_transporter
  {
    Gcalc_result_receiver *m_receiver;
    uint n_points;
    Gcalc_function::shape_type current_type;
    double last_x, last_y;
  public:
    Transporter(Gcalc_result_receiver *receiver) :
      Gcalc_shape_transporter(NULL), m_receiver(receiver)
    {}
    int single_point(double x, double y);
    int start_line();
    int complete_line();
    int start_poly();
    int complete_poly();
    int start_ring();
    int complete_ring();
    int add_point(double x, double y);

    int start_collection(int n_objects);
  };
  Gcalc_result_receiver res_receiver;
public:
  Item_func_boundary(THD *thd, Item *a)
   :Item_geometry_func_args_geometry(thd, a) {}
  const char *func_name() const { return "st_boundary"; }
  String *val_str(String *);
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_boundary>(thd, this); }
};


class Item_func_point: public Item_geometry_func
{
  bool check_arguments() const
  { return check_argument_types_can_return_real(0, 2); }
public:
  Item_func_point(THD *thd, Item *a, Item *b): Item_geometry_func(thd, a, b) {}
  Item_func_point(THD *thd, Item *a, Item *b, Item *srid):
    Item_geometry_func(thd, a, b, srid) {}
  const char *func_name() const { return "point"; }
  String *val_str(String *);
  Field::geometry_type get_geometry_type() const;
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_point>(thd, this); }
};

class Item_func_spatial_decomp: public Item_geometry_func_args_geometry
{
  enum Functype decomp_func;
public:
  Item_func_spatial_decomp(THD *thd, Item *a, Item_func::Functype ft):
    Item_geometry_func_args_geometry(thd, a) { decomp_func = ft; }
  const char *func_name() const 
  { 
    switch (decomp_func)
    {
      case SP_STARTPOINT:
        return "st_startpoint";
      case SP_ENDPOINT:
        return "st_endpoint";
      case SP_EXTERIORRING:
        return "st_exteriorring";
      default:
	DBUG_ASSERT(0);  // Should never happened
        return "spatial_decomp_unknown"; 
    }
  }
  String *val_str(String *);
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_spatial_decomp>(thd, this); }
};

class Item_func_spatial_decomp_n: public Item_geometry_func_args_geometry
{
  enum Functype decomp_func_n;
  bool check_arguments() const
  {
    return Item_geometry_func_args_geometry::check_arguments() ||
           args[1]->check_type_can_return_int(func_name());
  }
public:
  Item_func_spatial_decomp_n(THD *thd, Item *a, Item *b, Item_func::Functype ft)
   :Item_geometry_func_args_geometry(thd, a, b),
    decomp_func_n(ft)
  { }
  const char *func_name() const 
  { 
    switch (decomp_func_n)
    {
      case SP_POINTN:
        return "st_pointn";
      case SP_GEOMETRYN:
        return "st_geometryn";
      case SP_INTERIORRINGN:
        return "st_interiorringn";
      default:
	DBUG_ASSERT(0);  // Should never happened
        return "spatial_decomp_n_unknown"; 
    }
  }
  String *val_str(String *);
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_spatial_decomp_n>(thd, this); }
};

class Item_func_spatial_collection: public Item_geometry_func
{
  bool check_arguments() const
  {
    return check_argument_types_or_binary(&type_handler_geometry, 0, arg_count);
  }
  enum Geometry::wkbType coll_type; 
  enum Geometry::wkbType item_type;
public:
  Item_func_spatial_collection(THD *thd,
     List<Item> &list, enum Geometry::wkbType ct, enum Geometry::wkbType it):
  Item_geometry_func(thd, list)
  {
    coll_type=ct;
    item_type=it;
  }
  String *val_str(String *);
  bool fix_length_and_dec()
  {
    if (Item_geometry_func::fix_length_and_dec())
      return TRUE;
    for (unsigned int i= 0; i < arg_count; ++i)
    {
      if (args[i]->fixed && args[i]->field_type() != MYSQL_TYPE_GEOMETRY)
      {
        String str;
        args[i]->print(&str, QT_NO_DATA_EXPANSION);
        str.append('\0');
        my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0), "non geometric",
                 str.ptr());
        return TRUE;
      }
    }
    return FALSE;
  }
 
  const char *func_name() const { return "geometrycollection"; }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_spatial_collection>(thd, this); }
};


/*
  Spatial relations
*/

class Item_func_spatial_rel: public Item_bool_func2_with_rev
{
protected:
  enum Functype spatial_rel;
  String tmp_value1, tmp_value2;
  SEL_ARG *get_mm_leaf(RANGE_OPT_PARAM *param, Field *field,
                       KEY_PART *key_part,
                       Item_func::Functype type, Item *value);
  bool check_arguments() const
  {
    DBUG_ASSERT(arg_count >= 2);
    return check_argument_types_or_binary(&type_handler_geometry, 0, 2);
  }
public:
  Item_func_spatial_rel(THD *thd, Item *a, Item *b, enum Functype sp_rel):
    Item_bool_func2_with_rev(thd, a, b), spatial_rel(sp_rel)
  {
    maybe_null= true;
  }
  enum Functype functype() const { return spatial_rel; }
  enum Functype rev_functype() const
  {
    switch (spatial_rel)
    {
      case SP_CONTAINS_FUNC:
        return SP_WITHIN_FUNC;
      case SP_WITHIN_FUNC:
        return SP_CONTAINS_FUNC;
      default:
        return spatial_rel;
    }
  }
  bool is_null() { (void) val_int(); return null_value; }
  void add_key_fields(JOIN *join, KEY_FIELD **key_fields,
                      uint *and_level, table_map usable_tables,
                      SARGABLE_PARAM **sargables)
  {
    return add_key_fields_optimize_op(join, key_fields, and_level,
                                      usable_tables, sargables, false);
  }
  bool need_parentheses_in_default() { return false; }
  Item *build_clone(THD *thd) { return 0; }
};


class Item_func_spatial_mbr_rel: public Item_func_spatial_rel
{
public:
  Item_func_spatial_mbr_rel(THD *thd, Item *a, Item *b, enum Functype sp_rel):
    Item_func_spatial_rel(thd, a, b, sp_rel)
  { }
  longlong val_int();
  const char *func_name() const;
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_spatial_mbr_rel>(thd, this); }
};


class Item_func_spatial_precise_rel: public Item_func_spatial_rel
{
  Gcalc_heap collector;
  Gcalc_scan_iterator scan_it;
  Gcalc_function func;
public:
  Item_func_spatial_precise_rel(THD *thd, Item *a, Item *b, enum Functype sp_rel):
    Item_func_spatial_rel(thd, a, b, sp_rel), collector()
  { }
  longlong val_int();
  const char *func_name() const;
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_spatial_precise_rel>(thd, this); }
};


class Item_func_spatial_relate: public Item_bool_func_args_geometry_geometry
{
  Gcalc_heap collector;
  Gcalc_scan_iterator scan_it;
  Gcalc_function func;
  String tmp_value1, tmp_value2, tmp_matrix;
  bool check_arguments() const
  {
    return Item_bool_func_args_geometry_geometry::check_arguments() ||
           args[2]->check_type_general_purpose_string(func_name());
  }
public:
  Item_func_spatial_relate(THD *thd, Item *a, Item *b, Item *matrix):
    Item_bool_func_args_geometry_geometry(thd, a, b, matrix)
  { }
  longlong val_int();
  const char *func_name() const { return "st_relate"; }
  bool need_parentheses_in_default() { return false; }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_spatial_relate>(thd, this); }
};


/*
  Spatial operations
*/

class Item_func_spatial_operation: public Item_geometry_func
{
  bool check_arguments() const
  {
    DBUG_ASSERT(arg_count >= 2);
    return check_argument_types_or_binary(&type_handler_geometry, 0, 2);
  }
public:
  Gcalc_function::op_type spatial_op;
  Gcalc_heap collector;
  Gcalc_function func;

  Gcalc_result_receiver res_receiver;
  Gcalc_operation_reducer operation;
  String tmp_value1,tmp_value2;
public:
  Item_func_spatial_operation(THD *thd, Item *a,Item *b,
                              Gcalc_function::op_type sp_op):
    Item_geometry_func(thd, a, b), spatial_op(sp_op)
  {}
  virtual ~Item_func_spatial_operation();
  String *val_str(String *);
  const char *func_name() const;
  virtual inline void print(String *str, enum_query_type query_type)
  {
    Item_func::print(str, query_type);
  }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_spatial_operation>(thd, this); }
};


class Item_func_buffer: public Item_geometry_func_args_geometry
{
  bool check_arguments() const
  {
    return Item_geometry_func_args_geometry::check_arguments() ||
           args[1]->check_type_can_return_real(func_name());
  }
protected:
  class Transporter : public Gcalc_operation_transporter
  {
    int m_npoints;
    double m_d;
    double x1,y1,x2,y2;
    double x00,y00,x01,y01;
    int add_edge_buffer(double x3, double y3, bool round_p1, bool round_p2);
    int add_last_edge_buffer();
    int add_point_buffer(double x, double y);
    int complete();
    int m_nshapes;
    Gcalc_function::op_type buffer_op;
    int last_shape_pos;
    bool skip_line;

  public:
    Transporter(Gcalc_function *fn, Gcalc_heap *heap, double d) :
      Gcalc_operation_transporter(fn, heap), m_npoints(0), m_d(d),
      m_nshapes(0), buffer_op((d > 0.0) ? Gcalc_function::op_union :
                                          Gcalc_function::op_difference),
      skip_line(FALSE)
    {}
    int single_point(double x, double y);
    int start_line();
    int complete_line();
    int start_poly();
    int complete_poly();
    int start_ring();
    int complete_ring();
    int add_point(double x, double y);

    int start_collection(int n_objects);
  };
  Gcalc_heap collector;
  Gcalc_function func;

  Gcalc_result_receiver res_receiver;
  Gcalc_operation_reducer operation;

public:
  Item_func_buffer(THD *thd, Item *obj, Item *distance)
   :Item_geometry_func_args_geometry(thd, obj, distance) {}
  const char *func_name() const { return "st_buffer"; }
  String *val_str(String *);
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_buffer>(thd, this); }
};


class Item_func_isempty: public Item_bool_func_args_geometry
{
public:
  Item_func_isempty(THD *thd, Item *a)
   :Item_bool_func_args_geometry(thd, a) {}
  longlong val_int();
  const char *func_name() const { return "st_isempty"; }
  bool fix_length_and_dec() { maybe_null= 1; return FALSE; }
  bool need_parentheses_in_default() { return false; }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_isempty>(thd, this); }
};

class Item_func_issimple: public Item_long_func_args_geometry
{
  Gcalc_heap collector;
  Gcalc_function func;
  Gcalc_scan_iterator scan_it;
  String tmp;
public:
  Item_func_issimple(THD *thd, Item *a)
   :Item_long_func_args_geometry(thd, a) {}
  longlong val_int();
  const char *func_name() const { return "st_issimple"; }
  bool fix_length_and_dec() { decimals=0; max_length=2; return FALSE; }
  uint decimal_precision() const { return 1; }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_issimple>(thd, this); }
};

class Item_func_isclosed: public Item_long_func_args_geometry
{
public:
  Item_func_isclosed(THD *thd, Item *a)
   :Item_long_func_args_geometry(thd, a) {}
  longlong val_int();
  const char *func_name() const { return "st_isclosed"; }
  bool fix_length_and_dec() { decimals=0; max_length=2; return FALSE; }
  uint decimal_precision() const { return 1; }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_isclosed>(thd, this); }
};

class Item_func_isring: public Item_func_issimple
{
public:
  Item_func_isring(THD *thd, Item *a): Item_func_issimple(thd, a) {}
  longlong val_int();
  const char *func_name() const { return "st_isring"; }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_isring>(thd, this); }
};

class Item_func_dimension: public Item_long_func_args_geometry
{
public:
  Item_func_dimension(THD *thd, Item *a)
   :Item_long_func_args_geometry(thd, a) {}
  longlong val_int();
  const char *func_name() const { return "st_dimension"; }
  bool fix_length_and_dec() { max_length= 10; maybe_null= 1; return FALSE; }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_dimension>(thd, this); }
};


class Item_func_x: public Item_real_func_args_geometry
{
public:
  Item_func_x(THD *thd, Item *a): Item_real_func_args_geometry(thd, a) {}
  double val_real();
  const char *func_name() const { return "st_x"; }
  bool fix_length_and_dec()
  {
    if (Item_real_func::fix_length_and_dec())
      return TRUE;
    maybe_null= 1;
    return FALSE;
  }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_x>(thd, this); }
};


class Item_func_y: public Item_real_func_args_geometry
{
public:
  Item_func_y(THD *thd, Item *a): Item_real_func_args_geometry(thd, a) {}
  double val_real();
  const char *func_name() const { return "st_y"; }
  bool fix_length_and_dec()
  {
    if (Item_real_func::fix_length_and_dec())
      return TRUE;
    maybe_null= 1;
    return FALSE;
  }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_y>(thd, this); }
};


class Item_func_numgeometries: public Item_long_func_args_geometry
{
public:
  Item_func_numgeometries(THD *thd, Item *a)
   :Item_long_func_args_geometry(thd, a) {}
  longlong val_int();
  const char *func_name() const { return "st_numgeometries"; }
  bool fix_length_and_dec() { max_length= 10; maybe_null= 1; return FALSE; }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_numgeometries>(thd, this); }
};


class Item_func_numinteriorring: public Item_long_func_args_geometry
{
public:
  Item_func_numinteriorring(THD *thd, Item *a)
   :Item_long_func_args_geometry(thd, a) {}
  longlong val_int();
  const char *func_name() const { return "st_numinteriorrings"; }
  bool fix_length_and_dec() { max_length= 10; maybe_null= 1; return FALSE; }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_numinteriorring>(thd, this); }
};


class Item_func_numpoints: public Item_long_func_args_geometry
{
public:
  Item_func_numpoints(THD *thd, Item *a)
   :Item_long_func_args_geometry(thd, a) {}
  longlong val_int();
  const char *func_name() const { return "st_numpoints"; }
  bool fix_length_and_dec() { max_length= 10; maybe_null= 1; return FALSE; }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_numpoints>(thd, this); }
};


class Item_func_area: public Item_real_func_args_geometry
{
public:
  Item_func_area(THD *thd, Item *a): Item_real_func_args_geometry(thd, a) {}
  double val_real();
  const char *func_name() const { return "st_area"; }
  bool fix_length_and_dec()
  {
    if (Item_real_func::fix_length_and_dec())
      return TRUE;
    maybe_null= 1;
    return FALSE;
  }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_area>(thd, this); }
};


class Item_func_glength: public Item_real_func_args_geometry
{
  String value;
public:
  Item_func_glength(THD *thd, Item *a)
   :Item_real_func_args_geometry(thd, a) {}
  double val_real();
  const char *func_name() const { return "st_length"; }
  bool fix_length_and_dec()
  {
    if (Item_real_func::fix_length_and_dec())
      return TRUE;
    maybe_null= 1;
    return FALSE;
  }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_glength>(thd, this); }
};


class Item_func_srid: public Item_long_func_args_geometry
{
public:
  Item_func_srid(THD *thd, Item *a)
   :Item_long_func_args_geometry(thd, a) {}
  longlong val_int();
  const char *func_name() const { return "srid"; }
  bool fix_length_and_dec() { max_length= 10; maybe_null= 1; return FALSE; }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_srid>(thd, this); }
};


class Item_func_distance: public Item_real_func_args_geometry_geometry
{
  String tmp_value1;
  String tmp_value2;
  Gcalc_heap collector;
  Gcalc_function func;
  Gcalc_scan_iterator scan_it;
public:
  Item_func_distance(THD *thd, Item *a, Item *b)
   :Item_real_func_args_geometry_geometry(thd, a, b) {}
  double val_real();
  const char *func_name() const { return "st_distance"; }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_distance>(thd, this); }
};


class Item_func_sphere_distance: public Item_real_func
{
  double spherical_distance_points(Geometry *g1, Geometry *g2,
                                   const double sphere_r);
public:
  Item_func_sphere_distance(THD *thd, List<Item> &list):
    Item_real_func(thd, list) {}
  double val_real();
  const char *func_name() const { return "st_distance_sphere"; }
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_sphere_distance>(thd, this); }
};


class Item_func_pointonsurface: public Item_geometry_func_args_geometry
{
  String tmp_value;
  Gcalc_heap collector;
  Gcalc_function func;
  Gcalc_scan_iterator scan_it;
public:
  Item_func_pointonsurface(THD *thd, Item *a)
   :Item_geometry_func_args_geometry(thd, a) {}
  const char *func_name() const { return "st_pointonsurface"; }
  String *val_str(String *);
  Field::geometry_type get_geometry_type() const;
  Item *get_copy(THD *thd)
  { return get_item_copy<Item_func_pointonsurface>(thd, this); }
};


#ifndef DBUG_OFF
class Item_func_gis_debug: public Item_long_func
{
  public:
    Item_func_gis_debug(THD *thd, Item *a): Item_long_func(thd, a)
    { null_value= false; }
    bool fix_length_and_dec() { fix_char_length(10); return FALSE; }
    const char *func_name() const  { return "st_gis_debug"; }
    longlong val_int();
    bool check_vcol_func_processor(void *arg)
    {
      return mark_unsupported_function(func_name(), "()", arg, VCOL_IMPOSSIBLE);
    }
    Item *get_copy(THD *thd)
    { return get_item_copy<Item_func_gis_debug>(thd, this); }
};
#endif


#define GEOM_NEW(thd, obj_constructor) new (thd->mem_root) obj_constructor

#else /*HAVE_SPATIAL*/

#define GEOM_NEW(thd, obj_constructor) NULL

#endif /*HAVE_SPATIAL*/
#endif /* ITEM_GEOFUNC_INCLUDED */

Youez - 2016 - github.com/yon3zu
LinuXploit