Mega Code Archive

 
Categories / MySQL / Geometric
 

Using the POLYGON object in the variable

mysql> mysql> CREATE TABLE cities (     ->   id int(11) ,     ->   pt point NOT NULL default '',     ->   zip int(11) default NULL,     ->   country varchar(10) default NULL,     ->   state char(2) default NULL,     ->   city varchar(100) default NULL,     ->   district varchar(100) default NULL     -> ); Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> mysql> mysql> mysql> SET @d0 = 30000; Query OK, 0 rows affected (0.00 sec) mysql> SET @str = CONCAT('MULTIPOINT(', @x0-@d0, ' ', @y0-@d0, ', ',@x0+@d0, ' ', @y0+@d0, ')'); Query OK, 0 rows affected (0.00 sec) mysql> SET @bbox = ENVELOPE(GEOMFROMTEXT(@str)); Query OK, 0 rows affected (0.00 sec) mysql> SELECT @str; +------+ | @str | +------+ | NULL | +------+ 1 row in set (0.00 sec) mysql> mysql> mysql> SELECT city, X(pt), Y(pt) FROM cities WHERE MBRCONTAINS(@bbox, pt); Empty set (0.00 sec) mysql> mysql> drop table cities; Query OK, 0 rows affected (0.00 sec) mysql>