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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
217
218
219
220
221
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
266
267
268
269
|
--source include/have_innodb.inc
--source include/have_geometry.inc
--source include/innodb_page_size.inc
############################################################################################
# Creating the spatial objects #
############################################################################################
--echo # Creating the spatial objects
USE test;
CREATE TABLE gis_point (fid INTEGER NOT NULL PRIMARY KEY, g POINT);
CREATE TABLE gis_linestring (fid INTEGER NOT NULL PRIMARY KEY, g LINESTRING);
CREATE TABLE gis_polygon (fid INTEGER NOT NULL PRIMARY KEY, g POLYGON);
CREATE TABLE gis_multi_point (fid INTEGER NOT NULL PRIMARY KEY, g MULTIPOINT);
CREATE TABLE gis_multi_linestring (fid INTEGER NOT NULL PRIMARY KEY, g MULTILINESTRING);
CREATE TABLE gis_multi_polygon (fid INTEGER NOT NULL PRIMARY KEY, g MULTIPOLYGON);
CREATE TABLE gis_geometrycollection (fid INTEGER NOT NULL PRIMARY KEY, g GEOMETRYCOLLECTION);
############################################################################################
# Inserting the values specific to the spatial objects #
############################################################################################
--echo # Inserting POINT Geometry Values
INSERT INTO gis_point VALUES
(101, ST_POINTFROMTEXT('POINT(0 0)')),
(102, ST_POINTFROMTEXT('POINT(1 0)')),
(103, ST_POINTFROMTEXT('POINT(0 1)')),
(104, ST_POINTFROMTEXT('POINT(1 1)')),
(105, ST_POINTFROMTEXT('POINT(-1 1)'));
INSERT INTO gis_point VALUES
(106, ST_POINTFROMWKB(POINT(0,0))),
(107, ST_POINTFROMWKB(POINT(10,0))),
(108, ST_POINTFROMWKB(POINT(0,10))),
(109, ST_POINTFROMWKB(POINT(-10,0))),
(110, ST_POINTFROMWKB(POINT(0,-10)));
INSERT INTO gis_point VALUES
(111, ST_POINTFROMWKB(ST_ASWKB(ST_POINTFROMTEXT('POINT(1 1)')))),
(112, ST_POINTFROMWKB(ST_ASWKB(ST_POINTFROMTEXT('POINT(1e308 1e308)')))),
(113, ST_POINTFROMWKB(ST_ASWKB(ST_POINTFROMTEXT('POINT(1e308 -1e308)')))),
(114, ST_POINTFROMWKB(ST_ASWKB(ST_POINTFROMTEXT('POINT(-1e308 1e308)')))),
(115, ST_POINTFROMWKB(ST_ASWKB(ST_POINTFROMTEXT('POINT(-1e308 -1e308)'))));
--echo # Inserting LINESTRING Geometry Values
INSERT INTO gis_linestring VALUES
(201, ST_LINEFROMTEXT('LINESTRING(0 0,5 5)')),
(202, ST_LINEFROMTEXT('LINESTRING(0 0,2 2,4 4)')),
(203, ST_LINEFROMTEXT('LINESTRING(0 0,5 5,10 10)'));
INSERT INTO gis_linestring VALUES
(204, ST_LINESTRINGFROMTEXT('LINESTRING(10 10,5 5)')),
(205, ST_LINESTRINGFROMTEXT('LINESTRING(0 0,12 12,24 24)')),
(206, ST_LINESTRINGFROMTEXT('LINESTRING(0 0,50 50,100 100)'));
INSERT INTO gis_linestring VALUES
(207, ST_LINEFROMWKB(LINESTRING(POINT(0,0), POINT(5,5)))),
(208, ST_LINEFROMWKB(LINESTRING(POINT(0,0), POINT(-5,-5), POINT(-10,10)))),
(209, ST_LINEFROMWKB(LINESTRING(POINT(0,0), POINT(2,2), POINT(4,4), POINT(6,6), POINT(8,8))));
INSERT INTO gis_linestring VALUES
(210, ST_LINESTRINGFROMWKB(LINESTRING(POINT(0,0), POINT(5,5)))),
(211, ST_LINESTRINGFROMWKB(LINESTRING(POINT(0,0), POINT(-50,-50), POINT(10,-10)))),
(212, ST_LINESTRINGFROMWKB(LINESTRING(POINT(0,0), POINT(1e308,1e308), POINT(1e308,-1e308))));
INSERT INTO gis_linestring VALUES
(213, ST_LINEFROMWKB(ST_ASWKB(ST_LINEFROMTEXT('LINESTRING(1e308 1e308,1e308 -1e308)')))),
(214, ST_LINEFROMWKB(ST_ASWKB(ST_LINEFROMTEXT('LINESTRING(1 1,2 2,3 3,4 4,5 5,6 6,7 7,8 8,9 9)')))),
(215, ST_LINESTRINGFROMWKB(ST_ASWKB(ST_LINESTRINGFROMTEXT('LINESTRING(10 10,10 -10,-10 -10,-10 10,10 10)'))));
--echo # Inserting POLYGON Geometry Values
INSERT INTO gis_polygon VALUES
(301, ST_POLYFROMTEXT('POLYGON((0 0,0 5,5 5,0 0))')),
(302, ST_POLYFROMTEXT('POLYGON((0 0,0 5,5 5,5 0,0 0))')),
(303, ST_POLYFROMTEXT('POLYGON((0 0,0 10,10 10,10 0,0 0))'));
INSERT INTO gis_polygon VALUES
(304, ST_POLYGONFROMTEXT('POLYGON((0 0,0 50,50 50,50 0,0 0))')),
(305, ST_POLYGONFROMTEXT('POLYGON((0 0,0 10,10 10,10 0,0 0,0 0,0 0),(4 4,4 6,6 6,6 4,4 4))')),
(306, ST_POLYGONFROMTEXT('POLYGON((0 0,0 10,10 10,10 0,0 0,0 0,0 0),(2 2,2 4,4 4,4 2,2 2),(6 6,6 8,8 8,8 6,6 6))'));
INSERT INTO gis_polygon VALUES
(307, ST_POLYFROMWKB(POLYGON(LINESTRING(POINT(0,0), POINT(0,5), POINT(5,5), POINT(0,0))))),
(308, ST_POLYFROMWKB(POLYGON(LINESTRING(POINT(0,0), POINT(0,15), POINT(15,15), POINT(15,0), POINT(0,0))))),
(309, ST_POLYFROMWKB(POLYGON(LINESTRING(POINT(0,0), POINT(0,10), POINT(10,10), POINT(10,0), POINT(0,0)),
LINESTRING(POINT(4,4), POINT(4,6), POINT(6,6), POINT(6,4), POINT(4,4)))));
INSERT INTO gis_polygon VALUES
(310, ST_POLYGONFROMWKB(POLYGON(LINESTRING(POINT(0,0), POINT(0,5), POINT(5,5), POINT(0,0))))),
(311, ST_POLYGONFROMWKB(POLYGON(LINESTRING(POINT(10,10), POINT(10,15), POINT(15,15), POINT(15,10), POINT(10,10))))),
(312, ST_POLYGONFROMWKB(POLYGON(LINESTRING(POINT(10,10), POINT(10,20), POINT(20,20), POINT(20,10), POINT(10,10)),
LINESTRING(POINT(14,14), POINT(14,16), POINT(16,16), POINT(16,14), POINT(14,14)))));
INSERT INTO gis_polygon VALUES
(313, ST_POLYFROMWKB(ST_ASWKB(ST_POLYFROMTEXT('POLYGON((0 0,0 10,10 10,10 0,0 0,0 0,5 5,0 0))')))),
(314, ST_POLYFROMWKB(ST_ASWKB(ST_POLYGONFROMTEXT('POLYGON((10 0,10 10,0 10,-10 10,-10 0,-10 -10,0 10,10 -10,10 0))')))),
(315, ST_POLYGONFROMWKB(ST_ASWKB(ST_POLYGONFROMTEXT('POLYGON((0 0,0 10,10 10,10 0,0 0,0 0,0 0),(2 2,2 4,4 4,4 2,2 2),(6 6,6 8,8 8,8 6,6 6))'))));
--echo # Inserting MULTIPOINT Geometry Values
INSERT INTO gis_multi_point VALUES
(401, ST_GEOMFROMTEXT('MULTIPOINT(0 0)')),
(402, ST_GEOMFROMTEXT('MULTIPOINT(0 0,2 2,4 4)')),
(403, ST_GEOMFROMTEXT('MULTIPOINT(0 0,5 5,10 10)'));
INSERT INTO gis_multi_point VALUES
(404, ST_GEOMFROMTEXT('MULTIPOINT(0 0,100 100)')),
(405, ST_GEOMFROMTEXT('MULTIPOINT(0 0,1e308 1e308)')),
(406, ST_GEOMFROMTEXT('MULTIPOINT(1e308 1e308,1e308 -1e308,-1e308 1e308,-1e308 -1e308)'));
INSERT INTO gis_multi_point VALUES
(407, ST_GEOMFROMWKB(MULTIPOINT(POINT(0,0)))),
(408, ST_GEOMFROMWKB(MULTIPOINT(POINT(0,0), POINT(10,10)))),
(409, ST_GEOMFROMWKB(MULTIPOINT(POINT(0,0), POINT(2,2), POINT(4,4), POINT(6,6))));
INSERT INTO gis_multi_point VALUES
(410, ST_GEOMFROMWKB(MULTIPOINT(POINT(0,0)))),
(411, ST_GEOMFROMWKB(MULTIPOINT(POINT(0,0), POINT(1e308,1e308)))),
(412, ST_GEOMFROMWKB(MULTIPOINT(POINT(1e308,1e308), POINT(-1e308,1e308), POINT(1e308,-1e308), POINT(-1e308,-1e308))));
INSERT INTO gis_multi_point VALUES
(413, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTIPOINT(0 0)')))),
(414, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTIPOINT(0 0,1e308 1e308,-1e308 -1e308)')))),
(415, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTIPOINT(1e308 1e308,1e308 -1e308,-1e308 1e308,-1e308 -1e308,1e308 1e308)'))));
--echo # Inserting MULTILINESTRING Geometry Values
INSERT INTO gis_multi_linestring VALUES
(501, ST_GEOMFROMTEXT('MULTILINESTRING((0 0,2 2))')),
(502, ST_GEOMFROMTEXT('MULTILINESTRING((0 0,2 2,4 4))')),
(503, ST_GEOMFROMTEXT('MULTILINESTRING((0 0,2 2,4 4),(6 6,8 8,10 10))'));
INSERT INTO gis_multi_linestring VALUES
(504, ST_GEOMFROMTEXT('MULTILINESTRING((0 0,100 100,-100 -100))')),
(505, ST_GEOMFROMTEXT('MULTILINESTRING((1e308 1e308,-1e308 -1e308))')),
(506, ST_GEOMFROMTEXT('MULTILINESTRING((1e308 1e308,-1e308 -1e308),(1e308 -1e308,-1e308 1e308))'));
INSERT INTO gis_multi_linestring VALUES
(507, ST_GEOMFROMWKB(MULTILINESTRING(LINESTRING(POINT(0,0), POINT(2,2))))),
(508, ST_GEOMFROMWKB(MULTILINESTRING(LINESTRING(POINT(0,0), POINT(12,12), POINT(24,24))))),
(509, ST_GEOMFROMWKB(MULTILINESTRING(LINESTRING(POINT(0,0), POINT(2,2), POINT(4,4)),
LINESTRING(POINT(6,6), POINT(8,8), POINT(10,10)))));
INSERT INTO gis_multi_linestring VALUES
(510, ST_GEOMFROMWKB(MULTILINESTRING(LINESTRING(POINT(0,0), POINT(2,2), POINT(4,4))))),
(511, ST_GEOMFROMWKB(MULTILINESTRING(LINESTRING(POINT(0,0), POINT(1,1), POINT(2,2))))),
(512, ST_GEOMFROMWKB(MULTILINESTRING(LINESTRING(POINT(0,0), POINT(12,12), POINT(24,24)),
LINESTRING(POINT(36,36), POINT(48,48), POINT(50,50)))));
INSERT INTO gis_multi_linestring VALUES
(513, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTILINESTRING((0 0,10 10),(0 10,10 0))')))),
(514, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTILINESTRING((0 0,10 10,-10 10,0 0),(0 0,-10 -10,10 -10,0 0))')))),
(515, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTILINESTRING((0 0,0 100),(0 0,100 0),(0 0,0 -100),(0 0,-100 0))'))));
--echo # Inserting MULTIPOLGYON Geometry Values
INSERT INTO gis_multi_polygon VALUES
(601, ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,0 5,5 5,0 0)))')),
(602, ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,0 5,5 5,0 0)),((5 5,5 10,10 10,5 5)))')),
(603, ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0,0 0,0 0),(4 4,4 6,6 6,6 4,4 4)))'));
INSERT INTO gis_multi_polygon VALUES
(604, ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,0 5,5 5,0 0)))')),
(605, ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0,0 0,0 0),(4 4,4 6,6 6,6 4,4 4)),((0 0,0 -2,-2 -2,0 0)))')),
(606, ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,5 5,-5 5,0 0)),((0 0,-5 -5,5 -5,0 0)))'));
INSERT INTO gis_multi_polygon VALUES
(607, ST_GEOMFROMWKB(MULTIPOLYGON(POLYGON(LINESTRING(POINT(0,0), POINT(5,0), POINT(5,5), POINT(0,5), POINT(0,0)))))),
(608, ST_GEOMFROMWKB(MULTIPOLYGON(POLYGON(LINESTRING(POINT(0,0), POINT(10,0), POINT(10,10), POINT(0,10), POINT(0,0)),
LINESTRING(POINT(4,4), POINT(4,6), POINT(6,6), POINT(6,4), POINT(4,4)))))),
(609, ST_GEOMFROMWKB(MULTIPOLYGON(POLYGON(LINESTRING(POINT(0,0), POINT(5,0), POINT(5,5), POINT(0,5), POINT(0,0))),
POLYGON(LINESTRING(POINT(0,0), POINT(-5,0), POINT(-5,-5), POINT(0,-5), POINT(0,0))))));
INSERT INTO gis_multi_polygon VALUES
(610, ST_GEOMFROMWKB(MULTIPOLYGON(POLYGON(LINESTRING(POINT(0,0), POINT(-5,0), POINT(-5,-5), POINT(0,-5), POINT(0,0)))))),
(611, ST_GEOMFROMWKB(MULTIPOLYGON(POLYGON(LINESTRING(POINT(10,10), POINT(20,10), POINT(20,20), POINT(10,20), POINT(10,10)),
LINESTRING(POINT(14,14), POINT(14,16), POINT(16,16), POINT(16,14), POINT(14,14)))))),
(612, ST_GEOMFROMWKB(MULTIPOLYGON(POLYGON(LINESTRING(POINT(0,0), POINT(0,10), POINT(10,10), POINT(10,0), POINT(0,0)),
LINESTRING(POINT(4,4), POINT(4,6), POINT(6,6), POINT(6,4), POINT(4,4))),
POLYGON(LINESTRING(POINT(0,0), POINT(-5,0), POINT(-5,-5), POINT(0,-5), POINT(0,0))))));
INSERT INTO gis_multi_polygon VALUES
(613, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,5 5,5 -5,0 0)),((0 0,-5 5,-5 -5,0 0)))')))),
(614, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,10 10,-10 10,0 0)),((0 0,-10 -10,10 -10,0 0)))')))),
(615, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,5 5,10 0,5 -5,0 0)))'))));
--echo # Inserting GEOMETRYCOLLECTION Geometry Values
INSERT INTO gis_geometrycollection VALUES
(701, ST_GEOMCOLLFROMTEXT('GEOMETRYCOLLECTION(POINT(0 0))')),
(702, ST_GEOMCOLLFROMTEXT('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))')),
(703, ST_GEOMCOLLFROMTEXT('GEOMETRYCOLLECTION(POINT(5 5), POLYGON((0 0,0 10,10 10,10 0,0 0)))'));
INSERT INTO gis_geometrycollection VALUES
(704, ST_GEOMETRYCOLLECTIONFROMTEXT('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))')),
(705, ST_GEOMETRYCOLLECTIONFROMTEXT('GEOMETRYCOLLECTION(POINT(0 0),'
'LINESTRING(0 0,10 10),'
'POLYGON((0 0,0 10,10 10,10 0,0 0,0 0, 0 0)))')),
(706, ST_GEOMETRYCOLLECTIONFROMTEXT('GEOMETRYCOLLECTION(MULTIPOINT(0 0,5 5,10 10),'
'MULTILINESTRING((0 0,10 10),(0 10,10 0)),'
'MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),'
'((0 0,-10 0,-10 -10,0 -10,0 0))))'));
INSERT INTO gis_geometrycollection VALUES
(707, ST_GEOMCOLLFROMWKB(GEOMETRYCOLLECTION(POINT(0,0)))),
(708, ST_GEOMCOLLFROMWKB(GEOMETRYCOLLECTION(POINT(0,0),
LINESTRING(POINT(0,0), POINT(2,2), POINT(4,4), POINT(6,6), POINT(8,8)),
POLYGON(LINESTRING(POINT(0,0), POINT(0,10), POINT(10,10), POINT(10,0), POINT(0,0)),
LINESTRING(POINT(4,4), POINT(4,6), POINT(6,6), POINT(6,4), POINT(4,4)))))),
(709, ST_GEOMCOLLFROMWKB(GEOMETRYCOLLECTION(MULTIPOINT(POINT(0,0), POINT(5,5), POINT(10,10)),
MULTILINESTRING(LINESTRING(POINT(0,0), POINT(2,2), POINT(4,4), POINT(6,6), POINT(8,8)),
LINESTRING(POINT(10,10), POINT(5,5), POINT(0,10))),
MULTIPOLYGON(POLYGON(LINESTRING(POINT(0,0), POINT(0,10), POINT(10,10), POINT(10,0), POINT(0,0)),
LINESTRING(POINT(4,4), POINT(4,6), POINT(6,6), POINT(6,4), POINT(4,4))),
POLYGON(LINESTRING(POINT(0,0), POINT(-10,0), POINT(-10,-10), POINT(0,0)))))));
INSERT INTO gis_geometrycollection VALUES
(710, ST_GEOMETRYCOLLECTIONFROMWKB(GEOMETRYCOLLECTION(POINT(0,0),
LINESTRING(POINT(0,0), POINT(100,100))))),
(711, ST_GEOMETRYCOLLECTIONFROMWKB(GEOMETRYCOLLECTION(POINT(10,10),
LINESTRING(POINT(10,10), POINT(12,12), POINT(14,14), POINT(16,16), POINT(18,18)),
POLYGON(LINESTRING(POINT(0,0), POINT(0,10), POINT(10,10), POINT(10,0), POINT(0,0)),
LINESTRING(POINT(4,4), POINT(4,6), POINT(6,6), POINT(6,4), POINT(4,4)))))),
(712, ST_GEOMETRYCOLLECTIONFROMWKB(GEOMETRYCOLLECTION(MULTIPOINT(POINT(10,10), POINT(15,15), POINT(20,20)),
MULTILINESTRING(LINESTRING(POINT(0,0), POINT(2,2), POINT(4,4), POINT(6,6), POINT(8,8)),
LINESTRING(POINT(10,10), POINT(5,5), POINT(0,10))),
MULTIPOLYGON(POLYGON(LINESTRING(POINT(0,0), POINT(0,10), POINT(10,10), POINT(10,0), POINT(0,0)),
LINESTRING(POINT(4,4), POINT(4,6), POINT(6,6), POINT(6,4), POINT(4,4))),
POLYGON(LINESTRING(POINT(0,0), POINT(-10,0), POINT(-10,-10), POINT(0,0)))))));
INSERT INTO gis_geometrycollection VALUES
(713, ST_GEOMCOLLFROMWKB(ST_ASWKB(ST_GEOMCOLLFROMTEXT('GEOMETRYCOLLECTION('
'POINT(0 0),'
'LINESTRING(0 0,10 10),'
'POLYGON((0 0,0 10,10 10,10 0,0 0)),'
'MULTIPOINT(0 0,2 2,4 4,6 6,8 8,10 10),'
'MULTILINESTRING((0 0,10 10),(0 10,10 0)),'
'MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5))))'))));
############################################################################################
# Checking spatial index with geometry data #
############################################################################################
--echo # Creating a table with spatial index column
CREATE TABLE geom_index (fid INTEGER NOT NULL PRIMARY KEY, g GEOMETRY NOT NULL, SPATIAL INDEX(g));
--echo # Inserting geometry values
INSERT INTO geom_index SELECT * FROM gis_point;
INSERT INTO geom_index SELECT * FROM gis_linestring;
INSERT INTO geom_index SELECT * FROM gis_polygon;
INSERT INTO geom_index SELECT * FROM gis_multi_point;
INSERT INTO geom_index SELECT * FROM gis_multi_linestring;
INSERT INTO geom_index SELECT * FROM gis_multi_polygon;
INSERT INTO geom_index SELECT * FROM gis_geometrycollection;
check table geom_index;
--echo # Final cleanup
DROP TABLE gis_point;
DROP TABLE gis_linestring;
DROP TABLE gis_polygon;
DROP TABLE gis_multi_point;
DROP TABLE gis_multi_linestring;
DROP TABLE gis_multi_polygon;
DROP TABLE gis_geometrycollection;
DROP TABLE geom_index;
|