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

-- Back off displayed precision a little bit to reduce platform-to-platform
-- variation in results.
SET extra_float_digits TO -3;

--
-- Points
--

SELECT '' AS four, center(f1) AS center
   FROM BOX_TBL ORDER BY (center(f1))[0], (center(f1))[1];

SELECT '' AS four, (@@ f1) AS center
   FROM BOX_TBL ORDER BY (center(f1))[0], (center(f1))[1];

SELECT '' AS six, point(f1) AS center
   FROM CIRCLE_TBL ORDER BY (point(f1))[0], (point(f1))[1], radius(f1);

SELECT '' AS six, (@@ f1) AS center
   FROM CIRCLE_TBL ORDER BY (point(f1))[0], (point(f1))[1], radius(f1);

SELECT '' AS two, (@@ f1) AS center
   FROM POLYGON_TBL
   WHERE (# f1) > 2 ORDER BY ID;

-- "is horizontal" function
SELECT '' AS two, p1.f1
   FROM POINT_TBL p1
   WHERE ishorizontal(p1.f1, point '(0,0)') ORDER BY f1[0], f1[1];

-- "is horizontal" operator
SELECT '' AS two, p1.f1
   FROM POINT_TBL p1
   WHERE p1.f1 ?- point '(0,0)' ORDER BY f1[0], f1[1];

-- "is vertical" function
SELECT '' AS one, p1.f1
   FROM POINT_TBL p1
   WHERE isvertical(p1.f1, point '(5.1,34.5)') ORDER BY f1[0], f1[1];

-- "is vertical" operator
SELECT '' AS one, p1.f1
   FROM POINT_TBL p1
   WHERE p1.f1 ?| point '(5.1,34.5)' ORDER BY f1[0], f1[1];

--
-- Line segments
--

-- intersection
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
   FROM LSEG_TBL l, POINT_TBL p ORDER BY (l.s[0])[0], (l.s[0])[1], p.f1[0], p.f1[1];

-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
   FROM LSEG_TBL l, POINT_TBL p ORDER BY (l.s[0])[0], (l.s[0])[1], p.f1[0], p.f1[1];

--
-- Boxes
--

SELECT '' as six, box(f1) AS box FROM CIRCLE_TBL ORDER BY (point(f1))[0], (point(f1))[0], radius(f1);

-- translation
SELECT '' AS twentyfour, b.f1 + p.f1 AS translation
   FROM BOX_TBL b, POINT_TBL p ORDER BY (center(b.f1))[0], (center(b.f1))[1], p.f1[0], p.f1[1];

SELECT '' AS twentyfour, b.f1 - p.f1 AS translation
   FROM BOX_TBL b, POINT_TBL p ORDER BY (center(b.f1))[0], (center(b.f1))[1], p.f1[0], p.f1[1];

-- scaling and rotation
SELECT '' AS twentyfour, b.f1 * p.f1 AS rotation
   FROM BOX_TBL b, POINT_TBL p ORDER BY (center(b.f1))[0], (center(b.f1))[1], p.f1[0], p.f1[1];

SELECT '' AS twenty, b.f1 / p.f1 AS rotation
   FROM BOX_TBL b, POINT_TBL p
   WHERE (p.f1 <-> point '(0,0)') >= 1 ORDER BY (center(b.f1))[0], (center(b.f1))[1], p.f1[0], p.f1[1];

SELECT f1::box
	FROM POINT_TBL;

SELECT bound_box(a.f1, b.f1)
	FROM BOX_TBL a, BOX_TBL b;

--
-- Paths
--

SELECT '' AS eight, npoints(f1) AS npoints, f1 AS path FROM PATH_TBL ORDER BY ID;

SELECT '' AS four, path(f1) FROM POLYGON_TBL ORDER BY ID;

-- translation
SELECT '' AS eight, p1.f1 + point '(10,10)' AS dist_add
   FROM PATH_TBL p1 ORDER BY ID;

-- scaling and rotation
SELECT '' AS eight, p1.f1 * point '(2,-1)' AS dist_mul
   FROM PATH_TBL p1 ORDER BY ID;

--
-- Polygons
--

-- containment
SELECT '' AS twentyfour, p.f1, poly.f1, poly.f1 @> p.f1 AS contains
   FROM POLYGON_TBL poly, POINT_TBL p ORDER BY poly.ID, p.f1[0], p.f1[1];

SELECT '' AS twentyfour, p.f1, poly.f1, p.f1 <@ poly.f1 AS contained
   FROM POLYGON_TBL poly, POINT_TBL p ORDER BY poly.ID, p.f1[0], p.f1[1];

SELECT '' AS four, npoints(f1) AS npoints, f1 AS polygon
   FROM POLYGON_TBL ORDER BY ID;

SELECT '' AS four, polygon(f1)
   FROM BOX_TBL ORDER BY (center(f1))[0], (center(f1))[1];

SELECT '' AS four, polygon(f1)
   FROM PATH_TBL WHERE isclosed(f1) ORDER BY ID;

SELECT '' AS four, f1 AS open_path, polygon( pclose(f1)) AS polygon
   FROM PATH_TBL
   WHERE isopen(f1) ORDER BY ID;

-- convert circles to polygons using the default number of points
SELECT '' AS six, polygon(f1)
   FROM CIRCLE_TBL ORDER BY (point(f1))[0], (point(f1))[1], radius(f1);

-- convert the circle to an 8-point polygon
SELECT '' AS six, polygon(8, f1)
   FROM CIRCLE_TBL ORDER BY (point(f1))[0], (point(f1))[1], radius(f1);

--
-- Circles
--

SELECT '' AS six, circle(f1, 50.0)
   FROM POINT_TBL ORDER BY f1[0], f1[1];

SELECT '' AS four, circle(f1)
   FROM BOX_TBL ORDER BY (center(f1))[0], (center(f1))[1];

SELECT '' AS two, circle(f1)
   FROM POLYGON_TBL
   WHERE (# f1) >= 3 ORDER BY ID;

SELECT '' AS twentyfour, c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
   FROM CIRCLE_TBL c1, POINT_TBL p1
   WHERE (p1.f1 <-> c1.f1) > 0
   ORDER BY distance, area(c1.f1), p1.f1[0];