File: wkb_geometry_representation.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (450 lines) | stat: -rw-r--r-- 24,148 bytes parent folder | download
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
###############################################################################
#                                                                             #
# This test is aimed at testing the modified ST_ASWKB/ST_ASBINARY             #
# functions where they have been extended to accept two parameters:           #
# a geometry and an optional argument to specify the axis ordering of         #
# the returned WKB string.                                                    #
#                                                                             #
# Creation Date: 2016-29-07                                                   #
# Author : Hans H. Melby                                                      #
#                                                                             #
###############################################################################

--echo ##########################################################
--echo # Inserting testing SRS values in spatial reference table
--echo ##########################################################

--echo # Inserting geographical srs with long-lat ordering
CREATE SPATIAL REFERENCE SYSTEM 30000000 NAME 'TEST30000000' DEFINITION 'GEOGCS["SIRGAS 1995",DATUM["Sistema de Referencia Geocentrico para America del Sur 1995",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6170"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943278,AUTHORITY["EPSG","9122"]],AXIS["LONG",EAST],AXIS["LAT",NORTH],AUTHORITY["EPSG","30000000"]]';

--echo # Inserting geographical srs with lat-long ordering
CREATE SPATIAL REFERENCE SYSTEM 30100000 NAME 'TEST30100000' DEFINITION 'GEOGCS["SIRGAS 1995",DATUM["Sistema de Referencia Geocentrico para America del Sur 1995",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6170"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943278,AUTHORITY["EPSG","9122"]],AXIS["LAT",NORTH],AXIS["LONG",EAST],AUTHORITY["EPSG","30100000"]]';

--echo # Inserting projected srs with northing-easting ordering
CREATE SPATIAL REFERENCE SYSTEM 30200000 NAME 'TEST30200000' DEFINITION 'PROJCS["NAD83(NSRS2007) / Virginia Lambert",GEOGCS["NAD83(NSRS2007)",DATUM["NAD83 (National Spatial Reference System 2007)",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6759"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943278,AUTHORITY["EPSG","9122"]],AXIS["Lat",NORTH],AXIS["Long",EAST],AUTHORITY["EPSG","4759"]],PROJECTION["Lambert Conic Conformal (2SP)",AUTHORITY["EPSG","9802"]],PARAMETER["Latitude of false origin",36,AUTHORITY["EPSG","8821"]],PARAMETER["Longitude of false origin",-79.5,AUTHORITY["EPSG","8822"]],PARAMETER["Latitude of 1st standard parallel",37,AUTHORITY["EPSG","8823"]],PARAMETER["Latitude of 2nd standard parallel",39.5,AUTHORITY["EPSG","8824"]],PARAMETER["Easting at false origin",0,AUTHORITY["EPSG","8826"]],PARAMETER["Northing at false origin",0,AUTHORITY["EPSG","8827"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",NORTH],AXIS["Y",EAST],AUTHORITY["EPSG","30200000"]]';

--echo # Inserting projected srs with easting-northing ordering
CREATE SPATIAL REFERENCE SYSTEM 30300000 NAME 'TEST30300000' DEFINITION 'PROJCS["NAD83(NSRS2007) / Virginia Lambert",GEOGCS["NAD83(NSRS2007)",DATUM["NAD83 (National Spatial Reference System 2007)",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6759"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943278,AUTHORITY["EPSG","9122"]],AXIS["Lat",NORTH],AXIS["Long",EAST],AUTHORITY["EPSG","4759"]],PROJECTION["Lambert Conic Conformal (2SP)",AUTHORITY["EPSG","9802"]],PARAMETER["Latitude of false origin",36,AUTHORITY["EPSG","8821"]],PARAMETER["Longitude of false origin",-79.5,AUTHORITY["EPSG","8822"]],PARAMETER["Latitude of 1st standard parallel",37,AUTHORITY["EPSG","8823"]],PARAMETER["Latitude of 2nd standard parallel",39.5,AUTHORITY["EPSG","8824"]],PARAMETER["Easting at false origin",0,AUTHORITY["EPSG","8826"]],PARAMETER["Northing at false origin",0,AUTHORITY["EPSG","8827"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],AUTHORITY["EPSG","30300000"]]';


####################################
# Creating the spatial objects
####################################

--echo # Creating the spatial objects

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 POINT Geometry values
######################################

--echo # Inserting POINT Geometry Values with different SRID types

INSERT INTO gis_point VALUES
    (101, ST_SRID(ST_POINTFROMTEXT('POINT(5 10)',0), 30000000)),
    (102, ST_SRID(ST_POINTFROMTEXT('POINT(5 10)',0), 30100000)),
    (103, ST_SRID(ST_POINTFROMTEXT('POINT(5 10)',0), 30200000)),
    (104, ST_SRID(ST_POINTFROMTEXT('POINT(5 10)',0), 30300000)),
    (105, ST_SRID(ST_POINTFROMTEXT('POINT(5 10)',0), 0));

###########################################
# Inserting LINESTRING Geometry values
###########################################

--echo # Inserting LINESTRING Geometry Values with different SRID types

INSERT INTO gis_linestring VALUES
    (201, ST_SRID(ST_LINEFROMTEXT('LINESTRING(0 5,5 10,10 15)',0), 30000000)),
    (202, ST_SRID(ST_LINEFROMTEXT('LINESTRING(0 5,5 10,10 15)',0), 30100000)),
    (203, ST_SRID(ST_LINEFROMTEXT('LINESTRING(0 5,5 10,10 15)',0), 30200000)),
    (204, ST_SRID(ST_LINEFROMTEXT('LINESTRING(0 5,5 10,10 15)',0), 30300000)),
    (205, ST_SRID(ST_LINEFROMTEXT('LINESTRING(0 5,5 10,10 15)',0), 0));

############################################
# Inserting POLYGON Geometry values
############################################

--echo # Inserting POLYGON Geometry Values with different SRID types

INSERT INTO gis_polygon VALUES
    (301, ST_SRID(ST_POLYFROMTEXT('POLYGON((0 0,5 0,5 5,0 5,0 0))',0), 30000000)),
    (302, ST_SRID(ST_POLYFROMTEXT('POLYGON((0 0,5 0,5 5,0 5,0 0))',0), 30100000)),
    (303, ST_SRID(ST_POLYFROMTEXT('POLYGON((0 0,5 0,5 5,0 5,0 0))',0), 30200000)),
    (304, ST_SRID(ST_POLYFROMTEXT('POLYGON((0 0,5 0,5 5,0 5,0 0))',0), 30300000)),
    (305, ST_SRID(ST_POLYFROMTEXT('POLYGON((0 0,5 0,5 5,0 5,0 0))',0), 0));

############################################
# Inserting MULTIPOINT Geometry values
############################################

--echo # Inserting MULTIPOINT Geometry Values with different SRID types

INSERT INTO gis_multi_point VALUES
    (401, ST_SRID(ST_MPOINTFROMTEXT('MULTIPOINT((0 2), (5 7), (8 2), (4 9))',0), 30000000)),
    (402, ST_SRID(ST_MPOINTFROMTEXT('MULTIPOINT((0 2), (5 7), (8 2), (4 9))',0), 30100000)),
    (403, ST_SRID(ST_MPOINTFROMTEXT('MULTIPOINT((0 2), (5 7), (8 2), (4 9))',0), 30200000)),
    (404, ST_SRID(ST_MPOINTFROMTEXT('MULTIPOINT((0 2), (5 7), (8 2), (4 9))',0), 30300000)),
    (405, ST_SRID(ST_MPOINTFROMTEXT('MULTIPOINT((0 2), (5 7), (8 2), (4 9))',0), 0));

################################################
# Inserting MULTILINESTRING Geometry values
################################################

--echo # Inserting MULTILINESTRING Geometry Values with different SRID types

INSERT INTO gis_multi_linestring VALUES
    (501, ST_SRID(ST_MLINEFROMTEXT('MULTILINESTRING((0 2,2 4,4 6),(8 11,11 14,14 17))',0), 30000000)),
    (502, ST_SRID(ST_MLINEFROMTEXT('MULTILINESTRING((0 2,2 4,4 6),(8 11,11 14,14 17))',0), 30100000)),
    (503, ST_SRID(ST_MLINEFROMTEXT('MULTILINESTRING((0 2,2 4,4 6),(8 11,11 14,14 17))',0), 30200000)),
    (504, ST_SRID(ST_MLINEFROMTEXT('MULTILINESTRING((0 2,2 4,4 6),(8 11,11 14,14 17))',0), 30300000)),
    (505, ST_SRID(ST_MLINEFROMTEXT('MULTILINESTRING((0 2,2 4,4 6),(8 11,11 14,14 17))',0), 0));

#############################################
# Inserting MULTIPOLYGON Geometry values
#############################################

--echo # Inserting MULTIPOLYGON Geometry Values with different SRID types

INSERT INTO gis_multi_polygon VALUES
    (601, ST_SRID(ST_MPOLYFROMTEXT('MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(4 4,4 6,6 6,6 4, 4 4)),((0 0,-2 -2,0 -2, 0 0)))',0), 30000000)),
    (602, ST_SRID(ST_MPOLYFROMTEXT('MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(4 4,4 6,6 6,6 4, 4 4)),((0 0,-2 -2,0 -2, 0 0)))',0), 30100000)),
    (603, ST_SRID(ST_MPOLYFROMTEXT('MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(4 4,4 6,6 6,6 4, 4 4)),((0 0,-2 -2,0 -2, 0 0)))',0), 30200000)),
    (604, ST_SRID(ST_MPOLYFROMTEXT('MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(4 4,4 6,6 6,6 4, 4 4)),((0 0,-2 -2,0 -2, 0 0)))',0), 30300000)),
    (605, ST_SRID(ST_MPOLYFROMTEXT('MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(4 4,4 6,6 6,6 4, 4 4)),((0 0,-2 -2,0 -2, 0 0)))',0), 0));

##################################################
# Inserting GEOMETRYCOLLECTION Geometry values
##################################################

--echo # Inserting GEOMETRYCOLLECTION Geometry Values with different SRID types

INSERT INTO gis_geometrycollection VALUES
    (701, ST_SRID(ST_GEOMCOLLFROMTEXT('GEOMETRYCOLLECTION(POINT(3 5), POLYGON((0 0,10 0,10 10,0 10,0 0)), MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(4 4,4 6,6 6,6 4, 4 4)),((0 0,-2 -2,0 -2, 0 0))))',0), 30000000)),
    (702, ST_SRID(ST_GEOMCOLLFROMTEXT('GEOMETRYCOLLECTION(POINT(3 5), POLYGON((0 0,10 0,10 10,0 10,0 0)), MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(4 4,4 6,6 6,6 4, 4 4)),((0 0,-2 -2,0 -2, 0 0))))',0), 30100000)),
    (703, ST_SRID(ST_GEOMCOLLFROMTEXT('GEOMETRYCOLLECTION(POINT(3 5), POLYGON((0 0,10 0,10 10,0 10,0 0)), MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(4 4,4 6,6 6,6 4, 4 4)),((0 0,-2 -2,0 -2, 0 0))))',0), 30200000)),
    (704, ST_SRID(ST_GEOMCOLLFROMTEXT('GEOMETRYCOLLECTION(POINT(3 5), POLYGON((0 0,10 0,10 10,0 10,0 0)), MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(4 4,4 6,6 6,6 4, 4 4)),((0 0,-2 -2,0 -2, 0 0))))',0), 30300000)),
    (705, ST_SRID(ST_GEOMCOLLFROMTEXT('GEOMETRYCOLLECTION(POINT(3 5), POLYGON((0 0,10 0,10 10,0 10,0 0)), MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(4 4,4 6,6 6,6 4, 4 4)),((0 0,-2 -2,0 -2, 0 0))))',0), 0));

--echo #####################################################################
--echo # Retrieving geometries with ST_ASWKB with no parameter
--echo # (Should thus be retrieved with the SRID default axis ordering)
--echo #####################################################################

--echo # Retrieve all values from gis_point
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g))) FROM gis_point
 ORDER BY fid;

--echo # Retrieve all values from gis_linestring
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g))) FROM gis_linestring
 ORDER BY fid;

--echo # Retrieve all values from gis_polygon
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g))) FROM gis_polygon
 ORDER BY fid;

--echo # Retrieve all values from gis_multi_point
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g))) FROM gis_multi_point
 ORDER BY fid;

--echo # Retrieve all values from gis_multi_linestring
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g))) FROM gis_multi_linestring
 ORDER BY fid;

--echo # Retrieve all values from gis_multi_polygon
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g))) FROM gis_multi_polygon
 ORDER BY fid;

--echo # Retrieve all values from gis_geometrycollection
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g))) FROM gis_geometrycollection
 ORDER BY fid;

--echo #####################################################################
--echo # Retrieving geometries with ST_ASWKB with lat-long axis ordering
--echo # (Default SRID coordination should thus be overridden)
--echo #####################################################################

--echo # Retrieve all values from gis_point
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=lat-long'))) FROM gis_point
 ORDER BY fid;

--echo # Retrieve all values from gis_linestring
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=lat-long'))) FROM gis_linestring ORDER BY fid;

--echo # Retrieve all values from gis_polygon
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=lat-long'))) FROM gis_polygon
 ORDER BY fid;

--echo # Retrieve all values from gis_multi_point
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=lat-long'))) FROM gis_multi_point ORDER BY fid;

--echo # Retrieve all values from gis_multi_linestring
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=lat-long'))) FROM gis_multi_linestring ORDER BY fid;

--echo # Retrieve all values from gis_multi_polygon
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=lat-long'))) FROM gis_multi_polygon ORDER BY fid;

--echo # Retrieve all values from gis_geometrycollection
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=lat-long'))) FROM gis_geometrycollection ORDER BY fid;

--echo #####################################################################
--echo # Retrieving geometries with ST_ASWKB with long-lat axis ordering
--echo # (Default SRID coordination should thus be overridden)
--echo #####################################################################

--echo # Retrieve all values from gis_point
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=long-lat'))) FROM gis_point
 ORDER BY fid;

--echo # Retrieve all values from gis_linestring
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=long-lat'))) FROM gis_linestring ORDER BY fid;

--echo # Retrieve all values from gis_polygon
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=long-lat'))) FROM gis_polygon
 ORDER BY fid;

--echo # Retrieve all values from gis_multi_point
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=long-lat'))) FROM gis_multi_point ORDER BY fid;

--echo # Retrieve all values from gis_multi_linestring
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=long-lat'))) FROM gis_multi_linestring ORDER BY fid;

--echo # Retrieve all values from gis_multi_polygon
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=long-lat'))) FROM gis_multi_polygon ORDER BY fid;

--echo # Retrieve all values from gis_geometrycollection
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=long-lat'))) FROM gis_geometrycollection ORDER BY fid;

--echo #####################################################################
--echo # Retrieving geometries with ST_ASWKB with srid-default axis ordering
--echo # (Default SRID coordination should thus be explicitly used)
--echo #####################################################################

--echo # Retrieve all values from gis_point
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=srid-defined'))) FROM gis_point
 ORDER BY fid;

--echo # Retrieve all values from gis_linestring
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=srid-defined'))) FROM gis_linestring ORDER BY fid;

--echo # Retrieve all values from gis_polygon
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=srid-defined'))) FROM gis_polygon ORDER BY fid;

--echo # Retrieve all values from gis_multi_point
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=srid-defined'))) FROM gis_multi_point ORDER BY fid;

--echo # Retrieve all values from gis_multi_linestring
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=srid-defined'))) FROM gis_multi_linestring ORDER BY fid;

--echo # Retrieve all values from gis_multi_polygon
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=srid-defined'))) FROM gis_multi_polygon ORDER BY fid;

--echo # Retrieve all values from gis_geometrycollection
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=srid-defined'))) FROM gis_geometrycollection ORDER BY fid;

--echo ##########################################################################
--echo # Retrieving geometries with ST_ASWKB with empty axis ordering parameter
--echo # (Default SRID coordination should thus be used)
--echo ##########################################################################

--echo # Retrieve all values from gis_point
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, ''))) FROM gis_point
 ORDER BY fid;

--echo # Retrieve all values from gis_linestring
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, ''))) FROM gis_linestring
 ORDER BY fid;

--echo # Retrieve all values from gis_polygon
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, ''))) FROM gis_polygon
 ORDER BY fid;

--echo # Retrieve all values from gis_multi_point
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, ''))) FROM gis_multi_point
 ORDER BY fid;

--echo # Retrieve all values from gis_multi_linestring
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, ''))) FROM gis_multi_linestring
 ORDER BY fid;

--echo # Retrieve all values from gis_multi_polygon
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, ''))) FROM gis_multi_polygon
 ORDER BY fid;

--echo # Retrieve all values from gis_geometrycollection
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, ''))) FROM gis_geometrycollection
 ORDER BY fid;


--echo ################################
--echo # Specific cases testing
--echo # ##############################

--echo # Test with combined lowercase and uppercase characters in optional parameter
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'aXIs-oRDer=sriD-dEFineD'))) FROM gis_geometrycollection ORDER BY fid;
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=LaT-LOng'))) FROM gis_geometrycollection ORDER BY fid;
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, 'axis-order=LOnG-lAT'))) FROM gis_geometrycollection ORDER BY fid;

--echo # Test with combined lowercase, uppercase and whitespaces in optional parameter
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, '   aXIs-oRDer=sriD-dEFineD    '))) FROM gis_geometrycollection ORDER BY fid;
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, ' axis-order=LaT-LOng   '))) FROM gis_geometrycollection ORDER BY fid;
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, '   axis-order=LOnG-lAT       '))) FROM gis_geometrycollection ORDER BY fid;

--echo # Test with only whitespaces in optional parameter (Should return same as empty string)
SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASWKB(g, '       '))) FROM gis_geometrycollection
 ORDER BY fid;

--echo ##########################
--echo # Error testing
--echo # ########################

--echo # Test with badly formed options string

--error ER_INVALID_OPTION_KEY_VALUE_PAIR
SELECT ST_ASWKB(g, 'axis-order srid-defined') FROM gis_geometrycollection;
--error ER_INVALID_OPTION_START_CHARACTER
SELECT ST_ASWKB(g, '=axis-order srid-defined') FROM gis_geometrycollection;
--error ER_INVALID_OPTION_END_CHARACTER
SELECT ST_ASWKB(g, 'axis-order=srid-defined=') FROM gis_geometrycollection;
--error ER_INVALID_OPTION_CHARACTERS
SELECT ST_ASWKB(g, 'axis-order== srid-defined') FROM gis_geometrycollection;
--error ER_INVALID_OPTION_KEY_VALUE_PAIR
SELECT ST_ASWKB(g, 'axis-=order srid-def=ined') FROM gis_geometrycollection;
--error ER_INVALID_OPTION_END_CHARACTER
SELECT ST_ASWKB(g, 'axis-order srid-defined,') FROM gis_geometrycollection;
--error ER_INVALID_OPTION_START_CHARACTER
SELECT ST_ASWKB(g, ',axis-order srid-defined') FROM gis_geometrycollection;
--error ER_INVALID_OPTION_CHARACTERS
SELECT ST_ASWKB(g, 'axis-order,,srid-defined') FROM gis_geometrycollection;
--error ER_DUPLICATE_OPTION_KEY
SELECT ST_ASWKB(g, 'axis-order=srid-defined, axis-order=lat-long') FROM gis_geometrycollection;



--echo # Test with too many options

--error ER_INVALID_OPTION_KEY
SELECT ST_ASWKB(g, 'axis-order=srid-defined, axis-order2=lat-long') FROM gis_geometrycollection;

--echo # Test with invalid options key

--error ER_INVALID_OPTION_KEY
SELECT ST_ASWKB(g, 'axix-order=srid-defined') FROM gis_geometrycollection;
--error ER_INVALID_OPTION_KEY
SELECT ST_ASWKB(g, 'axix-order=lat-long') FROM gis_geometrycollection;
--error ER_INVALID_OPTION_KEY
SELECT ST_ASWKB(g, 'axix-order=long-lat') FROM gis_geometrycollection;

--echo # Test with invalid options value

--error ER_INVALID_OPTION_VALUE
SELECT ST_ASWKB(g, 'axis-order=invalid-option') FROM gis_geometrycollection;

--echo # Test with too many function parameters

--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
SELECT ST_ASWKB(g, 'axis-order=long-lat', POINT(2, 4)) FROM gis_geometrycollection;

--echo # Test with too invalid start and end characters in substring

--error ER_INVALID_OPTION_START_CHARACTER
SELECT ST_ASWKB(POINT(4, 2), 'axis-order=test,=long-lathello,=test');

--error ER_INVALID_OPTION_END_CHARACTER
SELECT ST_ASWKB(POINT(4, 2), 'axis-order=long-lat=, axis-order=lat-long');

--echo # Test with both invalid option and invalid value

--error ER_INVALID_OPTION_KEY
SELECT ST_ASWKB(g, 'invalid_option=invalid-value') FROM gis_geometrycollection;

--echo # NULL value testing: Should return NULL if either or both parameters of
--echo # ST_ASWKB/ST_ABINARY is NULL

SELECT ST_AsWKB(NULL, 'axis-order=srid-defined');
SELECT ST_AsWKB(POINT(0, 0), NULL);
SELECT ST_AsWKB(NULL, NULL);

--echo # Bug#24488316 Test case

SELECT ST_AsText(ST_GeomFromWKB(ST_AsWKB(ST_GeomFromText('GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(MULTILINESTRING((1 9,18 2,0 -17,5 -3),(19 19,-4 -14),(-16 5,19 6),(-6 0,6 12,12 19,-19 -12),(5 -19,8 -19),(14 0,-16 -1,-1 -4,-1 20)),MULTILINESTRING((-14 -4,6 -4),(1 -4,-13 -1),(-17 5,-10 -8),(9 -17,-17 0,4 -19,12 2)))))),LINESTRING(-5 -12,-5 -9))', 4016))));

--echo # Testing with null character in options string

--error ER_INVALID_OPTION_KEY_VALUE_PAIR
SELECT HEX(ST_ASWKB(ST_GEOMFROMTEXT('POINT(0 0)'), x'00c0ffee'));

--echo # Test with options strings that previously gave wrong error message

--error ER_INVALID_OPTION_KEY
SELECT ST_AsWKB(POINT(1, 1), 'axis-order=lat-long,foo=bar');
--error ER_INVALID_OPTION_KEY
SELECT ST_AsWKB(POINT(1, 1), 'axis-order=lat-long , foo=bar');

--echo # Test with invalid options value and invalid SRID (should give same
--echo # error as with a valid SRID)

--error ER_INVALID_OPTION_VALUE
DO ST_AsWKB(ST_GeomFromText('POINT(1 1)', 4326), 'axis-order = foo'); 


--echo #####################################################################
--echo # ST_ASBINARY
--echo #####################################################################

# ST_ASBINARY has the exact same implementation as ST_ASWKB. We still need
# minimal testing of the interface to detect changes that affect only the one
# function name.

# These queries are a selection of those done for ST_ASWKB.

SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASBINARY(g)))
FROM gis_geometrycollection ORDER BY fid;

SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASBINARY(g, 'axis-order=srid-defined')))
FROM gis_geometrycollection ORDER BY fid;

SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASBINARY(g, '')))
FROM gis_geometrycollection ORDER BY fid;

SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASBINARY(g, 'axis-order=lat-long')))
FROM gis_geometrycollection ORDER BY fid;

SELECT ST_ASTEXT(ST_GEOMFROMWKB(ST_ASBINARY(g, 'axis-order=long-lat')))
FROM gis_geometrycollection ORDER BY fid;

--error ER_INVALID_OPTION_KEY
SELECT ST_ASBINARY(g, 'invalid_option=invalid-value')
FROM gis_geometrycollection;

--error ER_INVALID_OPTION_KEY
SELECT ST_ASBINARY(g, 'axis-order=srid-defined, axis-order2=lat-long')
FROM gis_geometrycollection;

--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
SELECT ST_ASBINARY(g, 'axis-order=long-lat', POINT(2, 4))
FROM gis_geometrycollection;

SELECT ST_ASBINARY(NULL, 'axis-order=srid-defined');
SELECT ST_ASBINARY(POINT(0, 0), NULL);
SELECT ST_ASBINARY(NULL, NULL);

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;

# Cleanup.
DROP SPATIAL REFERENCE SYSTEM 30000000;
DROP SPATIAL REFERENCE SYSTEM 30100000;
DROP SPATIAL REFERENCE SYSTEM 30200000;
DROP SPATIAL REFERENCE SYSTEM 30300000;