item_geofunc.h 8.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* Copyright (C) 2000-2003 MySQL AB

   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; either version 2 of the License, or
   (at your option) any later version.

   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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */


/* This file defines all spatial functions */

hf@deer.(none)'s avatar
hf@deer.(none) committed
20 21
#ifdef HAVE_SPATIAL

22
#ifdef USE_PRAGMA_INTERFACE
23 24 25
#pragma interface			/* gcc class implementation */
#endif

26
class Item_geometry_func: public Item_str_func
27 28
{
public:
29 30 31 32 33 34 35 36 37 38 39 40 41
  Item_geometry_func() :Item_str_func() {}
  Item_geometry_func(Item *a) :Item_str_func(a) {}
  Item_geometry_func(Item *a,Item *b) :Item_str_func(a,b) {}
  Item_geometry_func(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {}
  Item_geometry_func(List<Item> &list) :Item_str_func(list) {}
  void fix_length_and_dec();
};

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) {}
42 43 44 45
  const char *func_name() const { return "geometryfromtext"; }
  String *val_str(String *);
};

46
class Item_func_geometry_from_wkb: public Item_geometry_func
47 48
{
public:
49 50
  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) {}
51 52 53 54
  const char *func_name() const { return "geometryfromwkb"; }
  String *val_str(String *);
};

55
class Item_func_as_wkt: public Item_str_func
56 57
{
public:
58
  Item_func_as_wkt(Item *a): Item_str_func(a) {}
59 60 61 62 63
  const char *func_name() const { return "astext"; }
  String *val_str(String *);
  void fix_length_and_dec();
};

64
class Item_func_as_wkb: public Item_geometry_func
65 66
{
public:
67
  Item_func_as_wkb(Item *a): Item_geometry_func(a) {}
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
  const char *func_name() const { return "aswkb"; }
  String *val_str(String *);
};

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"; }
  void fix_length_and_dec() 
  {
     max_length=20; // "GeometryCollection" is the most long
  };
};

84
class Item_func_centroid: public Item_geometry_func
85 86
{
public:
87
  Item_func_centroid(Item *a): Item_geometry_func(a) {}
88 89 90 91
  const char *func_name() const { return "centroid"; }
  String *val_str(String *);
};

92
class Item_func_envelope: public Item_geometry_func
93 94
{
public:
95
  Item_func_envelope(Item *a): Item_geometry_func(a) {}
96 97 98 99
  const char *func_name() const { return "envelope"; }
  String *val_str(String *);
};

100
class Item_func_point: public Item_geometry_func
101 102
{
public:
103 104
  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) {}
105 106 107 108
  const char *func_name() const { return "point"; }
  String *val_str(String *);
};

109
class Item_func_spatial_decomp: public Item_geometry_func
110 111 112 113
{
  enum Functype decomp_func;
public:
  Item_func_spatial_decomp(Item *a, Item_func::Functype ft) :
114
  	Item_geometry_func(a) { decomp_func = ft; }
115 116 117 118 119 120 121 122 123 124 125
  const char *func_name() const 
  { 
    switch (decomp_func)
    {
      case SP_STARTPOINT:
        return "startpoint";
      case SP_ENDPOINT:
        return "endpoint";
      case SP_EXTERIORRING:
        return "exteriorring";
      default:
126
	DBUG_ASSERT(0);  // Should never happened
127 128 129 130 131 132
        return "spatial_decomp_unknown"; 
    }
  }
  String *val_str(String *);
};

133
class Item_func_spatial_decomp_n: public Item_geometry_func
134 135 136 137
{
  enum Functype decomp_func_n;
public:
  Item_func_spatial_decomp_n(Item *a, Item *b, Item_func::Functype ft):
138
  	Item_geometry_func(a, b) { decomp_func_n = ft; }
139 140 141 142 143 144 145 146 147 148 149
  const char *func_name() const 
  { 
    switch (decomp_func_n)
    {
      case SP_POINTN:
        return "pointn";
      case SP_GEOMETRYN:
        return "geometryn";
      case SP_INTERIORRINGN:
        return "interiorringn";
      default:
150
	DBUG_ASSERT(0);  // Should never happened
151 152 153 154 155 156
        return "spatial_decomp_n_unknown"; 
    }
  }
  String *val_str(String *);
};

157
class Item_func_spatial_collection: public Item_geometry_func
158 159 160 161 162 163 164
{
  String tmp_value;
  enum Geometry::wkbType coll_type; 
  enum Geometry::wkbType item_type;
public:
  Item_func_spatial_collection(
     List<Item> &list, enum Geometry::wkbType ct, enum Geometry::wkbType it):
165
  Item_geometry_func(list)
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
  {
    coll_type=ct;
    item_type=it;
  }
  String *val_str(String *);
  const char *func_name() const { return "multipoint"; }
};

/*
  Spatial relations
*/

class Item_func_spatial_rel: public Item_bool_func2
{
  enum Functype spatial_rel;
public:
  Item_func_spatial_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;
    }
  }
  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:
217
      DBUG_ASSERT(0);  // Should never happened
218 219 220
      return "sp_unknown"; 
    }
    }
221
  void print(String *str) { Item_func::print(str); }
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
};

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"; }
};

class Item_func_issimple: public Item_bool_func
{
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"; }
};

class Item_func_isclosed: public Item_bool_func
{
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"; }
};

class Item_func_dimension: public Item_int_func
{
  String value;
public:
  Item_func_dimension(Item *a): Item_int_func(a) {}
  longlong val_int();
  const char *func_name() const { return "dimension"; }
  void fix_length_and_dec() { max_length=10; }
};

class Item_func_x: public Item_real_func
{
  String value;
public:
  Item_func_x(Item *a): Item_real_func(a) {}
266
  double val_real();
267 268 269 270 271 272 273 274 275
  const char *func_name() const { return "x"; }
};


class Item_func_y: public Item_real_func
{
  String value;
public:
  Item_func_y(Item *a): Item_real_func(a) {}
276
  double val_real();
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
  const char *func_name() const { return "y"; }
};


class Item_func_numgeometries: public Item_int_func
{
  String value;
public:
  Item_func_numgeometries(Item *a): Item_int_func(a) {}
  longlong val_int();
  const char *func_name() const { return "numgeometries"; }
  void fix_length_and_dec() { max_length=10; }
};


class Item_func_numinteriorring: public Item_int_func
{
  String value;
public:
  Item_func_numinteriorring(Item *a): Item_int_func(a) {}
  longlong val_int();
298
  const char *func_name() const { return "numinteriorrings"; }
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
  void fix_length_and_dec() { max_length=10; }
};


class Item_func_numpoints: public Item_int_func
{
  String value;
public:
  Item_func_numpoints(Item *a): Item_int_func(a) {}
  longlong val_int();
  const char *func_name() const { return "numpoints"; }
  void fix_length_and_dec() { max_length=10; }
};


class Item_func_area: public Item_real_func
{
  String value;
public:
  Item_func_area(Item *a): Item_real_func(a) {}
319
  double val_real();
320 321 322 323 324 325 326 327 328
  const char *func_name() const { return "area"; }
};


class Item_func_glength: public Item_real_func
{
  String value;
public:
  Item_func_glength(Item *a): Item_real_func(a) {}
329
  double val_real();
330 331 332 333 334 335 336 337 338 339 340 341 342
  const char *func_name() const { return "glength"; }
};


class Item_func_srid: public Item_int_func
{
  String value;
public:
  Item_func_srid(Item *a): Item_int_func(a) {}
  longlong val_int();
  const char *func_name() const { return "srid"; }
  void fix_length_and_dec() { max_length= 10; }
};
hf@deer.(none)'s avatar
hf@deer.(none) committed
343 344 345 346 347 348 349 350 351

#define GEOM_NEW(obj_constructor) new obj_constructor

#else /*HAVE_SPATIAL*/

#define GEOM_NEW(obj_constructor) NULL

#endif