]> granicus.if.org Git - postgresql/blob - src/test/regress/sql/geometry.sql
Create a 'type cache' that keeps track of the data needed for any particular
[postgresql] / src / test / regress / sql / geometry.sql
1 --
2 -- GEOMETRY
3 --
4
5 -- Back off displayed precision a little bit to reduce platform-to-platform
6 -- variation in results.
7 SET extra_float_digits TO -3;
8
9 --
10 -- Points
11 --
12
13 SELECT '' AS four, center(f1) AS center
14    FROM BOX_TBL;
15
16 SELECT '' AS four, (@@ f1) AS center
17    FROM BOX_TBL;
18
19 SELECT '' AS six, point(f1) AS center
20    FROM CIRCLE_TBL;
21
22 SELECT '' AS six, (@@ f1) AS center
23    FROM CIRCLE_TBL;
24
25 SELECT '' AS two, (@@ f1) AS center
26    FROM POLYGON_TBL
27    WHERE (# f1) > 2;
28
29 -- "is horizontal" function
30 SELECT '' AS two, p1.f1
31    FROM POINT_TBL p1
32    WHERE ishorizontal(p1.f1, point '(0,0)');
33
34 -- "is horizontal" operator
35 SELECT '' AS two, p1.f1
36    FROM POINT_TBL p1
37    WHERE p1.f1 ?- point '(0,0)';
38
39 -- "is vertical" function
40 SELECT '' AS one, p1.f1
41    FROM POINT_TBL p1
42    WHERE isvertical(p1.f1, point '(5.1,34.5)');
43
44 -- "is vertical" operator
45 SELECT '' AS one, p1.f1
46    FROM POINT_TBL p1
47    WHERE p1.f1 ?| point '(5.1,34.5)';
48
49 --
50 -- Line segments
51 --
52
53 -- intersection
54 SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
55    FROM LSEG_TBL l, POINT_TBL p;
56
57 -- closest point
58 SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
59    FROM LSEG_TBL l, POINT_TBL p;
60
61 --
62 -- Lines
63 --
64
65 --
66 -- Boxes
67 --
68
69 SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL;
70
71 -- translation
72 SELECT '' AS twentyfour, b.f1 + p.f1 AS translation
73    FROM BOX_TBL b, POINT_TBL p;
74
75 SELECT '' AS twentyfour, b.f1 - p.f1 AS translation
76    FROM BOX_TBL b, POINT_TBL p;
77
78 -- scaling and rotation
79 SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
80    FROM BOX_TBL b, POINT_TBL p;
81
82 SELECT '' AS twenty, b.f1 / p.f1 AS rotation
83    FROM BOX_TBL b, POINT_TBL p
84    WHERE (p.f1 <-> point '(0,0)') >= 1;
85
86 --
87 -- Paths
88 --
89
90 SET geqo TO 'off';
91
92 SELECT '' AS eight, npoints(f1) AS npoints, f1 AS path FROM PATH_TBL;
93
94 SELECT '' AS four, path(f1) FROM POLYGON_TBL;
95
96 -- translation
97 SELECT '' AS eight, p1.f1 + point '(10,10)' AS dist_add
98    FROM PATH_TBL p1;
99
100 -- scaling and rotation
101 SELECT '' AS eight, p1.f1 * point '(2,-1)' AS dist_mul
102    FROM PATH_TBL p1;
103
104 RESET geqo;
105
106 --
107 -- Polygons
108 --
109
110 -- containment
111 SELECT '' AS twentyfour, p.f1, poly.f1, poly.f1 ~ p.f1 AS contains
112    FROM POLYGON_TBL poly, POINT_TBL p;
113
114 SELECT '' AS twentyfour, p.f1, poly.f1, p.f1 @ poly.f1 AS contained
115    FROM POLYGON_TBL poly, POINT_TBL p;
116
117 SELECT '' AS four, npoints(f1) AS npoints, f1 AS polygon
118    FROM POLYGON_TBL;
119
120 SELECT '' AS four, polygon(f1)
121    FROM BOX_TBL;
122
123 SELECT '' AS four, polygon(f1)
124    FROM PATH_TBL WHERE isclosed(f1);
125
126 SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
127    FROM PATH_TBL
128    WHERE isopen(f1);
129
130 -- convert circles to polygons using the default number of points
131 SELECT '' AS six, polygon(f1)
132    FROM CIRCLE_TBL;
133
134 -- convert the circle to an 8-point polygon
135 SELECT '' AS six, polygon(8, f1)
136    FROM CIRCLE_TBL;
137
138 --
139 -- Circles
140 --
141
142 SELECT '' AS six, circle(f1, 50.0)
143    FROM POINT_TBL;
144
145 SELECT '' AS four, circle(f1)
146    FROM BOX_TBL;
147
148 SELECT '' AS two, circle(f1)
149    FROM POLYGON_TBL
150    WHERE (# f1) >= 3;
151
152 SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
153    FROM CIRCLE_TBL c1, POINT_TBL p1
154    WHERE (p1.f1 <-> c1.f1) > 0
155    ORDER BY distance, circle using <, point using <<;