summaryrefslogtreecommitdiff
path: root/mysql-test/t/gis.test
blob: f4b6138c86feaa641a92d59d9e14a32061b4597f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#
# Spatial objects
#

--disable_warnings
DROP TABLE IF EXISTS pt, ls, p, mpt, mls, mp, gc, geo;
--enable_warnings

CREATE TABLE pt  (fid INTEGER NOT NULL PRIMARY KEY, g POINT);
CREATE TABLE ls  (fid INTEGER NOT NULL PRIMARY KEY, g LINESTRING);
CREATE TABLE p   (fid INTEGER NOT NULL PRIMARY KEY, g POLYGON);
CREATE TABLE mpt (fid INTEGER NOT NULL PRIMARY KEY, g MULTIPOINT);
CREATE TABLE mls (fid INTEGER NOT NULL PRIMARY KEY, g MULTILINESTRING);
CREATE TABLE mp  (fid INTEGER NOT NULL PRIMARY KEY, g MULTIPOLYGON);
CREATE TABLE gc  (fid INTEGER NOT NULL PRIMARY KEY, g GEOMETRYCOLLECTION);
CREATE TABLE geo (fid INTEGER NOT NULL PRIMARY KEY, g GEOMETRY);

INSERT INTO pt VALUES 
(101, PointFromText('POINT(10 10)')),
(102, PointFromText('POINT(20 10)')),
(103, PointFromText('POINT(20 20)')),
(104, PointFromText('POINT(10 20)'));

INSERT INTO ls VALUES
(105, LineFromText('LINESTRING(0 0,0 10,10 0)')),
(106, LineStringFromText('LINESTRING(10 10,20 10,20 20,10 20,10 10)')),
(107, GeometryFromWKB(LineString(Point(10, 10), Point(40, 10))));

INSERT INTO p VALUES
(108, PolygonFromText('POLYGON((10 10,20 10,20 20,10 20,10 10))')),
(109, PolyFromText('POLYGON((0 0,50 0,50 50,0 50,0 0), (10 10,20 10,20 20,10 20,10 10))')),
(110, GeometryFromWKB(Polygon(LineString(Point(0, 0), Point(30, 0), Point(30, 30), Point(0, 0)))));

INSERT INTO mpt VALUES
(111, MultiPointFromText('MULTIPOINT(0 0,10 10,10 20,20 20)')),
(112, MPointFromText('MULTIPOINT(1 1,11 11,11 21,21 21)')),
(113, GeometryFromWKB(MultiPoint(Point(3, 6), Point(4, 10))));

INSERT INTO mls VALUES
(114, MultiLineStringFromText('MULTILINESTRING((10 48,10 21,10 0),(16 0,16 23,16 48))')),
(115, MLineFromText('MULTILINESTRING((10 48,10 21,10 0))')),
(116, GeometryFromWKB(MultiLineString(LineString(Point(1, 2), Point(3, 5)), LineString(Point(2, 5), Point(5, 8), Point(21, 7)))));


INSERT INTO mp VALUES
(117, MultiPolygonFromText('MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))')),
(118, MPolyFromText('MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))')),
(119, GeometryFromWKB(MultiPolygon(Polygon(LineString(Point(0, 3), Point(3, 3), Point(3, 0), Point(0, 3))))));

INSERT INTO gc VALUES
(120, GeomCollFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))')),
(121, GeometryFromWKB(GeometryCollection(Point(44, 6), LineString(Point(3, 6), Point(7, 9)))));

INSERT into geo SELECT * FROM pt;
INSERT into geo SELECT * FROM ls;
INSERT into geo SELECT * FROM p;
INSERT into geo SELECT * FROM mpt;
INSERT into geo SELECT * FROM mls;
INSERT into geo SELECT * FROM mp;
INSERT into geo SELECT * FROM gc;

SELECT fid, AsText(g) FROM pt;
SELECT fid, AsText(g) FROM ls;
SELECT fid, AsText(g) FROM p;
SELECT fid, AsText(g) FROM mpt;
SELECT fid, AsText(g) FROM mls;
SELECT fid, AsText(g) FROM mp;
SELECT fid, AsText(g) FROM gc;
SELECT fid, AsText(g) FROM geo;

SELECT fid, Dimension(g) FROM geo;
SELECT fid, GeometryType(g) FROM geo;
SELECT fid, IsEmpty(g) FROM geo;
SELECT fid, AsText(Envelope(g)) FROM geo;

SELECT fid, X(g) FROM pt;
SELECT fid, Y(g) FROM pt;

SELECT fid, AsText(StartPoint(g)) FROM ls;
SELECT fid, AsText(EndPoint(g)) FROM ls;
SELECT fid, GLength(g) FROM ls;
SELECT fid, NumPoints(g) FROM ls;
SELECT fid, AsText(PointN(g, 2)) FROM ls;
SELECT fid, IsClosed(g) FROM ls;

SELECT fid, AsText(Centroid(g)) FROM p;
SELECT fid, Area(g) FROM p;
SELECT fid, AsText(ExteriorRing(g)) FROM p;
SELECT fid, NumInteriorRings(g) FROM p;
SELECT fid, AsText(InteriorRingN(g, 1)) FROM p;

SELECT fid, IsClosed(g) FROM mls;

SELECT fid, AsText(Centroid(g)) FROM mp;
SELECT fid, Area(g) FROM mp;

SELECT fid, NumGeometries(g) from mpt;
SELECT fid, NumGeometries(g) from mls;
SELECT fid, NumGeometries(g) from mp;
SELECT fid, NumGeometries(g) from gc;

SELECT fid, AsText(GeometryN(g, 2)) from mpt;
SELECT fid, AsText(GeometryN(g, 2)) from mls;
SELECT fid, AsText(GeometryN(g, 2)) from mp;
SELECT fid, AsText(GeometryN(g, 2)) from gc;

SELECT g1.fid as first, g2.fid as second,
Within(g1.g, g2.g) as w, Contains(g1.g, g2.g) as c, Overlaps(g1.g, g2.g) as o,
Equals(g1.g, g2.g) as e, Disjoint(g1.g, g2.g) as d, Touches(g1.g, g2.g) as t,
Intersects(g1.g, g2.g) as i, Crosses(g1.g, g2.g) as r
FROM gc g1, gc g2 ORDER BY first, second;

DROP TABLE pt, ls, p, mpt, mls, mp, gc, geo;