diff options
author | Alexey Botchkov <holyfoot@mysql.com> | 2011-05-04 23:20:17 +0500 |
---|---|---|
committer | Alexey Botchkov <holyfoot@mysql.com> | 2011-05-04 23:20:17 +0500 |
commit | 788043cd0b20e01fc07f8a4673de678404938240 (patch) | |
tree | 934b397b431e04ee4875519a1ed20a0088a7d292 /sql/item_geofunc.h | |
parent | aaf9fb0de706da2924bdcb2533b1eda6933aca61 (diff) | |
download | mariadb-git-788043cd0b20e01fc07f8a4673de678404938240.tar.gz |
Precise GIS functions added.
Diffstat (limited to 'sql/item_geofunc.h')
-rw-r--r-- | sql/item_geofunc.h | 227 |
1 files changed, 161 insertions, 66 deletions
diff --git a/sql/item_geofunc.h b/sql/item_geofunc.h index 0bcd933e52b..1838a3783e8 100644 --- a/sql/item_geofunc.h +++ b/sql/item_geofunc.h @@ -1,4 +1,7 @@ -/* Copyright (c) 2003, 2011, Oracle and/or its affiliates. +#ifndef ITEM_GEOFUNC_INCLUDED +#define ITEM_GEOFUNC_INCLUDED + +/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 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 @@ -10,8 +13,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + along with this program; if not, write to the Free Software Foundation, + 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ /* This file defines all spatial functions */ @@ -22,6 +25,8 @@ #pragma interface /* gcc class implementation */ #endif +#include "gcalc_slicescan.h" + class Item_geometry_func: public Item_str_func { public: @@ -41,7 +46,7 @@ class Item_func_geometry_from_text: public Item_geometry_func public: Item_func_geometry_from_text(Item *a) :Item_geometry_func(a) {} Item_func_geometry_from_text(Item *a, Item *srid) :Item_geometry_func(a, srid) {} - const char *func_name() const { return "geometryfromtext"; } + const char *func_name() const { return "st_geometryfromtext"; } String *val_str(String *); }; @@ -50,7 +55,7 @@ class Item_func_geometry_from_wkb: public Item_geometry_func public: Item_func_geometry_from_wkb(Item *a): Item_geometry_func(a) {} Item_func_geometry_from_wkb(Item *a, Item *srid): Item_geometry_func(a, srid) {} - const char *func_name() const { return "geometryfromwkb"; } + const char *func_name() const { return "st_geometryfromwkb"; } String *val_str(String *); }; @@ -58,7 +63,7 @@ class Item_func_as_wkt: public Item_str_func { public: Item_func_as_wkt(Item *a): Item_str_func(a) {} - const char *func_name() const { return "astext"; } + const char *func_name() const { return "st_astext"; } String *val_str(String *); void fix_length_and_dec(); }; @@ -67,7 +72,7 @@ class Item_func_as_wkb: public Item_geometry_func { public: Item_func_as_wkb(Item *a): Item_geometry_func(a) {} - const char *func_name() const { return "aswkb"; } + const char *func_name() const { return "st_aswkb"; } String *val_str(String *); enum_field_types field_type() const { return MYSQL_TYPE_BLOB; } }; @@ -77,11 +82,12 @@ class Item_func_geometry_type: public Item_str_func public: Item_func_geometry_type(Item *a): Item_str_func(a) {} String *val_str(String *); - const char *func_name() const { return "geometrytype"; } + const char *func_name() const { return "st_geometrytype"; } void fix_length_and_dec() { - max_length=20; // "GeometryCollection" is the most long - maybe_null= 1; + // "GeometryCollection" is the longest + max_length= 20; + maybe_null= 1; }; }; @@ -89,7 +95,7 @@ class Item_func_centroid: public Item_geometry_func { public: Item_func_centroid(Item *a): Item_geometry_func(a) {} - const char *func_name() const { return "centroid"; } + const char *func_name() const { return "st_centroid"; } String *val_str(String *); Field::geometry_type get_geometry_type() const; }; @@ -98,7 +104,7 @@ class Item_func_envelope: public Item_geometry_func { public: Item_func_envelope(Item *a): Item_geometry_func(a) {} - const char *func_name() const { return "envelope"; } + const char *func_name() const { return "st_envelope"; } String *val_str(String *); Field::geometry_type get_geometry_type() const; }; @@ -108,7 +114,7 @@ class Item_func_point: public Item_geometry_func public: Item_func_point(Item *a, Item *b): Item_geometry_func(a, b) {} Item_func_point(Item *a, Item *b, Item *srid): Item_geometry_func(a, b, srid) {} - const char *func_name() const { return "point"; } + const char *func_name() const { return "st_point"; } String *val_str(String *); Field::geometry_type get_geometry_type() const; }; @@ -124,11 +130,11 @@ public: switch (decomp_func) { case SP_STARTPOINT: - return "startpoint"; + return "st_startpoint"; case SP_ENDPOINT: - return "endpoint"; + return "st_endpoint"; case SP_EXTERIORRING: - return "exteriorring"; + return "st_exteriorring"; default: DBUG_ASSERT(0); // Should never happened return "spatial_decomp_unknown"; @@ -148,11 +154,11 @@ public: switch (decomp_func_n) { case SP_POINTN: - return "pointn"; + return "st_pointn"; case SP_GEOMETRYN: - return "geometryn"; + return "st_geometryn"; case SP_INTERIORRINGN: - return "interiorringn"; + return "st_interiorringn"; default: DBUG_ASSERT(0); // Should never happened return "spatial_decomp_n_unknown"; @@ -177,7 +183,6 @@ public: String *val_str(String *); void fix_length_and_dec() { - Item_geometry_func::fix_length_and_dec(); for (unsigned int i= 0; i < arg_count; ++i) { if (args[i]->fixed && args[i]->field_type() != MYSQL_TYPE_GEOMETRY) @@ -191,57 +196,53 @@ public: } } - const char *func_name() const { return "multipoint"; } + const char *func_name() const { return "st_multipoint"; } }; + /* Spatial relations */ -class Item_func_spatial_rel: public Item_bool_func2 +class Item_func_spatial_mbr_rel: public Item_bool_func2 { enum Functype spatial_rel; public: - Item_func_spatial_rel(Item *a,Item *b, enum Functype sp_rel) : + Item_func_spatial_mbr_rel(Item *a,Item *b, enum Functype sp_rel) : Item_bool_func2(a,b) { spatial_rel = sp_rel; } longlong val_int(); enum Functype 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; - } + return spatial_rel; } enum Functype rev_functype() const { return spatial_rel; } - const char *func_name() const - { - switch (spatial_rel) { - case SP_CONTAINS_FUNC: - return "contains"; - case SP_WITHIN_FUNC: - return "within"; - case SP_EQUALS_FUNC: - return "equals"; - case SP_DISJOINT_FUNC: - return "disjoint"; - case SP_INTERSECTS_FUNC: - return "intersects"; - case SP_TOUCHES_FUNC: - return "touches"; - case SP_CROSSES_FUNC: - return "crosses"; - case SP_OVERLAPS_FUNC: - return "overlaps"; - default: - DBUG_ASSERT(0); // Should never happened - return "sp_unknown"; - } + const char *func_name() const; + virtual inline void print(String *str, enum_query_type query_type) + { + Item_func::print(str, query_type); } + void fix_length_and_dec() { maybe_null= 1; } + bool is_null() { (void) val_int(); return null_value; } +}; + +class Item_func_spatial_rel: public Item_bool_func2 +{ + enum Functype spatial_rel; + Gcalc_heap collector; + Gcalc_scan_iterator scan_it; + Gcalc_function func; + String tmp_value1,tmp_value2; +public: + Item_func_spatial_rel(Item *a,Item *b, enum Functype sp_rel); + virtual ~Item_func_spatial_rel(); + longlong val_int(); + enum Functype functype() const + { + return spatial_rel; + } + enum Functype rev_functype() const { return spatial_rel; } + const char *func_name() const; virtual inline void print(String *str, enum_query_type query_type) { Item_func::print(str, query_type); @@ -249,25 +250,104 @@ public: void fix_length_and_dec() { maybe_null= 1; } bool is_null() { (void) val_int(); return null_value; } +protected: + int func_touches(); + int func_equals(); }; + +/* + Spatial operations +*/ + +class Item_func_spatial_operation: public Item_geometry_func +{ +public: + Gcalc_function::op_type spatial_op; + Gcalc_heap collector; + Gcalc_function func; + Gcalc_scan_iterator scan_it; + + Gcalc_result_receiver res_receiver; + Gcalc_operation_reducer operation; + String tmp_value1,tmp_value2; +public: + Item_func_spatial_operation(Item *a,Item *b, Gcalc_function::op_type sp_op) : + Item_geometry_func(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); + } +}; + + +class Item_func_buffer: public Item_geometry_func +{ +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(); + public: + int m_nshapes; + Transporter(Gcalc_function *fn, Gcalc_heap *heap, double d) : + Gcalc_operation_transporter(fn, heap), m_npoints(0), m_d(d), m_nshapes(0) + {} + int single_point(double x, double y); + int start_line(); + int complete_line(); + int start_poly(); + int start_ring(); + int complete_ring(); + int add_point(double x, double y); + }; + Gcalc_heap collector; + Gcalc_function func; + Gcalc_scan_iterator scan_it; + + Gcalc_result_receiver res_receiver; + Gcalc_operation_reducer operation; + String tmp_value; + +public: + Item_func_buffer(Item *obj, Item *distance): + Item_geometry_func(obj, distance) {} + const char *func_name() const { return "st_buffer"; } + String *val_str(String *); +}; + + class Item_func_isempty: public Item_bool_func { public: Item_func_isempty(Item *a): Item_bool_func(a) {} longlong val_int(); optimize_type select_optimize() const { return OPTIMIZE_NONE; } - const char *func_name() const { return "isempty"; } + const char *func_name() const { return "st_isempty"; } void fix_length_and_dec() { maybe_null= 1; } }; class Item_func_issimple: public Item_bool_func { + Gcalc_heap collector; + Gcalc_function func; + Gcalc_scan_iterator scan_it; + String tmp; public: Item_func_issimple(Item *a): Item_bool_func(a) {} longlong val_int(); optimize_type select_optimize() const { return OPTIMIZE_NONE; } - const char *func_name() const { return "issimple"; } + const char *func_name() const { return "st_issimple"; } void fix_length_and_dec() { maybe_null= 1; } }; @@ -277,7 +357,7 @@ public: Item_func_isclosed(Item *a): Item_bool_func(a) {} longlong val_int(); optimize_type select_optimize() const { return OPTIMIZE_NONE; } - const char *func_name() const { return "isclosed"; } + const char *func_name() const { return "st_isclosed"; } void fix_length_and_dec() { maybe_null= 1; } }; @@ -287,7 +367,7 @@ class Item_func_dimension: public Item_int_func public: Item_func_dimension(Item *a): Item_int_func(a) {} longlong val_int(); - const char *func_name() const { return "dimension"; } + const char *func_name() const { return "st_dimension"; } void fix_length_and_dec() { max_length= 10; maybe_null= 1; } }; @@ -297,7 +377,7 @@ class Item_func_x: public Item_real_func public: Item_func_x(Item *a): Item_real_func(a) {} double val_real(); - const char *func_name() const { return "x"; } + const char *func_name() const { return "st_x"; } void fix_length_and_dec() { Item_real_func::fix_length_and_dec(); @@ -312,7 +392,7 @@ class Item_func_y: public Item_real_func public: Item_func_y(Item *a): Item_real_func(a) {} double val_real(); - const char *func_name() const { return "y"; } + const char *func_name() const { return "st_y"; } void fix_length_and_dec() { Item_real_func::fix_length_and_dec(); @@ -327,7 +407,7 @@ class Item_func_numgeometries: public Item_int_func public: Item_func_numgeometries(Item *a): Item_int_func(a) {} longlong val_int(); - const char *func_name() const { return "numgeometries"; } + const char *func_name() const { return "st_numgeometries"; } void fix_length_and_dec() { max_length= 10; maybe_null= 1; } }; @@ -338,7 +418,7 @@ class Item_func_numinteriorring: public Item_int_func public: Item_func_numinteriorring(Item *a): Item_int_func(a) {} longlong val_int(); - const char *func_name() const { return "numinteriorrings"; } + const char *func_name() const { return "st_numinteriorrings"; } void fix_length_and_dec() { max_length= 10; maybe_null= 1; } }; @@ -349,7 +429,7 @@ class Item_func_numpoints: public Item_int_func public: Item_func_numpoints(Item *a): Item_int_func(a) {} longlong val_int(); - const char *func_name() const { return "numpoints"; } + const char *func_name() const { return "st_numpoints"; } void fix_length_and_dec() { max_length= 10; maybe_null= 1; } }; @@ -360,7 +440,7 @@ class Item_func_area: public Item_real_func public: Item_func_area(Item *a): Item_real_func(a) {} double val_real(); - const char *func_name() const { return "area"; } + const char *func_name() const { return "st_area"; } void fix_length_and_dec() { Item_real_func::fix_length_and_dec(); @@ -375,7 +455,7 @@ class Item_func_glength: public Item_real_func public: Item_func_glength(Item *a): Item_real_func(a) {} double val_real(); - const char *func_name() const { return "glength"; } + const char *func_name() const { return "st_length"; } void fix_length_and_dec() { Item_real_func::fix_length_and_dec(); @@ -394,11 +474,26 @@ public: void fix_length_and_dec() { max_length= 10; maybe_null= 1; } }; + +class Item_func_distance: public Item_real_func +{ + String tmp_value1; + String tmp_value2; + Gcalc_heap collector; + Gcalc_function func; + Gcalc_scan_iterator scan_it; +public: + Item_func_distance(Item *a, Item *b): Item_real_func(a, b) {} + double val_real(); + const char *func_name() const { return "st_distance"; } +}; + #define GEOM_NEW(thd, obj_constructor) new (thd->mem_root) obj_constructor #else /*HAVE_SPATIAL*/ #define GEOM_NEW(thd, obj_constructor) NULL -#endif +#endif /*HAVE_SPATIAL*/ +#endif /*ITEM_GEOFUNC_INCLUDED*/ |