Friday, September 26, 2014

MySQL Spatial Queries

http://howto-use-mysql-spatial-ext.blogspot.ca/

org.hibernate.dialect.MySQLDialect
MySQL5Dialect, MySQLInnoDBDialect, MySQLMyISAMDialect
 https://docs.jboss.org/hibernate/orm/3.6/javadocs/org/hibernate/dialect/MySQLDialect.html

drop table test;

create table test (
    id INT NOT NULL PRIMARY KEY,
    location LINESTRING NOT NULL,
    SPATIAL KEY sx_location (location)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

set @a = linestring(point(1,1),point(5,1));
set @b = linestring(point(1,1),point(10,1));

insert into test values(1, @a);
insert into test values(2, @b);

select * from test where MBRtouches(location, linestring(point(1,1),point(5,1)) );
select * from test where MBRtouches(location, linestring(point(2,1),point(3,1)) );
select * from test where MBRtouches(location, linestring(point(1,1),point(2,1)) );
select * from test where MBRtouches(location, linestring(point(1,1),point(7,1)) );
select * from test where MBRtouches(location, linestring(point(-1,1),point(0,1)) );
select * from test where MBRtouches(location, linestring(point(0,1),point(1,1)) );
select * from test where MBRtouches(location, linestring(point(7,1),point(12,1)) );
select * from test where MBRtouches(location, linestring(point(12,1),point(20,1)) );

select MBRcontains(@b,@a);
select MBRcontains(@a,@b);
select MBRoverlaps(@a,@b);
select MBRoverlaps(@b,@a);
select MBRtouches(@a,@b);

No comments: