Commit 9d51588e authored by Alexey Botchkov's avatar Alexey Botchkov

Precision spatial function tests added.

parent e88c96d2
DROP TABLE IF EXISTS t1;
select 1, ST_Intersects(GeomFromText('POLYGON((0 0,20 0,20 20,0 20,0 0))'), GeomFromText('POLYGON((10 10,30 10,30 30,10 30,10 10))'));
1 ST_Intersects(GeomFromText('POLYGON((0 0,20 0,20 20,0 20,0 0))'), GeomFromText('POLYGON((10 10,30 10,30 30,10 30,10 10))'))
1 1
select 0, ST_Intersects(GeomFromText('POLYGON((0 0,20 10,10 30, 0 0))'), GeomFromText('POLYGON((10 40, 40 50, 20 70, 10 40))'));
0 ST_Intersects(GeomFromText('POLYGON((0 0,20 10,10 30, 0 0))'), GeomFromText('POLYGON((10 40, 40 50, 20 70, 10 40))'))
0 0
select 1, ST_Intersects(GeomFromText('POLYGON((0 0,20 10,10 30, 0 0))'), GeomFromText('POINT(10 10)'));
1 ST_Intersects(GeomFromText('POLYGON((0 0,20 10,10 30, 0 0))'), GeomFromText('POINT(10 10)'))
1 1
select 1, ST_Intersects(GeomFromText('POLYGON((0 0,20 10,10 30, 0 0))'), GeomFromText('POLYGON((10 10,30 20,20 40, 10 10))'));
1 ST_Intersects(GeomFromText('POLYGON((0 0,20 10,10 30, 0 0))'), GeomFromText('POLYGON((10 10,30 20,20 40, 10 10))'))
1 1
select 0, ST_Within(GeomFromText('POLYGON((0 0,20 10,10 30, 0 0))'), GeomFromText('POLYGON((10 10,30 20,20 40, 10 10))'));
0 ST_Within(GeomFromText('POLYGON((0 0,20 10,10 30, 0 0))'), GeomFromText('POLYGON((10 10,30 20,20 40, 10 10))'))
0 0
select 1, ST_Within(GeomFromText('POLYGON((1 1,20 10,10 30, 1 1))'), GeomFromText('POLYGON((0 0,30 5,10 40, 0 0))'));
1 ST_Within(GeomFromText('POLYGON((1 1,20 10,10 30, 1 1))'), GeomFromText('POLYGON((0 0,30 5,10 40, 0 0))'))
1 1
create table t1 (g point);
insert into t1 values
(GeomFromText('POINT(2 2)')), (GeomFromText('POINT(2 4)')), (GeomFromText('POINT(2 6)')), (GeomFromText('POINT(2 8)')),
(GeomFromText('POINT(4 2)')), (GeomFromText('POINT(4 4)')), (GeomFromText('POINT(4 6)')), (GeomFromText('POINT(4 8)')),
(GeomFromText('POINT(6 2)')), (GeomFromText('POINT(6 4)')), (GeomFromText('POINT(6 6)')), (GeomFromText('POINT(6 8)')),
(GeomFromText('POINT(8 2)')), (GeomFromText('POINT(8 4)')), (GeomFromText('POINT(8 6)')), (GeomFromText('POINT(8 8)'));
select astext(g) from t1 where ST_Within(g, GeomFromText('POLYGON((5 1, 7 1, 7 7, 5 7, 3 3, 5 3, 5 1))'));
astext(g)
POINT(4 2)
POINT(4 4)
POINT(4 6)
POINT(6 2)
POINT(6 4)
POINT(6 6)
select 'Contains';
Contains
Contains
select astext(g) from t1 where ST_Contains(GeomFromText('POLYGON((5 1, 7 1, 7 7, 5 7, 3 3, 5 3, 5 1))'), g);
astext(g)
POINT(4 4)
POINT(6 2)
POINT(6 4)
POINT(6 6)
select 'Intersects';
Intersects
Intersects
select astext(g) from t1 where ST_Intersects(GeomFromText('POLYGON((5 1, 7 1, 7 7, 5 7, 3 3, 5 3, 5 1))'), g);
astext(g)
POINT(4 4)
POINT(6 2)
POINT(6 4)
POINT(6 6)
select 'Contains';
Contains
Contains
select astext(g) from t1 where ST_Contains(GeomFromText('POLYGON((5 1, 7 1, 7 7, 5 7, 3 3, 5 3, 5 1))'), g);
astext(g)
POINT(4 4)
POINT(6 2)
POINT(6 4)
POINT(6 6)
select 'Contains2';
Contains2
Contains2
select astext(g) from t1 where ST_Contains(GeomFromText('POLYGON((5 1, 7 1, 7 7, 5 7, 3 3, 5 3, 5 1), (5.01 3.01, 6 5, 9 5, 8 3, 5.01 3.01))'), g);
astext(g)
POINT(4 4)
POINT(6 2)
POINT(6 6)
POINT(8 4)
DROP TABLE t1;
select 0, ST_Within(GeomFromText('LINESTRING(15 15, 50 50, 60 60)'), GeomFromText('POLYGON((10 10,30 20,20 40, 10 10))'));
0 ST_Within(GeomFromText('LINESTRING(15 15, 50 50, 60 60)'), GeomFromText('POLYGON((10 10,30 20,20 40, 10 10))'))
0 0
select 1, ST_Within(GeomFromText('LINESTRING(15 15, 16 16)'), GeomFromText('POLYGON((10 10,30 20,20 40, 10 10))'));
1 ST_Within(GeomFromText('LINESTRING(15 15, 16 16)'), GeomFromText('POLYGON((10 10,30 20,20 40, 10 10))'))
1 1
select 1, ST_Intersects(GeomFromText('LINESTRING(15 15, 50 50)'), GeomFromText('LINESTRING(50 15, 15 50)'));
1 ST_Intersects(GeomFromText('LINESTRING(15 15, 50 50)'), GeomFromText('LINESTRING(50 15, 15 50)'))
1 1
select 0, ST_Intersects(GeomFromText('LINESTRING(15 15, 50 50)'), GeomFromText('LINESTRING(16 16, 51 51)'));
0 ST_Intersects(GeomFromText('LINESTRING(15 15, 50 50)'), GeomFromText('LINESTRING(16 16, 51 51)'))
0 0
select 1, ST_Intersects(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('POLYGON((50 5, 55 10, 0 45, 50 5))'));
1 ST_Intersects(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('POLYGON((50 5, 55 10, 0 45, 50 5))'))
1 1
select astext(ST_Union(geometryfromtext('point(1 1)'), geometryfromtext('polygon((0 0, 2 0, 1 2, 0 0))')));
astext(ST_Union(geometryfromtext('point(1 1)'), geometryfromtext('polygon((0 0, 2 0, 1 2, 0 0))')))
POLYGON((0 0,1 2,2 0,0 0))
select astext(ST_Intersection(geometryfromtext('point(1 1)'), geometryfromtext('polygon((0 0, 2 0, 1 2, 0 0))')));
astext(ST_Intersection(geometryfromtext('point(1 1)'), geometryfromtext('polygon((0 0, 2 0, 1 2, 0 0))')))
POINT(1 1)
select ST_Intersects(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('POLYGON((50 5, 55 10, 0 45, 50 5))'));
ST_Intersects(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('POLYGON((50 5, 55 10, 0 45, 50 5))'))
1
select ST_contains(GeomFromText('MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0)), ((6 6, 6 11, 11 11, 11 6, 6 6)))'), GeomFromText('POINT(5 10)'));
ST_contains(GeomFromText('MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0)), ((6 6, 6 11, 11 11, 11 6, 6 6)))'), GeomFromText('POINT(5 10)'))
0
select ST_Disjoint(GeomFromText('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'), GeomFromText('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))'));
ST_Disjoint(GeomFromText('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'), GeomFromText('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))'))
1
select ST_Disjoint(GeomFromText('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'), GeomFromText('POLYGON((10 10, 10 4, 4 4, 4 10, 10 10))'));
ST_Disjoint(GeomFromText('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'), GeomFromText('POLYGON((10 10, 10 4, 4 4, 4 10, 10 10))'))
0
select ST_Overlaps(GeomFromText('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'), GeomFromText('POLYGON((10 10, 10 4, 4 4, 4 10, 10 10))'));
ST_Overlaps(GeomFromText('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'), GeomFromText('POLYGON((10 10, 10 4, 4 4, 4 10, 10 10))'))
1
select ST_Overlaps(GeomFromText('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'), GeomFromText('POLYGON((1 1, 1 4, 4 4, 4 1, 1 1))'));
ST_Overlaps(GeomFromText('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'), GeomFromText('POLYGON((1 1, 1 4, 4 4, 4 1, 1 1))'))
0
select ST_DISTANCE(geomfromtext('polygon((0 0, 1 2, 2 1, 0 0))'), geomfromtext('polygon((2 2, 3 4, 4 3, 2 2))'));
ST_DISTANCE(geomfromtext('polygon((0 0, 1 2, 2 1, 0 0))'), geomfromtext('polygon((2 2, 3 4, 4 3, 2 2))'))
0.707106781186547
select ST_DISTANCE(geomfromtext('polygon((0 0, 1 2, 2 1, 0 0))'), geomfromtext('linestring(0 1, 1 0)'));
ST_DISTANCE(geomfromtext('polygon((0 0, 1 2, 2 1, 0 0))'), geomfromtext('linestring(0 1, 1 0)'))
0
select ST_DISTANCE(geomfromtext('polygon((0 0, 3 6, 6 3, 0 0))'), geomfromtext('polygon((2 2, 3 4, 4 3, 2 2))'));
ST_DISTANCE(geomfromtext('polygon((0 0, 3 6, 6 3, 0 0))'), geomfromtext('polygon((2 2, 3 4, 4 3, 2 2))'))
0
select ST_DISTANCE(geomfromtext('polygon((0 0, 3 6, 6 3, 0 0),(2 2, 3 4, 4 3, 2 2))'), geomfromtext('point(3 3)'));
ST_DISTANCE(geomfromtext('polygon((0 0, 3 6, 6 3, 0 0),(2 2, 3 4, 4 3, 2 2))'), geomfromtext('point(3 3)'))
0.447213595499958
select ST_DISTANCE(geomfromtext('linestring(0 0, 3 6, 6 3, 0 0)'), geomfromtext('polygon((2 2, 3 4, 4 3, 2 2))'));
ST_DISTANCE(geomfromtext('linestring(0 0, 3 6, 6 3, 0 0)'), geomfromtext('polygon((2 2, 3 4, 4 3, 2 2))'))
0.894427190999916
select astext(ST_Intersection(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('POLYGON((50 5, 55 10, 0 45, 50 5))')));
astext(ST_Intersection(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('POLYGON((50 5, 55 10, 0 45, 50 5))')))
POLYGON((26.4705882352941 23.8235294117647,21.9512195121951 27.4390243902439,23.855421686747 29.8192771084337,29.2899408284024 26.3609467455621,26.4705882352941 23.8235294117647))
select astext(ST_Intersection(GeomFromText('LINESTRING(0 0, 50 45, 40 50, 0 0)'), GeomFromText('LINESTRING(50 5, 55 10, 0 45, 50 5)')));
astext(ST_Intersection(GeomFromText('LINESTRING(0 0, 50 45, 40 50, 0 0)'), GeomFromText('LINESTRING(50 5, 55 10, 0 45, 50 5)')))
MULTIPOINT(26.4705882352941 23.8235294117647,29.2899408284024 26.3609467455621,21.9512195121951 27.4390243902439,23.855421686747 29.8192771084337)
select astext(ST_Intersection(GeomFromText('LINESTRING(0 0, 50 45, 40 50)'), GeomFromText('LINESTRING(50 5, 55 10, 0 45)')));
astext(ST_Intersection(GeomFromText('LINESTRING(0 0, 50 45, 40 50)'), GeomFromText('LINESTRING(50 5, 55 10, 0 45)')))
POINT(29.2899408284024 26.3609467455621)
select astext(ST_Intersection(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('POINT(20 20)')));
astext(ST_Intersection(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('POINT(20 20)')))
POINT(20 20)
select astext(ST_Intersection(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('LINESTRING(-10 -10, 200 200)')));
astext(ST_Intersection(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('LINESTRING(-10 -10, 200 200)')))
LINESTRING(0 0,46.6666666666667 46.6666666666667)
select astext(ST_Intersection(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('LINESTRING(-10 -10, 200 200, 199 201, -11 -9)')));
astext(ST_Intersection(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('LINESTRING(-10 -10, 200 200, 199 201, -11 -9)')))
MULTILINESTRING((0 0,46.6666666666667 46.6666666666667),(8 10,45.3333333333333 47.3333333333333))
select astext(ST_UNION(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('LINESTRING(-10 -10, 200 200, 199 201, -11 -9)')));
astext(ST_UNION(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('LINESTRING(-10 -10, 200 200, 199 201, -11 -9)')))
GEOMETRYCOLLECTION(LINESTRING(-10 -10,0 0),LINESTRING(-11 -9,8 10),POLYGON((0 0,40 50,50 45,0 0)),LINESTRING(46.6666666666667 46.6666666666667,200 200,199 201,45.3333333333333 47.3333333333333))
select astext(ST_intersection(geomfromtext('polygon((0 0, 1 0, 0 1, 0 0))'), geomfromtext('polygon((0 0, 1 1, 0 2, 0 0))')));
astext(ST_intersection(geomfromtext('polygon((0 0, 1 0, 0 1, 0 0))'), geomfromtext('polygon((0 0, 1 1, 0 2, 0 0))')))
POLYGON((0 0,0 1,0.5 0.5,0 0))
select astext(ST_symdifference(geomfromtext('polygon((0 0, 1 0, 0 1, 0 0))'), geomfromtext('polygon((0 0, 1 1, 0 2, 0 0))')));
astext(ST_symdifference(geomfromtext('polygon((0 0, 1 0, 0 1, 0 0))'), geomfromtext('polygon((0 0, 1 1, 0 2, 0 0))')))
MULTIPOLYGON(((0 0,0 1,0 0,0.5 0.5,1 0,0 0)),((0.5 0.5,0 1,0 2,1 1,0.5 0.5)))
select astext(ST_UNION(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('LINESTRING(-10 -10, 200 200, 199 201, -11 -9)')));
astext(ST_UNION(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('LINESTRING(-10 -10, 200 200, 199 201, -11 -9)')))
GEOMETRYCOLLECTION(LINESTRING(-10 -10,0 0),LINESTRING(-11 -9,8 10),POLYGON((0 0,40 50,50 45,0 0)),LINESTRING(46.6666666666667 46.6666666666667,200 200,199 201,45.3333333333333 47.3333333333333))
select astext(ST_buffer(geometryfromtext('point(1 1)'), 1));
astext(ST_buffer(geometryfromtext('point(1 1)'), 1))
POLYGON((1 0,0.950932325672582 0.00120454379482759,0.901982859670439 0.00481527332780318,0.853269525544638 0.010823490035219,0.804909677983872 0.0192147195967696,0.757019820096736 0.029968746805456,0.709715322745538 0.0430596642677911,0.66311014660778 0.0584559348169792,0.61731656763491 0.0761204674887133,0.572444906569718 0.0960107068765567,0.528603263174002 0.118078735651645,0.485897255806778 0.142271389999728,0.444429766980398 0.168530387697455,0.404300695507567 0.196792468519355,0.365606715836355 0.226989546637263,0.328441045152982 0.259048874645041,0.292893218813453 0.292893218813453,0.259048874645041 0.328441045152982,0.226989546637263 0.365606715836355,0.196792468519355 0.404300695507567,0.168530387697455 0.444429766980398,0.142271389999728 0.485897255806778,0.118078735651645 0.528603263174002,0.0960107068765567 0.572444906569718,0.0761204674887133 0.61731656763491,0.0584559348169792 0.66311014660778,0.0430596642677911 0.709715322745538,0.029968746805456 0.757019820096736,0.0192147195967696 0.804909677983872,0.010823490035219 0.853269525544638,0.00481527332780318 0.901982859670439,0.00120454379482759 0.950932325672582,0 1,0.00481527332780318 1.09801714032956,0.010823490035219 1.14673047445536,0.0192147195967696 1.19509032201613,0.029968746805456 1.24298017990326,0.0430596642677911 1.29028467725446,0.0584559348169792 1.33688985339222,0.0761204674887133 1.38268343236509,0.0960107068765567 1.42755509343028,0.118078735651645 1.471396736826,0.142271389999728 1.51410274419322,0.168530387697455 1.5555702330196,0.196792468519355 1.59569930449243,0.226989546637263 1.63439328416365,0.259048874645041 1.67155895484702,0.292893218813453 1.70710678118655,0.328441045152982 1.74095112535496,0.365606715836355 1.77301045336274,0.404300695507567 1.80320753148064,0.444429766980398 1.83146961230255,0.485897255806778 1.85772861000027,0.528603263174002 1.88192126434835,0.572444906569718 1.90398929312344,0.61731656763491 1.92387953251129,0.66311014660778 1.94154406518302,0.709715322745538 1.95694033573221,0.757019820096736 1.97003125319454,0.804909677983872 1.98078528040323,0.853269525544638 1.98917650996478,0.901982859670439 1.9951847266722,0.950932325672582 1.99879545620517,1 2,1.04906767432742 1.99879545620517,1.09801714032956 1.9951847266722,1.14673047445536 1.98917650996478,1.19509032201613 1.98078528040323,1.24298017990326 1.97003125319454,1.29028467725446 1.95694033573221,1.33688985339222 1.94154406518302,1.38268343236509 1.92387953251129,1.42755509343028 1.90398929312344,1.471396736826 1.88192126434835,1.51410274419322 1.85772861000027,1.5555702330196 1.83146961230255,1.59569930449243 1.80320753148064,1.63439328416365 1.77301045336274,1.67155895484702 1.74095112535496,1.70710678118655 1.70710678118655,1.74095112535496 1.67155895484702,1.77301045336274 1.63439328416365,1.80320753148064 1.59569930449243,1.83146961230255 1.5555702330196,1.85772861000027 1.51410274419322,1.88192126434835 1.471396736826,1.90398929312344 1.42755509343028,1.92387953251129 1.38268343236509,1.94154406518302 1.33688985339222,1.95694033573221 1.29028467725446,1.97003125319454 1.24298017990326,1.98078528040323 1.19509032201613,1.98917650996478 1.14673047445536,1.9951847266722 1.09801714032956,1.99879545620517 1.04906767432742,2 1,1.9951847266722 0.901982859670439,1.98917650996478 0.853269525544638,1.98078528040323 0.804909677983872,1.97003125319454 0.757019820096736,1.95694033573221 0.709715322745538,1.94154406518302 0.66311014660778,1.92387953251129 0.61731656763491,1.90398929312344 0.572444906569718,1.88192126434835 0.528603263174002,1.85772861000027 0.485897255806778,1.83146961230255 0.444429766980398,1.80320753148064 0.404300695507567,1.77301045336274 0.365606715836355,1.74095112535496 0.328441045152982,1.70710678118655 0.292893218813453,1.67155895484702 0.259048874645041,1.63439328416365 0.226989546637263,1.59569930449243 0.196792468519355,1.5555702330196 0.168530387697455,1.51410274419322 0.142271389999728,1.471396736826 0.118078735651645,1.42755509343028 0.0960107068765567,1.38268343236509 0.0761204674887133,1.33688985339222 0.0584559348169792,1.29028467725446 0.0430596642677911,1.24298017990326 0.029968746805456,1.19509032201613 0.0192147195967696,1.14673047445536 0.010823490035219,1.09801714032956 0.00481527332780318,1.04906767432742 0.00120454379482759,1 0))
create table t1(geom geometrycollection);
insert into t1 values (geomfromtext('POLYGON((0 0, 10 10, 0 8, 0 0))'));
insert into t1 values (geomfromtext('POLYGON((1 1, 10 10, 0 8, 1 1))'));
select astext(geom), area(geom),area(ST_buffer(geom,2)) from t1;
astext(geom) area(geom) area(ST_buffer(geom,2))
POLYGON((0 0,10 10,0 8,0 0)) 40 101.671508403749
POLYGON((1 1,10 10,0 8,1 1)) 36 108.555395892665
select astext(ST_buffer(geom,2)) from t1;
astext(ST_buffer(geom,2))
POLYGON((1.41421356237309 -1.41421356237309,-1.41421356237309 1.41421356237309,0 2.82842712474619,0 6.00005026122218,-0.0960457772985613 6.00230752900675,-0.193952209526528 6.00942657999767,-0.29139139389354 6.02134109671101,-0.388128590869789 6.03802237603243,-0.483930752074584 6.05943023129893,-0.578567081710303 6.08551308911207,-0.671809592569691 6.11620811358278,-0.763433655277008 6.15144135770856,-0.853218539439872 6.19112794151823,-0.940947945408108 6.23517225655526,-1.02641052535855 6.2834681962069,-1.10940039245046 6.33589941132431,-1.18971761682496 6.39233959051784,-1.26716870725357 6.45265276445223,-1.34156707727553 6.51669363340867,-1.41273349470095 6.58430791732451,-1.48049651339678 6.65533272746751,-1.54469288631567 6.72959695884898,-1.6051679587723 6.80692170243074,-1.66177604102015 6.88712067613267,-1.71438075923078 6.97000067360251,-1.76285538403041 7.05536202966692,-1.80708313580201 7.14299910134239,-1.84695746601768 7.23270076324713,-1.88238231392335 7.32425091622068,-1.91327233795755 7.41742900792569,-1.93955312134675 7.5120105641778,-1.96116135138184 7.60776772972363,-1.978044971944 7.70446981716405,-1.99016330891247 7.8018838627003,-1.99748716815206 7.89977518736424,-1.99999890584435 7.99790796238047,-1.99769247099325 8.09604577729856,-1.99057342000233 8.19395220952653,-1.97865890328899 8.29139139389354,-1.96197762396757 8.38812859086979,-1.94056976870107 8.48393075207458,-1.91448691088793 8.5785670817103,-1.88379188641722 8.67180959256969,-1.84855864229144 8.76343365527701,-1.80887205848177 8.85321853943987,-1.76482774344474 8.94094794540811,-1.7165318037931 9.02641052535855,-1.66410058867569 9.10940039245046,-1.60766040948216 9.18971761682496,-1.54734723554777 9.26716870725357,-1.48330636659133 9.34156707727553,-1.41569208267549 9.41273349470094,-1.34466727253249 9.48049651339678,-1.27040304115102 9.54469288631567,-1.19307829756926 9.6051679587723,-1.11287932386733 9.66177604102015,-1.02999932639749 9.71438075923078,-0.944637970333077 9.76285538403041,-0.857000898657614 9.80708313580201,-0.767299236752872 9.84695746601768,-0.675749083779317 9.88238231392335,-0.582570992074307 9.91327233795755,-0.487989435822199 9.93955312134675,-0.392232270276368 9.96116135138184,-0.295530182835952 9.978044971944,-0.392232270276368 9.96116135138184,9.60776772972363 11.9611613513818,9.60981935596774 11.9615705608065,9.70653905108928 11.9783530199296,9.80396571934088 11.9903694533444,9.90186465134516 11.9975909124103,10 12,10.0981353486548 11.9975909124103,10.1960342806591 11.9903694533444,10.2934609489107 11.9783530199296,10.3901806440323 11.9615705608065,10.4859603598065 11.9400625063891,10.5805693545089 11.9138806714644,10.6737797067844 11.883088130366,10.7653668647302 11.8477590650226,10.8551101868606 11.8079785862469,10.942793473652 11.7638425286967,11.0282054883864 11.7154572200005,11.1111404660392 11.6629392246051,11.1913986089849 11.6064150629613,11.2687865683273 11.5460209067255,11.343117909694 11.4819022507099,11.4142135623731 11.4142135623731,11.4819022507099 11.343117909694,11.5460209067255 11.2687865683273,11.6064150629613 11.1913986089849,11.6629392246051 11.1111404660392,11.7154572200005 11.0282054883864,11.7638425286967 10.942793473652,11.8079785862469 10.8551101868606,11.8477590650226 10.7653668647302,11.883088130366 10.6737797067844,11.9138806714644 10.5805693545089,11.9400625063891 10.4859603598065,11.9615705608065 10.3901806440323,11.9783530199296 10.2934609489107,11.9903694533444 10.1960342806591,11.9975909124103 10.0981353486548,12 10,11.9975909124103 9.90186465134516,11.9903694533444 9.80396571934088,11.9783530199296 9.70653905108928,11.9615705608065 9.60981935596774,11.9400625063891 9.51403964019347,11.9138806714644 9.41943064549108,11.883088130366 9.32622029321556,11.8477590650226 9.23463313526982,11.8079785862469 9.14488981313944,11.7638425286967 9.057206526348,11.7154572200005 8.97179451161356,11.6629392246051 8.8888595339608,11.6064150629613 8.80860139101513,11.5460209067255 8.73121343167271,11.4819022507099 8.65688209030596,11.4142135623731 8.5857864376269,1.41421356237309 -1.41421356237309))
POLYGON((0.989269849411119 -0.999971215759952,0.891148838068309 -0.997035659307595,0.793290058708828 -0.989289069032301,0.69592926170357 -0.976750107148565,0.599300997740319 -0.959448981113848,0.503638052770599 -0.937427370856167,0.409170887207927 -0.910738328363497,0.316127080728489 -0.879446149876889,0.22473078401177 -0.843626220995187,0.135202178741929 -0.803364835064523,0.0477569471708416 -0.758758985290084,-0.0373942474793394 -0.709916131070988,-0.120046268522338 -0.656953939121177,-0.2 -0.6,-0.277062826370076 -0.539191520735374,-0.351049096533933 -0.474674994280042,-0.421780571086316 -0.406605846597216,-0.489086851709682 -0.335148062225815,-0.552805791678675 -0.260473789227354,-0.61278388648579 -0.182762924466179,-0.668876643647177 -0.102202680222169,-0.720948930797688 -0.0189871331799512,-0.768875301236584 0.0666832431188291,-0.812540296139623 0.154602061233829,-0.851838722709481 0.244557517031431,-0.886675907594418 0.33633289993945,-0.916967924964667 0.429707115021888,-0.942641798697117 0.524455215615996,-0.963635678181181 0.620348945248487,-0.979898987322333 0.717157287525381,-1.97989898732233 7.71715728752538,-1.99016330891247 7.8018838627003,-1.99748716815206 7.89977518736424,-1.99999890584435 7.99790796238047,-1.99769247099325 8.09604577729856,-1.99057342000233 8.19395220952653,-1.97865890328899 8.29139139389354,-1.96197762396757 8.38812859086979,-1.94056976870107 8.48393075207458,-1.91448691088793 8.5785670817103,-1.88379188641722 8.67180959256969,-1.84855864229144 8.76343365527701,-1.80887205848177 8.85321853943987,-1.76482774344474 8.94094794540811,-1.7165318037931 9.02641052535855,-1.66410058867569 9.10940039245046,-1.60766040948216 9.18971761682496,-1.54734723554777 9.26716870725357,-1.48330636659133 9.34156707727553,-1.41569208267549 9.41273349470094,-1.34466727253249 9.48049651339678,-1.27040304115102 9.54469288631567,-1.19307829756926 9.6051679587723,-1.11287932386733 9.66177604102015,-1.02999932639749 9.71438075923078,-0.944637970333077 9.76285538403041,-0.857000898657614 9.80708313580201,-0.767299236752872 9.84695746601768,-0.675749083779317 9.88238231392335,-0.582570992074307 9.91327233795755,-0.487989435822199 9.93955312134675,-0.392232270276368 9.96116135138184,9.60776772972363 11.9611613513818,9.60981935596774 11.9615705608065,9.70653905108928 11.9783530199296,9.80396571934088 11.9903694533444,9.90186465134516 11.9975909124103,10 12,10.0981353486548 11.9975909124103,10.1960342806591 11.9903694533444,10.2934609489107 11.9783530199296,10.3901806440323 11.9615705608065,10.4859603598065 11.9400625063891,10.5805693545089 11.9138806714644,10.6737797067844 11.883088130366,10.7653668647302 11.8477590650226,10.8551101868606 11.8079785862469,10.942793473652 11.7638425286967,11.0282054883864 11.7154572200005,11.1111404660392 11.6629392246051,11.1913986089849 11.6064150629613,11.2687865683273 11.5460209067255,11.343117909694 11.4819022507099,11.4142135623731 11.4142135623731,11.4819022507099 11.343117909694,11.5460209067255 11.2687865683273,11.6064150629613 11.1913986089849,11.6629392246051 11.1111404660392,11.7154572200005 11.0282054883864,11.7638425286967 10.942793473652,11.8079785862469 10.8551101868606,11.8477590650226 10.7653668647302,11.883088130366 10.6737797067844,11.9138806714644 10.5805693545089,11.9400625063891 10.4859603598065,11.9615705608065 10.3901806440323,11.9783530199296 10.2934609489107,11.9903694533444 10.1960342806591,11.9975909124103 10.0981353486548,12 10,11.9975909124103 9.90186465134516,11.9903694533444 9.80396571934088,11.9783530199296 9.70653905108928,11.9615705608065 9.60981935596774,11.9400625063891 9.51403964019347,11.9138806714644 9.41943064549108,11.883088130366 9.32622029321556,11.8477590650226 9.23463313526982,11.8079785862469 9.14488981313944,11.7638425286967 9.057206526348,11.7154572200005 8.97179451161356,11.6629392246051 8.8888595339608,11.6064150629613 8.80860139101513,11.5460209067255 8.73121343167271,11.4819022507099 8.65688209030596,11.4142135623731 8.5857864376269,2.41421356237309 -0.414213562373095,2.40660584659722 -0.421780571086316,2.33514806222581 -0.489086851709682,2.26047378922735 -0.552805791678675,2.18276292446618 -0.61278388648579,2.10220268022217 -0.668876643647177,2.01898713317995 -0.720948930797688,1.93331675688117 -0.768875301236584,1.84539793876617 -0.812540296139623,1.75544248296857 -0.851838722709481,1.66366710006055 -0.886675907594418,1.57029288497811 -0.916967924964667,1.475544784384 -0.942641798697117,1.37965105475151 -0.963635678181181,1.28284271247462 -0.979898987322333,1.18535297732928 -0.991392546384357,1.08741671062655 -0.998088666376754,0.989269849411119 -0.999971215759952))
set @geom=geomfromtext('LINESTRING(2 1, 4 2, 2 3, 2 5)');
set @buff=ST_buffer(@geom,1);
select astext(@buff);
astext(@buff)
POLYGON((2.02185940085665 0.000238945250322198,1.97277712041129 0.000370611262904941,1.92376042226731 0.00291047203014849,1.87492739194389 0.0078524088049996,1.82639567248833 0.015184516028905,1.7782821810637 0.0248891300133454,1.73070282728507 0.0369428714932084,1.68377223398316 0.0513167019494863,1.63760346106787 0.0679759935656108,1.59230773315705 0.086880612648897,1.54799417162668 0.107985016316124,1.50476953172789 0.131238362210331,1.46273794540424 0.156584630984506,1.42200067042871 0.1839627612571,1.38265584646488 0.213306796714246,1.34479825863987 0.244546045004294,1.3085191091987 0.277605248041878,1.27390579779004 0.312404763311236,1.24104171091284 0.348860755732007,1.21000602103095 0.386885399625282,1.1808734958397 0.426387090293356,1.15371431814397 0.467270664703471,1.12859391678171 0.509437630743893,1.10557280900008 0.552786404500042,1.08470645466414 0.597212554979035,1.06604512264916 0.642609055693097,1.0496337697385 0.688866542495745,1.0355119323188 0.735873577049592,1.02371363113331 0.783516915291068,1.01426728932301 0.831681780245288,1.00719566395272 0.880252138533831,1.00251579118736 0.929110979909321,1.00023894525032 0.978140599143353,1.0003706112629 1.02722287958871,1.00291047203015 1.07623957773269,1.007852408805 1.12507260805611,1.01518451602891 1.17360432751167,1.02488913001335 1.2217178189363,1.03694287149321 1.26929717271493,1.05131670194949 1.31622776601684,1.06797599356561 1.36239653893213,1.0868806126489 1.40769226684295,1.10798501631612 1.45200582837332,1.13123836221033 1.49523046827211,1.15658463098451 1.53726205459576,1.1839627612571 1.57799932957129,1.21330679671425 1.61734415353512,1.24454604500429 1.65520174136013,1.27760524804188 1.6914808908013,1.31240476331124 1.72609420220996,1.34886075573201 1.75895828908716,1.38688539962528 1.78999397896905,1.42638709029336 1.8191265041603,1.46727066470347 1.84628568185603,1.50943763074389 1.87140608321829,1.55278640450004 1.89442719099992,1.76393202250021 2,1.55278640450004 2.10557280900008,1.528603263174 2.11807873565165,1.48589725580678 2.14227138999973,1.4444297669804 2.16853038769745,1.40430069550757 2.19679246851936,1.36560671583635 2.22698954663726,1.32844104515298 2.25904887464504,1.29289321881345 2.29289321881345,1.25904887464504 2.32844104515298,1.22698954663726 2.36560671583635,1.19679246851936 2.40430069550757,1.16853038769745 2.4444297669804,1.14227138999973 2.48589725580678,1.11807873565165 2.528603263174,1.09601070687656 2.57244490656972,1.07612046748871 2.61731656763491,1.05845593481698 2.66311014660778,1.04305966426779 2.70971532274554,1.02996874680546 2.75701982009674,1.01921471959677 2.80490967798387,1.01082349003522 2.85326952554464,1.0048152733278 2.90198285967044,1.00120454379483 2.95093232567258,1 3,1 5,1.0048152733278 5.09801714032956,1.01082349003522 5.14673047445536,1.01921471959677 5.19509032201613,1.02996874680546 5.24298017990326,1.04305966426779 5.29028467725446,1.05845593481698 5.33688985339222,1.07612046748871 5.38268343236509,1.09601070687656 5.42755509343028,1.11807873565165 5.471396736826,1.14227138999973 5.51410274419322,1.16853038769745 5.5555702330196,1.19679246851936 5.59569930449243,1.22698954663726 5.63439328416365,1.25904887464504 5.67155895484702,1.29289321881345 5.70710678118655,1.32844104515298 5.74095112535496,1.36560671583635 5.77301045336274,1.40430069550757 5.80320753148064,1.4444297669804 5.83146961230254,1.48589725580678 5.85772861000027,1.528603263174 5.88192126434835,1.57244490656972 5.90398929312344,1.61731656763491 5.92387953251129,1.66311014660778 5.94154406518302,1.70971532274554 5.95694033573221,1.75701982009674 5.97003125319454,1.80490967798387 5.98078528040323,1.85326952554464 5.98917650996478,1.90198285967044 5.9951847266722,1.95093232567258 5.99879545620517,2 6,2.04906767432742 5.99879545620517,2.09801714032956 5.9951847266722,2.14673047445536 5.98917650996478,2.19509032201613 5.98078528040323,2.24298017990326 5.97003125319454,2.29028467725446 5.95694033573221,2.33688985339222 5.94154406518302,2.38268343236509 5.92387953251129,2.42755509343028 5.90398929312344,2.471396736826 5.88192126434835,2.51410274419322 5.85772861000027,2.5555702330196 5.83146961230254,2.59569930449243 5.80320753148064,2.63439328416365 5.77301045336274,2.67155895484702 5.74095112535496,2.70710678118655 5.70710678118655,2.74095112535496 5.67155895484702,2.77301045336274 5.63439328416365,2.80320753148064 5.59569930449243,2.83146961230255 5.5555702330196,2.85772861000027 5.51410274419322,2.88192126434835 5.471396736826,2.90398929312344 5.42755509343028,2.92387953251129 5.38268343236509,2.94154406518302 5.33688985339222,2.95694033573221 5.29028467725446,2.97003125319454 5.24298017990326,2.98078528040323 5.19509032201613,2.98917650996478 5.14673047445536,2.9951847266722 5.09801714032956,2.99879545620517 5.04906767432742,3 5,3 3.61803398874989,4.44721359549996 2.89442719099992,4.45200582837332 2.89201498368388,4.49523046827211 2.86876163778967,4.53726205459576 2.84341536901549,4.57799932957129 2.8160372387429,4.61734415353512 2.78669320328575,4.65520174136013 2.75545395499571,4.6914808908013 2.72239475195812,4.72609420220996 2.68759523668876,4.75895828908716 2.65113924426799,4.78999397896905 2.61311460037472,4.8191265041603 2.57361290970664,4.84628568185602 2.53272933529653,4.87140608321829 2.49056236925611,4.89442719099992 2.44721359549996,4.91529354533586 2.40278744502096,4.93395487735084 2.3573909443069,4.9503662302615 2.31113345750426,4.9644880676812 2.26412642295041,4.97628636886669 2.21648308470893,4.98573271067699 2.16831821975471,4.99280433604728 2.11974786146617,4.99748420881264 2.07088902009068,4.99976105474968 2.02185940085665,4.99962938873709 1.97277712041129,4.99708952796985 1.92376042226731,4.992147591195 1.87492739194389,4.9848154839711 1.82639567248833,4.97511086998665 1.7782821810637,4.96305712850679 1.73070282728507,4.94868329805051 1.68377223398316,4.93202400643439 1.63760346106787,4.9131193873511 1.59230773315705,4.89201498368388 1.54799417162668,4.86876163778967 1.50476953172789,4.84341536901549 1.46273794540424,4.8160372387429 1.42200067042871,4.78669320328575 1.38265584646488,4.75545395499571 1.34479825863987,4.72239475195812 1.3085191091987,4.68759523668876 1.27390579779004,4.65113924426799 1.24104171091284,4.61311460037472 1.21000602103095,4.57361290970664 1.1808734958397,4.53272933529653 1.15371431814397,4.49056236925611 1.12859391678171,4.44721359549996 1.10557280900008,2.44721359549996 0.105572809000084,2.3573909443069 0.0660451226491613,2.31113345750426 0.0496337697385035,2.26412642295041 0.0355119323187965,2.21648308470893 0.0237136311333106,2.16831821975471 0.014267289323011,2.11974786146617 0.00719566395272053,2.07088902009068 0.00251579118735756,2.02185940085665 0.000238945250322198))
DROP TABLE t1;
select st_touches(geomfromtext('point(0 0)'), geomfromtext('point(1 1)'));
st_touches(geomfromtext('point(0 0)'), geomfromtext('point(1 1)'))
0
select st_touches(geomfromtext('point(1 1)'), geomfromtext('point(1 1)'));
st_touches(geomfromtext('point(1 1)'), geomfromtext('point(1 1)'))
1
select st_touches(geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), geomfromtext('point(1 1)'));
st_touches(geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), geomfromtext('point(1 1)'))
1
select st_touches(geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), geomfromtext('point(1 0)'));
st_touches(geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), geomfromtext('point(1 0)'))
0
select st_touches(geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), geomfromtext('point(1 2)'));
st_touches(geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), geomfromtext('point(1 2)'))
0
select st_touches(geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), geomfromtext('polygon((1 1.2, 1 0, 2 0, 1 1.2))'));
st_touches(geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), geomfromtext('polygon((1 1.2, 1 0, 2 0, 1 1.2))'))
0
select st_touches(geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), geomfromtext('polygon((1 1, 1 0, 2 0, 1 1))'));
st_touches(geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), geomfromtext('polygon((1 1, 1 0, 2 0, 1 1))'))
1
SELECT ST_Equals(PolyFromText('POLYGON((67 13, 67 18, 67 18, 59 18, 59 13, 67 13) )'),PolyFromText('POLYGON((67 13, 67 18, 59 19, 59 13, 59 13, 67 13) )')) as result;
result
0
SELECT ST_Equals(PolyFromText('POLYGON((67 13, 67 18, 67 18, 59 18, 59 13, 67 13) )'),PolyFromText('POLYGON((67 13, 67 18, 59 18, 59 13, 59 13, 67 13) )')) as result;
result
1
SELECT ST_Equals(PointFromText('POINT (12 13)'),PointFromText('POINT (12 13)')) as result;
result
1
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (
fid INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
g GEOMETRY NOT NULL,
SPATIAL KEY(g)
) ENGINE=MyISAM;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`fid` int(11) NOT NULL AUTO_INCREMENT,
`g` geometry NOT NULL,
PRIMARY KEY (`fid`),
SPATIAL KEY `g` (`g`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SELECT count(*) FROM t1;
count(*)
150
EXPLAIN SELECT fid, AsText(g) FROM t1 WHERE ST_Within(g, GeomFromText('Polygon((140 140,160 140,160 160,140 140))'));
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range g g 34 NULL 8 Using where
SELECT fid, AsText(g) FROM t1 WHERE ST_Within(g, GeomFromText('Polygon((140 140,160 140,160 160,140 160,140 140))'));
fid AsText(g)
11 LINESTRING(140 140,160 160)
DROP TABLE t1;
CREATE TABLE t1 (
fid INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
g GEOMETRY NOT NULL
) ENGINE=MyISAM;
ALTER TABLE t1 ADD SPATIAL KEY(g);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`fid` int(11) NOT NULL AUTO_INCREMENT,
`g` geometry NOT NULL,
PRIMARY KEY (`fid`),
SPATIAL KEY `g` (`g`)
) ENGINE=MyISAM AUTO_INCREMENT=101 DEFAULT CHARSET=latin1
SELECT count(*) FROM t1;
count(*)
100
EXPLAIN SELECT fid, AsText(g) FROM t1 WHERE ST_Within(g,
GeomFromText('Polygon((40 40,60 40,60 60,40 40))'));
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range g g 34 NULL 1 Using where
SELECT fid, AsText(g) FROM t1 WHERE ST_Within(g,
GeomFromText('Polygon((40 40,60 40,60 60,40 40))'));
fid AsText(g)
DROP TABLE t1;
End of 5.5 tests.
-- source include/have_geometry.inc
#
# Spatial objects
#
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
select 1, ST_Intersects(GeomFromText('POLYGON((0 0,20 0,20 20,0 20,0 0))'), GeomFromText('POLYGON((10 10,30 10,30 30,10 30,10 10))'));
select 0, ST_Intersects(GeomFromText('POLYGON((0 0,20 10,10 30, 0 0))'), GeomFromText('POLYGON((10 40, 40 50, 20 70, 10 40))'));
select 1, ST_Intersects(GeomFromText('POLYGON((0 0,20 10,10 30, 0 0))'), GeomFromText('POINT(10 10)'));
select 1, ST_Intersects(GeomFromText('POLYGON((0 0,20 10,10 30, 0 0))'), GeomFromText('POLYGON((10 10,30 20,20 40, 10 10))'));
select 0, ST_Within(GeomFromText('POLYGON((0 0,20 10,10 30, 0 0))'), GeomFromText('POLYGON((10 10,30 20,20 40, 10 10))'));
select 1, ST_Within(GeomFromText('POLYGON((1 1,20 10,10 30, 1 1))'), GeomFromText('POLYGON((0 0,30 5,10 40, 0 0))'));
create table t1 (g point);
insert into t1 values
(GeomFromText('POINT(2 2)')), (GeomFromText('POINT(2 4)')), (GeomFromText('POINT(2 6)')), (GeomFromText('POINT(2 8)')),
(GeomFromText('POINT(4 2)')), (GeomFromText('POINT(4 4)')), (GeomFromText('POINT(4 6)')), (GeomFromText('POINT(4 8)')),
(GeomFromText('POINT(6 2)')), (GeomFromText('POINT(6 4)')), (GeomFromText('POINT(6 6)')), (GeomFromText('POINT(6 8)')),
(GeomFromText('POINT(8 2)')), (GeomFromText('POINT(8 4)')), (GeomFromText('POINT(8 6)')), (GeomFromText('POINT(8 8)'));
select astext(g) from t1 where ST_Within(g, GeomFromText('POLYGON((5 1, 7 1, 7 7, 5 7, 3 3, 5 3, 5 1))'));
select 'Contains';
select astext(g) from t1 where ST_Contains(GeomFromText('POLYGON((5 1, 7 1, 7 7, 5 7, 3 3, 5 3, 5 1))'), g);
select 'Intersects';
select astext(g) from t1 where ST_Intersects(GeomFromText('POLYGON((5 1, 7 1, 7 7, 5 7, 3 3, 5 3, 5 1))'), g);
select 'Contains';
select astext(g) from t1 where ST_Contains(GeomFromText('POLYGON((5 1, 7 1, 7 7, 5 7, 3 3, 5 3, 5 1))'), g);
select 'Contains2';
select astext(g) from t1 where ST_Contains(GeomFromText('POLYGON((5 1, 7 1, 7 7, 5 7, 3 3, 5 3, 5 1), (5.01 3.01, 6 5, 9 5, 8 3, 5.01 3.01))'), g);
DROP TABLE t1;
select 0, ST_Within(GeomFromText('LINESTRING(15 15, 50 50, 60 60)'), GeomFromText('POLYGON((10 10,30 20,20 40, 10 10))'));
select 1, ST_Within(GeomFromText('LINESTRING(15 15, 16 16)'), GeomFromText('POLYGON((10 10,30 20,20 40, 10 10))'));
select 1, ST_Intersects(GeomFromText('LINESTRING(15 15, 50 50)'), GeomFromText('LINESTRING(50 15, 15 50)'));
select 0, ST_Intersects(GeomFromText('LINESTRING(15 15, 50 50)'), GeomFromText('LINESTRING(16 16, 51 51)'));
select 1, ST_Intersects(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('POLYGON((50 5, 55 10, 0 45, 50 5))'));
select astext(ST_Union(geometryfromtext('point(1 1)'), geometryfromtext('polygon((0 0, 2 0, 1 2, 0 0))')));
select astext(ST_Intersection(geometryfromtext('point(1 1)'), geometryfromtext('polygon((0 0, 2 0, 1 2, 0 0))')));
select ST_Intersects(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('POLYGON((50 5, 55 10, 0 45, 50 5))'));
select ST_contains(GeomFromText('MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0)), ((6 6, 6 11, 11 11, 11 6, 6 6)))'), GeomFromText('POINT(5 10)'));
select ST_Disjoint(GeomFromText('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'), GeomFromText('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))'));
select ST_Disjoint(GeomFromText('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'), GeomFromText('POLYGON((10 10, 10 4, 4 4, 4 10, 10 10))'));
select ST_Overlaps(GeomFromText('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'), GeomFromText('POLYGON((10 10, 10 4, 4 4, 4 10, 10 10))'));
select ST_Overlaps(GeomFromText('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'), GeomFromText('POLYGON((1 1, 1 4, 4 4, 4 1, 1 1))'));
# Distance tests
select ST_DISTANCE(geomfromtext('polygon((0 0, 1 2, 2 1, 0 0))'), geomfromtext('polygon((2 2, 3 4, 4 3, 2 2))'));
select ST_DISTANCE(geomfromtext('polygon((0 0, 1 2, 2 1, 0 0))'), geomfromtext('linestring(0 1, 1 0)'));
select ST_DISTANCE(geomfromtext('polygon((0 0, 3 6, 6 3, 0 0))'), geomfromtext('polygon((2 2, 3 4, 4 3, 2 2))'));
select ST_DISTANCE(geomfromtext('polygon((0 0, 3 6, 6 3, 0 0),(2 2, 3 4, 4 3, 2 2))'), geomfromtext('point(3 3)'));
select ST_DISTANCE(geomfromtext('linestring(0 0, 3 6, 6 3, 0 0)'), geomfromtext('polygon((2 2, 3 4, 4 3, 2 2))'));
# Operations tests
select astext(ST_Intersection(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('POLYGON((50 5, 55 10, 0 45, 50 5))')));
select astext(ST_Intersection(GeomFromText('LINESTRING(0 0, 50 45, 40 50, 0 0)'), GeomFromText('LINESTRING(50 5, 55 10, 0 45, 50 5)')));
select astext(ST_Intersection(GeomFromText('LINESTRING(0 0, 50 45, 40 50)'), GeomFromText('LINESTRING(50 5, 55 10, 0 45)')));
select astext(ST_Intersection(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('POINT(20 20)')));
select astext(ST_Intersection(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('LINESTRING(-10 -10, 200 200)')));
select astext(ST_Intersection(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('LINESTRING(-10 -10, 200 200, 199 201, -11 -9)')));
select astext(ST_UNION(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('LINESTRING(-10 -10, 200 200, 199 201, -11 -9)')));
select astext(ST_intersection(geomfromtext('polygon((0 0, 1 0, 0 1, 0 0))'), geomfromtext('polygon((0 0, 1 1, 0 2, 0 0))')));
select astext(ST_symdifference(geomfromtext('polygon((0 0, 1 0, 0 1, 0 0))'), geomfromtext('polygon((0 0, 1 1, 0 2, 0 0))')));
select astext(ST_UNION(GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), GeomFromText('LINESTRING(-10 -10, 200 200, 199 201, -11 -9)')));
# Buffer() tests
select astext(ST_buffer(geometryfromtext('point(1 1)'), 1));
create table t1(geom geometrycollection);
insert into t1 values (geomfromtext('POLYGON((0 0, 10 10, 0 8, 0 0))'));
insert into t1 values (geomfromtext('POLYGON((1 1, 10 10, 0 8, 1 1))'));
select astext(geom), area(geom),area(ST_buffer(geom,2)) from t1;
select astext(ST_buffer(geom,2)) from t1;
set @geom=geomfromtext('LINESTRING(2 1, 4 2, 2 3, 2 5)');
set @buff=ST_buffer(@geom,1);
select astext(@buff);
# cleanup
DROP TABLE t1;
#Touches tests
select st_touches(geomfromtext('point(0 0)'), geomfromtext('point(1 1)'));
select st_touches(geomfromtext('point(1 1)'), geomfromtext('point(1 1)'));
select st_touches(geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), geomfromtext('point(1 1)'));
select st_touches(geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), geomfromtext('point(1 0)'));
select st_touches(geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), geomfromtext('point(1 2)'));
select st_touches(geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), geomfromtext('polygon((1 1.2, 1 0, 2 0, 1 1.2))'));
select st_touches(geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), geomfromtext('polygon((1 1, 1 0, 2 0, 1 1))'));
#Equals test
SELECT ST_Equals(PolyFromText('POLYGON((67 13, 67 18, 67 18, 59 18, 59 13, 67 13) )'),PolyFromText('POLYGON((67 13, 67 18, 59 19, 59 13, 59 13, 67 13) )')) as result;
SELECT ST_Equals(PolyFromText('POLYGON((67 13, 67 18, 67 18, 59 18, 59 13, 67 13) )'),PolyFromText('POLYGON((67 13, 67 18, 59 18, 59 13, 59 13, 67 13) )')) as result;
SELECT ST_Equals(PointFromText('POINT (12 13)'),PointFromText('POINT (12 13)')) as result;
-- source include/have_geometry.inc
#
# test of rtree (using with spatial data)
#
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (
fid INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
g GEOMETRY NOT NULL,
SPATIAL KEY(g)
) ENGINE=MyISAM;
SHOW CREATE TABLE t1;
--disable_query_log
let $1=150;
let $2=150;
while ($1)
{
eval INSERT INTO t1 (g) VALUES (GeomFromText('LineString($1 $1, $2 $2)'));
dec $1;
inc $2;
}
--enable_query_log
SELECT count(*) FROM t1;
EXPLAIN SELECT fid, AsText(g) FROM t1 WHERE ST_Within(g, GeomFromText('Polygon((140 140,160 140,160 160,140 140))'));
SELECT fid, AsText(g) FROM t1 WHERE ST_Within(g, GeomFromText('Polygon((140 140,160 140,160 160,140 160,140 140))'));
DROP TABLE t1;
CREATE TABLE t1 (
fid INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
g GEOMETRY NOT NULL
) ENGINE=MyISAM;
--disable_query_log
let $1=10;
while ($1)
{
let $2=10;
while ($2)
{
eval INSERT INTO t1 (g) VALUES (LineString(Point($1 * 10 - 9, $2 * 10 - 9), Point($1 * 10, $2 * 10)));
dec $2;
}
dec $1;
}
--enable_query_log
ALTER TABLE t1 ADD SPATIAL KEY(g);
SHOW CREATE TABLE t1;
SELECT count(*) FROM t1;
EXPLAIN SELECT fid, AsText(g) FROM t1 WHERE ST_Within(g,
GeomFromText('Polygon((40 40,60 40,60 60,40 40))'));
SELECT fid, AsText(g) FROM t1 WHERE ST_Within(g,
GeomFromText('Polygon((40 40,60 40,60 60,40 40))'));
DROP TABLE t1;
--echo End of 5.5 tests.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment