-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathgeospatial
6351 lines (5936 loc) · 505 KB
/
geospatial
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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
statement ok
CREATE TABLE geo_table(
id int primary key,
geog geography(geometry, 4326),
geom geometry(point),
orphan geography,
FAMILY f (orphan)
)
statement ok
INSERT INTO geo_table VALUES
(1, 'POINT(1.0 1.0)', 'POINT(2.0 2.0)', 'POINT(3.0 3.0)'),
(2, 'LINESTRING(1.0 1.0, 2.0 2.0)', 'POINT(1.0 1.0)', 'POINT(3.0 3.0)')
statement error SRID 4004 does not match column SRID 4326
INSERT INTO geo_table (id, geog) VALUES
(3, 'SRID=4004;POINT(1.0 2.0)')
statement error type LineString does not match column type Point
INSERT INTO geo_table (id, geom) VALUES
(3, 'SRID=4004;LINESTRING(0.0 0.0, 1.0 2.0)')
statement error projection for SRID 404 does not exist
SELECT 'SRID=404;POINT(1.0 2.0)'::geometry
statement error projection for SRID 404 does not exist
SELECT 'SRID=404;POINT(1.0 2.0)'::geography
statement error pq: object type PointZ does not match column type Point
INSERT INTO geo_table (id, geom) VALUES
(3, 'POINT Z(1 2 3)')
statement error pq: object type PointZ does not match column dimensionality Geometry
INSERT INTO geo_table (id, geog) VALUES
(3, 'POINT Z(1 2 3)')
statement ok
CREATE INDEX geo_table_geom_idx ON geo_table USING GIST(geom)
statement ok
CREATE INDEX geo_table_geog_idx ON geo_table USING GIST(geog)
statement ok
CREATE TABLE geom_table_negative_values(
a geometry(geometry, -1)
)
statement ok
CREATE TABLE geom_table_public_schema (
geom public.geometry,
geog public.geography
)
statement ok
INSERT INTO geom_table_public_schema VALUES ('POINT(1 0)', 'POINT(3 2)')
query TT
SELECT ST_AsText(geom), ST_AsText(geog) FROM geom_table_public_schema
----
POINT (1 0) POINT (3 2)
statement error type .*geometry.* already exists
CREATE TYPE geometry AS enum('no')
statement error type .*geography.* already exists
CREATE TYPE geography AS enum('no')
statement error type .*geometry.* already exists
CREATE TABLE geometry (a geometry)
statement error type .*geography.* already exists
CREATE TABLE geography (a geography)
query T
SELECT create_statement FROM [SHOW CREATE TABLE geom_table_negative_values]
----
CREATE TABLE public.geom_table_negative_values (
a GEOMETRY(GEOMETRY) NULL,
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT geom_table_negative_values_pkey PRIMARY KEY (rowid ASC)
)
statement ok
CREATE TABLE geog_table_negative_values(
a geography(geometry, -1)
)
query T
SELECT create_statement FROM [SHOW CREATE TABLE geog_table_negative_values]
----
CREATE TABLE public.geog_table_negative_values (
a GEOGRAPHY(GEOMETRY) NULL,
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT geog_table_negative_values_pkey PRIMARY KEY (rowid ASC)
)
statement error SRID 3857 cannot be used for geography as it is not in a lon/lat coordinate system
SELECT 'SRID=3857;POINT(1.0 2.0)'::geography
query ITTT rowsort
SELECT * FROM geo_table
----
1 0101000020E6100000000000000000F03F000000000000F03F 010100000000000000000000400000000000000040 0101000020E610000000000000000008400000000000000840
2 0102000020E610000002000000000000000000F03F000000000000F03F00000000000000400000000000000040 0101000000000000000000F03F000000000000F03F 0101000020E610000000000000000008400000000000000840
query T rowsort
SELECT orphan FROM geo_table
----
0101000020E610000000000000000008400000000000000840
0101000020E610000000000000000008400000000000000840
query TTBTTTB rowsort
SHOW COLUMNS FROM geo_table
----
id INT8 false NULL · {geo_table_geog_idx,geo_table_geom_idx,geo_table_pkey} false
geog GEOGRAPHY(GEOMETRY,4326) true NULL · {geo_table_geog_idx,geo_table_pkey} false
geom GEOMETRY(POINT) true NULL · {geo_table_geom_idx,geo_table_pkey} false
orphan GEOGRAPHY true NULL · {geo_table_pkey} false
statement error column bad_pk is of type geography and thus is not indexable
CREATE TABLE bad_geog_table(bad_pk geography primary key)
statement error column bad_pk is of type geometry and thus is not indexable
CREATE TABLE bad_geom_table(bad_pk geometry primary key)
statement error column geog is of type geography and thus is not indexable
CREATE INDEX geog_idx ON geo_table(geog)
statement error column geom is of type geometry and thus is not indexable
CREATE INDEX geom_idx ON geo_table(geom)
statement ok
CREATE INVERTED INDEX geog_idx ON geo_table(geog)
statement ok
CREATE INVERTED INDEX geom_idx ON geo_table(geom)
statement ok
INSERT INTO geo_table VALUES
(3, 'POINT(-1.25 3.375)', 'POINT(2.220 -2.445)', 'POINT(3.0 -3.710)')
query ITTT rowsort
SELECT * FROM geo_table
----
1 0101000020E6100000000000000000F03F000000000000F03F 010100000000000000000000400000000000000040 0101000020E610000000000000000008400000000000000840
2 0102000020E610000002000000000000000000F03F000000000000F03F00000000000000400000000000000040 0101000000000000000000F03F000000000000F03F 0101000020E610000000000000000008400000000000000840
3 0101000020E6100000000000000000F4BF0000000000000B40 0101000000C3F5285C8FC201408FC2F5285C8F03C0 0101000020E61000000000000000000840AE47E17A14AE0DC0
statement ok
CREATE TABLE geo_array_table(id int, geog geography array, geom geometry array)
statement ok
INSERT INTO geo_array_table VALUES (
1,
array['POINT(1.0 1.0)'::geography, 'LINESTRING(2.0 2.0, 3.0 3.0)'::geography],
array['POINT(1.0 1.0)'::geometry, 'LINESTRING(2.0 2.0, 3.0 3.0)'::geometry]
)
query ITT
SELECT * FROM geo_array_table
----
1 {0101000020E6100000000000000000F03F000000000000F03F:0102000020E6100000020000000000000000000040000000000000004000000000000008400000000000000840} {0101000000000000000000F03F000000000000F03F:0102000000020000000000000000000040000000000000004000000000000008400000000000000840}
query TT
SELECT NULL::geometry, NULL::geography
----
NULL NULL
query T nosort
SELECT ST_AsText(p) FROM (VALUES
(ST_Point(1, 2)),
(ST_Point(3, 4))
) tbl(p)
----
POINT (1 2)
POINT (3 4)
query T nosort
SELECT ST_AsText(p) FROM (VALUES
('POINT(200 200)'::geography),
('POLYGON((200 200, 200 200, 200 200, 200 200))'::geography),
('GEOMETRYCOLLECTION(POINT (200 200), POLYGON((200 200, 200 200, 200 200, 200 200, 200 200)))'::geography),
('MULTIPOLYGON(((200 200,200 200, 200 200, 200 200)),((200 200,200 200,200 200,200 200)))'::geography)
) tbl(p)
----
POINT (-160 -20)
POLYGON ((-160 -20, -160 -20, -160 -20, -160 -20))
GEOMETRYCOLLECTION (POINT (-160 -20), POLYGON ((-160 -20, -160 -20, -160 -20, -160 -20, -160 -20)))
MULTIPOLYGON (((-160 -20, -160 -20, -160 -20, -160 -20)), ((-160 -20, -160 -20, -160 -20, -160 -20)))
query T nosort
SELECT ST_AsText(p) FROM (VALUES
('POINT(200 200)'::geometry),
('POLYGON((200 200, 200 200, 200 200, 200 200))'::geometry),
('GEOMETRYCOLLECTION(POINT (200 200), POLYGON((200 200, 200 200, 200 200, 200 200, 200 200)))'::geometry),
('MULTIPOLYGON(((200 200,200 200, 200 200, 200 200)),((200 200,200 200,200 200,200 200)))'::geometry)
) tbl(p)
----
POINT (200 200)
POLYGON ((200 200, 200 200, 200 200, 200 200))
GEOMETRYCOLLECTION (POINT (200 200), POLYGON ((200 200, 200 200, 200 200, 200 200, 200 200)))
MULTIPOLYGON (((200 200, 200 200, 200 200, 200 200)), ((200 200, 200 200, 200 200, 200 200)))
query T
SELECT ST_AsText(ST_Project('POINT(0 0)'::geography, 100000, radians(45.0)))
----
POINT (0.635231029125537 0.639472334729198)
statement error arguments must be POINT geometries
SELECT ST_Azimuth('POLYGON((0 0, 0 0, 0 0, 0 0))'::geometry, 'POLYGON((0 0, 0 0, 0 0, 0 0))'::geometry)
query RR
SELECT
degrees(ST_Azimuth(ST_Point(25, 45), ST_Point(75, 100))) AS degA_B,
degrees(ST_Azimuth(ST_Point(75, 100), ST_Point(25, 45))) AS degB_A
----
42.27368900609371 222.27368900609372
query R
SELECT ST_Azimuth(ST_Point(0, 0), ST_Point(0, 0))
----
NULL
query RRRRRRR
SELECT
degrees(ST_Angle('POINT (0 0)', 'POINT (0 1)', 'POINT (0 0)', 'POINT (1 0)')),
degrees(ST_Angle('POINT (0 0)', 'POINT (0 1)', 'POINT (0 0)')),
degrees(ST_Angle('POINT (0 0)', 'POINT (0 1)', 'POINT (1 1)')),
degrees(ST_Angle('POINT (0 0)', 'POINT (0 0)', 'POINT (0 0)', 'POINT (0 0)')),
degrees(ST_Angle('LINESTRING (0 0, 0 1)', 'LINESTRING (0 0, 1 0)')),
degrees(ST_Angle('LINESTRING (0 0, 0 1)', 'LINESTRING (0 0, 0 1)')),
degrees(ST_Angle('LINESTRING (0 0, 0 0)', 'LINESTRING (0 0, 0 0)'))
----
90 0 270 NULL 90 0 NULL
subtest json_test
# All values here should be true.
query BB nosort
SELECT
to_json(g::geometry) = st_asgeojson(g::geometry)::jsonb,
to_json(g::geography) = st_asgeojson(g::geography)::jsonb
FROM ( VALUES
('POINT (30 10)'),
('LINESTRING (30 10, 10 30, 40 40)'),
('POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))'),
('MULTIPOINT (10 40, 40 30, 20 20, 30 10)'),
('MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))'),
('MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))'),
('GEOMETRYCOLLECTION (POINT (40 10), LINESTRING (10 10, 20 20, 10 40), POLYGON ((40 40, 20 45, 45 30, 40 40)))')
) tbl(g)
----
true true
true true
true true
true true
true true
true true
true true
# Regression test for #124175. Allow full precision for encoding JSON instead of the old default limit of 9.
query FFT nosort
SELECT
st_x(g), st_y(g), to_json(g)
FROM ( VALUES
('SRID=4326;POINT (-123.45 12.3456)'::GEOMETRY),
('SRID=4326;POINT (-123.45678901234 12.3456789012)'::GEOMETRY),
('SRID=4326;POINT (-123.4567890123456789 12.34567890123456789)'::GEOMETRY)
) tbl(g)
----
-123.45 12.3456 {"coordinates": [-123.45, 12.3456], "type": "Point"}
-123.45678901234 12.3456789012 {"coordinates": [-123.45678901234, 12.3456789012], "type": "Point"}
-123.45678901234568 12.345678901234567 {"coordinates": [-123.45678901234568, 12.345678901234567], "type": "Point"}
# st_asgeojson uses a default of 9 decimal digit precision.
query TTTT nosort
SELECT
st_asgeojson(tbl.*)::JSONB->'geometry'->'coordinates',
st_asgeojson(g)::JSONB->'coordinates',
st_asgeojson(tbl.*, 'g')::JSONB->'geometry'->'coordinates',
st_asgeojson(tbl.*, 'g', 4)::JSONB->'geometry'->'coordinates'
FROM ( VALUES
('SRID=4326;POINT (-123.45 12.3456)'::GEOMETRY),
('SRID=4326;POINT (-123.45678901234 12.3456789012)'::GEOMETRY),
('SRID=4326;POINT (-123.4567890123456789 12.34567890123456789)'::GEOMETRY)
) tbl(g)
----
[-123.45, 12.3456] [-123.45, 12.3456] [-123.45, 12.3456] [-123.45, 12.3456]
[-123.456789012, 12.345678901] [-123.456789012, 12.345678901] [-123.456789012, 12.345678901] [-123.4568, 12.3457]
[-123.456789012, 12.345678901] [-123.456789012, 12.345678901] [-123.456789012, 12.345678901] [-123.4568, 12.3457]
subtest cast_test
query T nosort
SELECT ST_AsEWKT(geom) FROM (VALUES
('SRID=4326;POINT(1.0 2.0)'::geometry::geometry(point, 4326)),
('SRID=4326;POINT(1.0 2.0)'::geometry::geometry(geometry, 4326)),
('SRID=4326;POINT(1.0 2.0)'::geography::geometry)
) t(geom)
----
SRID=4326;POINT (1 2)
SRID=4326;POINT (1 2)
SRID=4326;POINT (1 2)
query T nosort
SELECT ST_AsEWKT(geog) FROM (VALUES
('POINT(1.0 2.0)'::geography::geography(point, 4326)),
('POINT(1.0 2.0)'::geometry::geography(point, 4326)),
('SRID=4004;POINT(1.0 2.0)'::geometry::geography(point, 4004)),
('SRID=4004;POINT(1.0 2.0)'::geometry::geography),
('SRID=4004;POINT(1.0 2.0)'::geography::geography(point, 4004)),
('SRID=4004;POINT(1.0 2.0)'::geography::geography(geometry, 4004)),
('POINT(1.0 2.0)'::geometry::geography),
('POINT(1.0 2.0)'::geometry::geography(geometry, 4326))
) t(geog)
----
SRID=4326;POINT (1 2)
SRID=4326;POINT (1 2)
SRID=4004;POINT (1 2)
SRID=4004;POINT (1 2)
SRID=4004;POINT (1 2)
SRID=4004;POINT (1 2)
SRID=4326;POINT (1 2)
SRID=4326;POINT (1 2)
statement error SRID 4004 does not match column SRID 4326
SELECT 'SRID=4004;POINT(2.0 3.0)'::geometry::geography(point, 4326)
statement error SRID 4326 does not match column SRID 4004
SELECT 'SRID=4326;POINT(2.0 3.0)'::geometry::geography(point, 4004)
statement error SRID 4326 does not match column SRID 4004
SELECT 'SRID=4326;POINT(2.0 3.0)'::geography::geography(point, 4004)
statement error SRID 4004 does not match column SRID 4326
SELECT 'SRID=4004;POINT(2.0 3.0)'::geometry::geometry(point, 4326)
statement error SRID 4004 does not match column SRID 4326
SELECT 'SRID=4004;POINT(2.0 3.0)'::geography::geometry(point, 4326)
statement error SRID 4326 does not match column SRID 4004
SELECT 'POINT(1.0 2.0)'::geometry::geography(geometry, 4004)
statement error type Point does not match column type LineString
SELECT 'SRID=4004;POINT(2.0 3.0)'::geometry::geometry(linestring)
statement error type Point does not match column type LineString
SELECT 'SRID=4004;POINT(2.0 3.0)'::geometry::geography(linestring)
statement error type Point does not match column type LineString
SELECT 'SRID=4004;POINT(2.0 3.0)'::geography::geography(linestring)
statement error type Point does not match column type LineString
SELECT 'SRID=4004;POINT(2.0 3.0)'::geography::geometry(linestring)
subtest parse_and_unparse
statement ok
CREATE TABLE parse_test (
id SERIAL PRIMARY KEY,
geom GEOMETRY,
geog GEOGRAPHY
)
# These values cannot be inserted into the database due to mismatching SRIDs.
query TT nosort
SELECT
ST_AsEWKT(geom),
ST_AsEWKT(geog)
FROM ( VALUES
(ST_GeometryFromText('SRID=4326;POINT(1.0 2.0)', 4004), ST_GeographyFromText('SRID=4326;POINT(1.0 2.0)', 4004)),
(ST_GeomFromText('SRID=4326;POINT(1.0 2.0)', 4004), ST_GeogFromText('SRID=4326;POINT(1.0 2.0)', 4004)),
(ST_GeometryFromText('SRID=4326;POINT(1.0 2.0)'), ST_GeographyFromText('POINT(1.0 2.0)', 4004)),
(ST_GeomFromEWKT('SRID=4004;POINT(1.0 2.0)'), ST_GeogFromEWKT('SRID=4004;POINT(1.0 2.0)')),
(ST_GeomFromWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex'), 4004), ST_GeogFromWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex'), 4004)),
(ST_GeomFromWKB(decode('0101000020E6100000000000000000F03F0000000000000040', 'hex'), 4004), ST_GeogFromWKB(decode('0101000020E6100000000000000000F03F0000000000000040', 'hex'), 4004)),
(ST_GeomFromWKB(decode('0101000020A40F0000000000000000F03F0000000000000040', 'hex')), ST_GeogFromWKB(decode('0101000020A40F0000000000000000F03F0000000000000040', 'hex')))
) t(geom, geog)
----
SRID=4004;POINT (1 2) SRID=4004;POINT (1 2)
SRID=4004;POINT (1 2) SRID=4004;POINT (1 2)
SRID=4326;POINT (1 2) SRID=4004;POINT (1 2)
SRID=4004;POINT (1 2) SRID=4004;POINT (1 2)
SRID=4004;POINT (1 1) SRID=4004;POINT (1 1)
SRID=4004;POINT (1 2) SRID=4004;POINT (1 2)
SRID=4004;POINT (1 2) SRID=4004;POINT (1 2)
query T nosort
SELECT ST_AsEWKT(g) FROM ( VALUES
(GeomFromEWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex'))),
(GeomFromEWKT('SRID=4004;LINESTRING(-1 -1, 2 2)'))
) t(g)
----
POINT (1 1)
SRID=4004;LINESTRING (-1 -1, 2 2)
statement ok
INSERT INTO parse_test (geom, geog) VALUES
(ST_GeomFromText('POINT(1.555 -2.0)'), ST_GeogFromText('POINT(1.555 -2.0)')),
(ST_GeomFromText('SRID=4326;POINT(1.0 2.0)'), ST_GeogFromText('SRID=4326;POINT(1.0 2.0)')),
(ST_GeometryFromText('SRID=4004;POINT(1.0 2.0)'), ST_GeographyFromText('POINT(1.0 2.0)')),
(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[1,2]}'), ST_GeogFromGeoJSON('{"type":"Point","coordinates":[1,2]}')),
(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[1,2]}'::jsonb), ST_GeogFromGeoJSON('{"type":"Point","coordinates":[1,2]}'::jsonb)),
(ST_GeomFromWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex')), ST_GeogFromWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex'))),
(ST_GeomFromEWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex')), ST_GeogFromEWKB(decode('0101000000000000000000F03F000000000000F03F', 'hex'))),
(ST_GeomFromText('POINT EMPTY'), ST_GeogFromText('POINT EMPTY')),
(ST_GeomFromGeoJSON('null':::jsonb), ST_GeogFromGeoJSON('null':::jsonb))
query BB
SELECT
st_geomfromwkb(decode('0101000000000000000000F03F000000000000F03F', 'hex')) = st_wkbtosql(decode('0101000000000000000000F03F000000000000F03F', 'hex')),
st_geomfromtext('POINT(1.0 2.0)') = st_wkttosql('POINT(1.0 2.0)')
----
true true
statement error invalid GeoJSON input
select st_geomfromgeojson(json_typeof('null'))
statement error invalid GeoJSON input
select st_geogfromgeojson(json_typeof('null'))
query TTTTTTT
SELECT
ST_AsText(geom),
ST_AsEWKT(geom),
ST_AsBinary(geom),
ST_AsBinary(geom, 'ndr'),
ST_AsBinary(geom, 'xdr'),
ST_AsEWKB(geom),
ST_AsKML(geom)
FROM parse_test ORDER BY id ASC
----
POINT (1.555 -2) POINT (1.555 -2) [1 1 0 0 0 225 122 20 174 71 225 248 63 0 0 0 0 0 0 0 192] [1 1 0 0 0 225 122 20 174 71 225 248 63 0 0 0 0 0 0 0 192] [0 0 0 0 1 63 248 225 71 174 20 122 225 192 0 0 0 0 0 0 0] [1 1 0 0 0 225 122 20 174 71 225 248 63 0 0 0 0 0 0 0 192] <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1.555,-2</coordinates></Point>
POINT (1 2) SRID=4326;POINT (1 2) [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] [0 0 0 0 1 63 240 0 0 0 0 0 0 64 0 0 0 0 0 0 0] [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,2</coordinates></Point>
POINT (1 2) SRID=4004;POINT (1 2) [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] [0 0 0 0 1 63 240 0 0 0 0 0 0 64 0 0 0 0 0 0 0] [1 1 0 0 32 164 15 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,2</coordinates></Point>
POINT (1 2) SRID=4326;POINT (1 2) [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] [0 0 0 0 1 63 240 0 0 0 0 0 0 64 0 0 0 0 0 0 0] [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,2</coordinates></Point>
POINT (1 2) SRID=4326;POINT (1 2) [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] [0 0 0 0 1 63 240 0 0 0 0 0 0 64 0 0 0 0 0 0 0] [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,2</coordinates></Point>
POINT (1 1) POINT (1 1) [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] [0 0 0 0 1 63 240 0 0 0 0 0 0 63 240 0 0 0 0 0 0] [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,1</coordinates></Point>
POINT (1 1) POINT (1 1) [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] [0 0 0 0 1 63 240 0 0 0 0 0 0 63 240 0 0 0 0 0 0] [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,1</coordinates></Point>
POINT EMPTY POINT EMPTY [1 1 0 0 0 0 0 0 0 0 0 248 127 0 0 0 0 0 0 248 127] [1 1 0 0 0 0 0 0 0 0 0 248 127 0 0 0 0 0 0 248 127] [0 0 0 0 1 127 248 0 0 0 0 0 0 127 248 0 0 0 0 0 0] [1 1 0 0 0 0 0 0 0 0 0 248 127 0 0 0 0 0 0 248 127] <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates></coordinates></Point>
NULL NULL NULL NULL NULL NULL NULL
query TTT nosort
SELECT ST_AsEWKT(g), ST_GeoHash(g), ST_GeoHash(g, 8) FROM ( VALUES
('POINT (0 0)'::geometry),
('LINESTRING(0 0, 1 0)'::geometry)
) t(g)
----
POINT (0 0) s0000000000000000000 s0000000
LINESTRING (0 0, 1 0) · s00252h0
query TTT
SELECT
ST_AsGeoJSON(geom),
ST_AsGeoJSON(geom, 6, 8),
ST_AsGeoJSON(geom, 6, 5)
FROM parse_test ORDER BY id ASC
----
{"type":"Point","coordinates":[1.555,-2]} {"type":"Point","coordinates":[1.555,-2]} {"type":"Point","bbox":[1.555,-2,1.555,-2],"coordinates":[1.555,-2]}
{"type":"Point","coordinates":[1,2]} {"type":"Point","coordinates":[1,2]} {"type":"Point","bbox":[1,2,1,2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,2]}
{"type":"Point","crs":{"type":"name","properties":{"name":"EPSG:4004"}},"coordinates":[1,2]} {"type":"Point","crs":{"type":"name","properties":{"name":"EPSG:4004"}},"coordinates":[1,2]} {"type":"Point","bbox":[1,2,1,2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4004"}},"coordinates":[1,2]}
{"type":"Point","coordinates":[1,2]} {"type":"Point","coordinates":[1,2]} {"type":"Point","bbox":[1,2,1,2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,2]}
{"type":"Point","coordinates":[1,2]} {"type":"Point","coordinates":[1,2]} {"type":"Point","bbox":[1,2,1,2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,2]}
{"type":"Point","coordinates":[1,1]} {"type":"Point","coordinates":[1,1]} {"type":"Point","bbox":[1,1,1,1],"coordinates":[1,1]}
{"type":"Point","coordinates":[1,1]} {"type":"Point","coordinates":[1,1]} {"type":"Point","bbox":[1,1,1,1],"coordinates":[1,1]}
{"type":"Point","coordinates":[]} {"type":"Point","coordinates":[]} {"type":"Point","coordinates":[]}
NULL NULL NULL
# Since id in parse_test can change between tests, make a new table
# that has a consistent id over multiple logic test runs.
statement ok
CREATE TABLE parse_test_geojson AS
SELECT
row_number() OVER (ORDER BY id) as id,
geom,
geog
FROM parse_test
query T nosort
SELECT
ST_AsGeoJSON(t.*)
FROM ( VALUES
(1),
(2)
) t(row_id)
----
{"geometry": {"type": null}, "properties": {"row_id": 1}, "type": "Feature"}
{"geometry": {"type": null}, "properties": {"row_id": 2}, "type": "Feature"}
query TTT
SELECT
ST_AsGeoJSON(parse_test_geojson.*),
ST_AsGeoJSON(parse_test_geojson.*, 'geom'),
ST_AsGeoJSON(parse_test_geojson.*, 'geog')
FROM parse_test_geojson ORDER BY id ASC
----
{"geometry": {"coordinates": [1.555, -2], "type": "Point"}, "properties": {"geog": {"coordinates": [1.555, -2], "type": "Point"}, "id": 1}, "type": "Feature"} {"geometry": {"coordinates": [1.555, -2], "type": "Point"}, "properties": {"geog": {"coordinates": [1.555, -2], "type": "Point"}, "id": 1}, "type": "Feature"} {"geometry": {"coordinates": [1.555, -2], "type": "Point"}, "properties": {"geom": {"coordinates": [1.555, -2], "type": "Point"}, "id": 1}, "type": "Feature"}
{"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 2], "type": "Point"}, "id": 2}, "type": "Feature"} {"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 2], "type": "Point"}, "id": 2}, "type": "Feature"} {"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geom": {"coordinates": [1, 2], "type": "Point"}, "id": 2}, "type": "Feature"}
{"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 2], "type": "Point"}, "id": 3}, "type": "Feature"} {"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 2], "type": "Point"}, "id": 3}, "type": "Feature"} {"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geom": {"coordinates": [1, 2], "type": "Point"}, "id": 3}, "type": "Feature"}
{"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 2], "type": "Point"}, "id": 4}, "type": "Feature"} {"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 2], "type": "Point"}, "id": 4}, "type": "Feature"} {"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geom": {"coordinates": [1, 2], "type": "Point"}, "id": 4}, "type": "Feature"}
{"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 2], "type": "Point"}, "id": 5}, "type": "Feature"} {"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 2], "type": "Point"}, "id": 5}, "type": "Feature"} {"geometry": {"coordinates": [1, 2], "type": "Point"}, "properties": {"geom": {"coordinates": [1, 2], "type": "Point"}, "id": 5}, "type": "Feature"}
{"geometry": {"coordinates": [1, 1], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 1], "type": "Point"}, "id": 6}, "type": "Feature"} {"geometry": {"coordinates": [1, 1], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 1], "type": "Point"}, "id": 6}, "type": "Feature"} {"geometry": {"coordinates": [1, 1], "type": "Point"}, "properties": {"geom": {"coordinates": [1, 1], "type": "Point"}, "id": 6}, "type": "Feature"}
{"geometry": {"coordinates": [1, 1], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 1], "type": "Point"}, "id": 7}, "type": "Feature"} {"geometry": {"coordinates": [1, 1], "type": "Point"}, "properties": {"geog": {"coordinates": [1, 1], "type": "Point"}, "id": 7}, "type": "Feature"} {"geometry": {"coordinates": [1, 1], "type": "Point"}, "properties": {"geom": {"coordinates": [1, 1], "type": "Point"}, "id": 7}, "type": "Feature"}
{"geometry": {"coordinates": [], "type": "Point"}, "properties": {"geog": {"coordinates": [], "type": "Point"}, "id": 8}, "type": "Feature"} {"geometry": {"coordinates": [], "type": "Point"}, "properties": {"geog": {"coordinates": [], "type": "Point"}, "id": 8}, "type": "Feature"} {"geometry": {"coordinates": [], "type": "Point"}, "properties": {"geom": {"coordinates": [], "type": "Point"}, "id": 8}, "type": "Feature"}
{"geometry": {"type": null}, "properties": {"geog": null, "geom": null, "id": 9}, "type": "Feature"} {"geometry": {"type": null}, "properties": {"geog": null, "id": 9}, "type": "Feature"} {"geometry": {"type": null}, "properties": {"geom": null, "id": 9}, "type": "Feature"}
query T
SELECT
ST_AsGeoJSON(parse_test_geojson.*, 'geog', 3, true)
FROM parse_test_geojson ORDER BY id ASC
----
{
"geometry": {
"coordinates": [
1.555,
-2
],
"type": "Point"
},
"properties": {
"geom": {
"coordinates": [
1.555,
-2
],
"type": "Point"
},
"id": 1
},
"type": "Feature"
}
{
"geometry": {
"coordinates": [
1,
2
],
"type": "Point"
},
"properties": {
"geom": {
"coordinates": [
1,
2
],
"type": "Point"
},
"id": 2
},
"type": "Feature"
}
{
"geometry": {
"coordinates": [
1,
2
],
"type": "Point"
},
"properties": {
"geom": {
"coordinates": [
1,
2
],
"type": "Point"
},
"id": 3
},
"type": "Feature"
}
{
"geometry": {
"coordinates": [
1,
2
],
"type": "Point"
},
"properties": {
"geom": {
"coordinates": [
1,
2
],
"type": "Point"
},
"id": 4
},
"type": "Feature"
}
{
"geometry": {
"coordinates": [
1,
2
],
"type": "Point"
},
"properties": {
"geom": {
"coordinates": [
1,
2
],
"type": "Point"
},
"id": 5
},
"type": "Feature"
}
{
"geometry": {
"coordinates": [
1,
1
],
"type": "Point"
},
"properties": {
"geom": {
"coordinates": [
1,
1
],
"type": "Point"
},
"id": 6
},
"type": "Feature"
}
{
"geometry": {
"coordinates": [
1,
1
],
"type": "Point"
},
"properties": {
"geom": {
"coordinates": [
1,
1
],
"type": "Point"
},
"id": 7
},
"type": "Feature"
}
{
"geometry": {
"coordinates": [],
"type": "Point"
},
"properties": {
"geom": {
"coordinates": [],
"type": "Point"
},
"id": 8
},
"type": "Feature"
}
{
"geometry": {
"type": null
},
"properties": {
"geom": null,
"id": 9
},
"type": "Feature"
}
statement error "geom_no_exist" column not found
SELECT
ST_AsGeoJSON(parse_test.*, 'geom_no_exist')
FROM parse_test ORDER BY id asc
# tests casts
query TTT
SELECT
geom::bytea,
geom::jsonb,
geom::string
FROM parse_test ORDER BY id ASC
----
[1 1 0 0 0 225 122 20 174 71 225 248 63 0 0 0 0 0 0 0 192] {"coordinates": [1.555, -2], "type": "Point"} 0101000000E17A14AE47E1F83F00000000000000C0
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] {"coordinates": [1, 2], "type": "Point"} 0101000020E6100000000000000000F03F0000000000000040
[1 1 0 0 32 164 15 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] {"coordinates": [1, 2], "type": "Point"} 0101000020A40F0000000000000000F03F0000000000000040
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] {"coordinates": [1, 2], "type": "Point"} 0101000020E6100000000000000000F03F0000000000000040
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] {"coordinates": [1, 2], "type": "Point"} 0101000020E6100000000000000000F03F0000000000000040
[1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] {"coordinates": [1, 1], "type": "Point"} 0101000000000000000000F03F000000000000F03F
[1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] {"coordinates": [1, 1], "type": "Point"} 0101000000000000000000F03F000000000000F03F
[1 1 0 0 0 0 0 0 0 0 0 248 127 0 0 0 0 0 0 248 127] {"coordinates": [], "type": "Point"} 0101000000000000000000F87F000000000000F87F
NULL NULL NULL
query TTT
SELECT
geom::bytea::geometry,
geom::jsonb::geometry,
geom::string::geometry
FROM parse_test ORDER BY id ASC
----
0101000000E17A14AE47E1F83F00000000000000C0 0101000020E6100000E17A14AE47E1F83F00000000000000C0 0101000000E17A14AE47E1F83F00000000000000C0
0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040
0101000020A40F0000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0101000020A40F0000000000000000F03F0000000000000040
0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040
0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040
0101000000000000000000F03F000000000000F03F 0101000020E6100000000000000000F03F000000000000F03F 0101000000000000000000F03F000000000000F03F
0101000000000000000000F03F000000000000F03F 0101000020E6100000000000000000F03F000000000000F03F 0101000000000000000000F03F000000000000F03F
0101000000000000000000F87F000000000000F87F 0101000020E6100000000000000000F87F000000000000F87F 0101000000000000000000F87F000000000000F87F
NULL NULL NULL
# test out of bounds precisions
query TTTT
SELECT
ST_AsText(geom, 123123123),
ST_AsText(geom, -1),
ST_AsGeoJSON(geom, 123123123),
ST_AsGeoJSON(geom, -1)
FROM parse_test ORDER BY id ASC
----
POINT (1.5549999999999999378275106209912337362766265869140625 -2) POINT (1.555 -2) {"type":"Point","coordinates":[1.5549999999999999378275106209912337362766265869140625,-2]} {"type":"Point","coordinates":[1.555,-2]}
POINT (1 2) POINT (1 2) {"type":"Point","coordinates":[1,2]} {"type":"Point","coordinates":[1,2]}
POINT (1 2) POINT (1 2) {"type":"Point","crs":{"type":"name","properties":{"name":"EPSG:4004"}},"coordinates":[1,2]} {"type":"Point","crs":{"type":"name","properties":{"name":"EPSG:4004"}},"coordinates":[1,2]}
POINT (1 2) POINT (1 2) {"type":"Point","coordinates":[1,2]} {"type":"Point","coordinates":[1,2]}
POINT (1 2) POINT (1 2) {"type":"Point","coordinates":[1,2]} {"type":"Point","coordinates":[1,2]}
POINT (1 1) POINT (1 1) {"type":"Point","coordinates":[1,1]} {"type":"Point","coordinates":[1,1]}
POINT (1 1) POINT (1 1) {"type":"Point","coordinates":[1,1]} {"type":"Point","coordinates":[1,1]}
POINT EMPTY POINT EMPTY {"type":"Point","coordinates":[]} {"type":"Point","coordinates":[]}
NULL NULL NULL NULL
query TTT
SELECT
ST_AsHexEWKB(geom),
ST_AsHexEWKB(geom, 'ndr'),
ST_AsHexEWKB(geom, 'xdr')
FROM parse_test ORDER BY id ASC
----
0101000000E17A14AE47E1F83F00000000000000C0 0101000000E17A14AE47E1F83F00000000000000C0 00000000013FF8E147AE147AE1C000000000000000
0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0020000001000010E63FF00000000000004000000000000000
0101000020A40F0000000000000000F03F0000000000000040 0101000020A40F0000000000000000F03F0000000000000040 002000000100000FA43FF00000000000004000000000000000
0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0020000001000010E63FF00000000000004000000000000000
0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0020000001000010E63FF00000000000004000000000000000
0101000000000000000000F03F000000000000F03F 0101000000000000000000F03F000000000000F03F 00000000013FF00000000000003FF0000000000000
0101000000000000000000F03F000000000000F03F 0101000000000000000000F03F000000000000F03F 00000000013FF00000000000003FF0000000000000
0101000000000000000000F87F000000000000F87F 0101000000000000000000F87F000000000000F87F 00000000017FF80000000000007FF8000000000000
NULL NULL NULL
query TTTTTTT
SELECT
ST_AsText(geog),
ST_AsEWKT(geog),
ST_AsBinary(geog),
ST_AsBinary(geog, 'ndr'),
ST_AsBinary(geog, 'xdr'),
ST_AsEWKB(geog),
ST_AsKML(geog)
FROM parse_test ORDER BY id ASC
----
POINT (1.555 -2) SRID=4326;POINT (1.555 -2) [1 1 0 0 0 225 122 20 174 71 225 248 63 0 0 0 0 0 0 0 192] [1 1 0 0 0 225 122 20 174 71 225 248 63 0 0 0 0 0 0 0 192] [0 0 0 0 1 63 248 225 71 174 20 122 225 192 0 0 0 0 0 0 0] [1 1 0 0 32 230 16 0 0 225 122 20 174 71 225 248 63 0 0 0 0 0 0 0 192] <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1.555,-2</coordinates></Point>
POINT (1 2) SRID=4326;POINT (1 2) [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] [0 0 0 0 1 63 240 0 0 0 0 0 0 64 0 0 0 0 0 0 0] [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,2</coordinates></Point>
POINT (1 2) SRID=4326;POINT (1 2) [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] [0 0 0 0 1 63 240 0 0 0 0 0 0 64 0 0 0 0 0 0 0] [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,2</coordinates></Point>
POINT (1 2) SRID=4326;POINT (1 2) [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] [0 0 0 0 1 63 240 0 0 0 0 0 0 64 0 0 0 0 0 0 0] [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,2</coordinates></Point>
POINT (1 2) SRID=4326;POINT (1 2) [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] [0 0 0 0 1 63 240 0 0 0 0 0 0 64 0 0 0 0 0 0 0] [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,2</coordinates></Point>
POINT (1 1) SRID=4326;POINT (1 1) [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] [0 0 0 0 1 63 240 0 0 0 0 0 0 63 240 0 0 0 0 0 0] [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,1</coordinates></Point>
POINT (1 1) SRID=4326;POINT (1 1) [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] [1 1 0 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] [0 0 0 0 1 63 240 0 0 0 0 0 0 63 240 0 0 0 0 0 0] [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates>1,1</coordinates></Point>
POINT EMPTY SRID=4326;POINT EMPTY [1 1 0 0 0 0 0 0 0 0 0 248 127 0 0 0 0 0 0 248 127] [1 1 0 0 0 0 0 0 0 0 0 248 127 0 0 0 0 0 0 248 127] [0 0 0 0 1 127 248 0 0 0 0 0 0 127 248 0 0 0 0 0 0] [1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 248 127 0 0 0 0 0 0 248 127] <?xml version="1.0" encoding="UTF-8"?>
<Point><coordinates></coordinates></Point>
NULL NULL NULL NULL NULL NULL NULL
query TTT
SELECT
ST_AsGeoJSON(geog),
ST_AsGeoJSON(geog, 6, 8),
ST_AsGeoJSON(geog, 6, 5)
FROM parse_test ORDER BY id ASC
----
{"type":"Point","coordinates":[1.555,-2]} {"type":"Point","coordinates":[1.555,-2]} {"type":"Point","bbox":[1.555,-2,1.555,-2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1.555,-2]}
{"type":"Point","coordinates":[1,2]} {"type":"Point","coordinates":[1,2]} {"type":"Point","bbox":[1,2,1,2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,2]}
{"type":"Point","coordinates":[1,2]} {"type":"Point","coordinates":[1,2]} {"type":"Point","bbox":[1,2,1,2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,2]}
{"type":"Point","coordinates":[1,2]} {"type":"Point","coordinates":[1,2]} {"type":"Point","bbox":[1,2,1,2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,2]}
{"type":"Point","coordinates":[1,2]} {"type":"Point","coordinates":[1,2]} {"type":"Point","bbox":[1,2,1,2],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,2]}
{"type":"Point","coordinates":[1,1]} {"type":"Point","coordinates":[1,1]} {"type":"Point","bbox":[1,1,1,1],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,1]}
{"type":"Point","coordinates":[1,1]} {"type":"Point","coordinates":[1,1]} {"type":"Point","bbox":[1,1,1,1],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[1,1]}
{"type":"Point","coordinates":[]} {"type":"Point","coordinates":[]} {"type":"Point","crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::4326"}},"coordinates":[]}
NULL NULL NULL
query T
select st_asgeojson(
('0101000000000000000000F03F000000000000F03F':::GEOMETRY,),
'':::STRING::STRING,
2088580099783884006:::INT8::INT8,
false::BOOL
)::STRING AS regression_57983
----
{"geometry": {"coordinates": [1, 1], "type": "Point"}, "properties": {}, "type": "Feature"}
query TTT nosort
SELECT ST_AsEWKT(g), ST_GeoHash(g), ST_GeoHash(g, 8) FROM ( VALUES
('POINT (0 0)'::geography),
('LINESTRING(0 0, 1 0)'::geography)
) t(g)
----
SRID=4326;POINT (0 0) s0000000000000000000 s0000000
SRID=4326;LINESTRING (0 0, 1 0) · s00252h0
# tests casts
query TTT
SELECT
geog::bytea,
geog::jsonb,
geog::string
FROM parse_test ORDER BY id ASC
----
[1 1 0 0 32 230 16 0 0 225 122 20 174 71 225 248 63 0 0 0 0 0 0 0 192] {"coordinates": [1.555, -2], "type": "Point"} 0101000020E6100000E17A14AE47E1F83F00000000000000C0
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] {"coordinates": [1, 2], "type": "Point"} 0101000020E6100000000000000000F03F0000000000000040
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] {"coordinates": [1, 2], "type": "Point"} 0101000020E6100000000000000000F03F0000000000000040
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] {"coordinates": [1, 2], "type": "Point"} 0101000020E6100000000000000000F03F0000000000000040
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 0 64] {"coordinates": [1, 2], "type": "Point"} 0101000020E6100000000000000000F03F0000000000000040
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] {"coordinates": [1, 1], "type": "Point"} 0101000020E6100000000000000000F03F000000000000F03F
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 240 63 0 0 0 0 0 0 240 63] {"coordinates": [1, 1], "type": "Point"} 0101000020E6100000000000000000F03F000000000000F03F
[1 1 0 0 32 230 16 0 0 0 0 0 0 0 0 248 127 0 0 0 0 0 0 248 127] {"coordinates": [], "type": "Point"} 0101000020E6100000000000000000F87F000000000000F87F
NULL NULL NULL
query TTT
SELECT
geog::bytea::geography,
geog::jsonb::geography,
geog::string::geography
FROM parse_test ORDER BY id ASC
----
0101000020E6100000E17A14AE47E1F83F00000000000000C0 0101000020E6100000E17A14AE47E1F83F00000000000000C0 0101000020E6100000E17A14AE47E1F83F00000000000000C0
0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040
0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040
0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040
0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040
0101000020E6100000000000000000F03F000000000000F03F 0101000020E6100000000000000000F03F000000000000F03F 0101000020E6100000000000000000F03F000000000000F03F
0101000020E6100000000000000000F03F000000000000F03F 0101000020E6100000000000000000F03F000000000000F03F 0101000020E6100000000000000000F03F000000000000F03F
0101000020E6100000000000000000F87F000000000000F87F 0101000020E6100000000000000000F87F000000000000F87F 0101000020E6100000000000000000F87F000000000000F87F
NULL NULL NULL
query TTTT
SELECT
ST_AsHexWKB(geog),
ST_AsHexEWKB(geog),
ST_AsHexEWKB(geog, 'ndr'),
ST_AsHexEWKB(geog, 'xdr')
FROM parse_test ORDER BY id ASC
----
0101000000E17A14AE47E1F83F00000000000000C0 0101000020E6100000E17A14AE47E1F83F00000000000000C0 0101000020E6100000E17A14AE47E1F83F00000000000000C0 0020000001000010E63FF8E147AE147AE1C000000000000000
0101000000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0020000001000010E63FF00000000000004000000000000000
0101000000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0020000001000010E63FF00000000000004000000000000000
0101000000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0020000001000010E63FF00000000000004000000000000000
0101000000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0101000020E6100000000000000000F03F0000000000000040 0020000001000010E63FF00000000000004000000000000000
0101000000000000000000F03F000000000000F03F 0101000020E6100000000000000000F03F000000000000F03F 0101000020E6100000000000000000F03F000000000000F03F 0020000001000010E63FF00000000000003FF0000000000000
0101000000000000000000F03F000000000000F03F 0101000020E6100000000000000000F03F000000000000F03F 0101000020E6100000000000000000F03F000000000000F03F 0020000001000010E63FF00000000000003FF0000000000000
0101000000000000000000F87F000000000000F87F 0101000020E6100000000000000000F87F000000000000F87F 0101000020E6100000000000000000F87F000000000000F87F 0020000001000010E67FF80000000000007FF8000000000000
NULL NULL NULL NULL
query T nosort
SELECT
ST_AsText(g)
FROM ( VALUES
(ST_PointFromGeoHash('s000000000000000')),
(ST_PointFromGeoHash('kkqnpkue9ktbpe5')),
(ST_PointFromGeoHash('w000000000000000')),
(ST_PointFromGeoHash('w000000000000000',5)),
(ST_GeomFromGeoHash('s000000000000000')),
(ST_GeomFromGeoHash('kkqnpkue9ktbpe5')),
(ST_GeomFromGeoHash('w000000000000000')),
(ST_GeomFromGeoHash('w000000000000000',5))
) tbl(g)
----
POINT (0.000000000163709 0.000000000081855)
POINT (20.01234499963175 -20.01234499963175)
POINT (90.000000000163709 0.000000000081855)
POINT (90.02197265625 0.02197265625)
POLYGON ((0 0, 0 0.000000000163709, 0.000000000327418 0.000000000163709, 0.000000000327418 0, 0 0))
POLYGON ((20.012344998976914 -20.012345000286587, 20.012344998976914 -20.012344998976914, 20.012345000286587 -20.012344998976914, 20.012345000286587 -20.012345000286587, 20.012344998976914 -20.012345000286587))
POLYGON ((90 0, 90 0.000000000163709, 90.000000000327418 0.000000000163709, 90.000000000327418 0, 90 0))
POLYGON ((90 0, 90 0.0439453125, 90.0439453125 0.0439453125, 90.0439453125 0, 90 0))
statement error pq: st_pointfromgeohash\(\): invalid GeoHash: geohash decode '----': invalid character at index 0
SELECT ST_AsText(ST_PointFromGeoHash('----'))
statement error pq: st_pointfromgeohash\(\): length of GeoHash must be greater than 0
SELECT ST_AsText(ST_PointFromGeoHash(''))
query TTTTTTTT
SELECT
ST_PointFromText('POINT(1.0 1.0)'),
ST_PointFromText('POINT(1.0 1.0)', 4326),
ST_PointFromText('LINESTRING(1.0 1.0, 2.0 2.0)'),
ST_PointFromText('LINESTRING(1.0 1.0, 2.0 2.0)', 4326),
ST_PointFromWKB(ST_AsBinary('POINT(1.0 1.0)'::geometry)),
ST_PointFromWKB(ST_AsBinary('POINT(1.0 1.0)'::geometry), 4326),
ST_PointFromWKB(ST_AsBinary('LINESTRING(1.0 1.0, 2.0 2.0)'::geometry)),
ST_PointFromWKB(ST_AsBinary('LINESTRING(1.0 1.0, 2.0 2.0)'::geometry), 4326)
----
0101000000000000000000F03F000000000000F03F 0101000020E6100000000000000000F03F000000000000F03F NULL NULL 0101000000000000000000F03F000000000000F03F 0101000020E6100000000000000000F03F000000000000F03F NULL NULL
subtest geom_operators
statement ok
CREATE TABLE geom_operators_test (
dsc TEXT PRIMARY KEY,
geom GEOMETRY
)
statement ok
INSERT INTO geom_operators_test VALUES
('NULL', NULL),
('Square (left)', 'POLYGON((-1.0 0.0, 0.0 0.0, 0.0 1.0, -1.0 1.0, -1.0 0.0))'),
('Point middle of Left Square', 'POINT(-0.5 0.5)'),
('Square (right)', 'POLYGON((0.0 0.0, 1.0 0.0, 1.0 1.0, 0.0 1.0, 0.0 0.0))'),
('Point middle of Right Square', 'POINT(0.5 0.5)'),
('Square overlapping left and right square', 'POLYGON((-0.1 0.0, 1.0 0.0, 1.0 1.0, -0.1 1.0, -0.1 0.0))'),
('Line going through left and right square', 'LINESTRING(-0.5 0.5, 0.5 0.5)'),
('Faraway point', 'POINT(5.0 5.0)'),
('Empty LineString', 'LINESTRING EMPTY'),
('Empty Point', 'POINT EMPTY'),
('Empty GeometryCollection', 'GEOMETRYCOLLECTION EMPTY'),
('Nested Geometry Collection', 'GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(0 0)))'::geometry)
-- ('Partially Empty GeometryCollection', 'GEOMETRYCOLLECTION ( LINESTRING EMPTY, POINT (0.0 0.0) )') -- some of these cases crash GEOS.
# GROUP BY
query TR
SELECT
a.dsc,
ST_Area(a.geom)
FROM geom_operators_test a
GROUP BY a.dsc, a.geom
ORDER BY a.dsc
----
Empty GeometryCollection 0
Empty LineString 0
Empty Point 0
Faraway point 0
Line going through left and right square 0
NULL NULL
Nested Geometry Collection 0
Point middle of Left Square 0
Point middle of Right Square 0
Square (left) 1
Square (right) 1
Square overlapping left and right square 1.1
# *BBox operators
query TBTTT
SELECT
dsc,
PostGIS_HasBBox(geom),
ST_AsEWKT(PostGIS_AddBBox(geom)),
PostGIS_GetBBox(geom),
ST_AsEWKT(PostGIS_DropBBox(geom))
FROM geom_operators_test
ORDER BY dsc ASC
----
Empty GeometryCollection false GEOMETRYCOLLECTION EMPTY NULL GEOMETRYCOLLECTION EMPTY
Empty LineString false LINESTRING EMPTY NULL LINESTRING EMPTY
Empty Point false POINT EMPTY NULL POINT EMPTY
Faraway point false POINT (5 5) BOX(5 5,5 5) POINT (5 5)
Line going through left and right square true LINESTRING (-0.5 0.5, 0.5 0.5) BOX(-0.5 0.5,0.5 0.5) LINESTRING (-0.5 0.5, 0.5 0.5)
NULL NULL NULL NULL NULL
Nested Geometry Collection true GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0))) BOX(0 0,0 0) GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0)))
Point middle of Left Square false POINT (-0.5 0.5) BOX(-0.5 0.5,-0.5 0.5) POINT (-0.5 0.5)
Point middle of Right Square false POINT (0.5 0.5) BOX(0.5 0.5,0.5 0.5) POINT (0.5 0.5)
Square (left) true POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0)) BOX(-1 0,0 1) POLYGON ((-1 0, 0 0, 0 1, -1 1, -1 0))
Square (right) true POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) BOX(0 0,1 1) POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
Square overlapping left and right square true POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0)) BOX(-0.1 0,1 1) POLYGON ((-0.1 0, 1 0, 1 1, -0.1 1, -0.1 0))
# Validity checking.
query TBBBTTTT nosort
SELECT
dsc,
ST_IsValid(geom),
ST_IsValid(geom, 0),
ST_IsValid(geom, 1),
ST_IsValidReason(geom),
ST_IsValidReason(geom, 0),