File: rt_geos_relationships.sql

package info (click to toggle)
postgis 2.5.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 75,792 kB
  • sloc: ansic: 139,314; sql: 136,281; xml: 48,954; sh: 4,906; perl: 4,509; makefile: 2,897; python: 1,198; yacc: 441; cpp: 305; lex: 132
file content (272 lines) | stat: -rw-r--r-- 5,943 bytes parent folder | download | duplicates (7)
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
-- These tests are for raster functions that use GEOS spatial relationship functions

SET client_min_messages TO warning;

DROP TABLE IF EXISTS raster_geos_rast;
CREATE TABLE raster_geos_rast (
	rid integer,
	rast raster
);
CREATE OR REPLACE FUNCTION make_test_raster(
	rid integer,
	width integer DEFAULT 2, height integer DEFAULT 2,
	ul_x double precision DEFAULT 0, ul_y double precision DEFAULT 0,
	skew_x double precision DEFAULT 0, skew_y double precision DEFAULT 0
)
	RETURNS void
	AS $$
	DECLARE
		x int;
		y int;
		rast raster;
	BEGIN
		rast := ST_MakeEmptyRaster(width, height, ul_x, ul_y, 1, 1, skew_x, skew_y, 0);
		rast := ST_AddBand(rast, 1, '8BUI', 1, 0);

		INSERT INTO raster_geos_rast VALUES (rid, rast);

		RETURN;
	END;
	$$ LANGUAGE 'plpgsql';
SELECT make_test_raster(0, 2, 2, -1, -1);
SELECT make_test_raster(1, 2, 2);
SELECT make_test_raster(2, 3, 3);
SELECT make_test_raster(3, 2, 2, -1, -10);
DROP FUNCTION make_test_raster(integer, integer, integer, double precision, double precision, double precision, double precision);

INSERT INTO raster_geos_rast VALUES (10, (
	SELECT
		ST_SetValue(rast, 1, 1, 1, 0)
	FROM raster_geos_rast
	WHERE rid = 1
));
INSERT INTO raster_geos_rast VALUES (11, (
	SELECT
		ST_SetValue(rast, 1, 2, 1, 0)
	FROM raster_geos_rast
	WHERE rid = 1
));
INSERT INTO raster_geos_rast VALUES (12, (
	SELECT
		ST_SetValue(
			ST_SetValue(
				ST_SetValue(rast, 1, 1, 1, 0),
				1, 2, 1, 0
			),
			1, 1, 2, 0
		)
	FROM raster_geos_rast
	WHERE rid = 1
));
INSERT INTO raster_geos_rast VALUES (13, (
	SELECT
		ST_SetValue(
			ST_SetValue(
				ST_SetValue(
					ST_SetValue(rast, 1, 1, 1, 0),
					1, 2, 1, 0
				),
				1, 1, 2, 0
			),
			1, 2, 2, 0
		)
	FROM raster_geos_rast
	WHERE rid = 1
));
INSERT INTO raster_geos_rast VALUES (14, (
	SELECT
		ST_SetUpperLeft(rast, 2, 0)
	FROM raster_geos_rast
	WHERE rid = 1
));
INSERT INTO raster_geos_rast VALUES (15, (
	SELECT
		ST_SetScale(
			ST_SetUpperLeft(rast, 0.1, 0.1),
			0.4, 0.4
		)
	FROM raster_geos_rast
	WHERE rid = 1
));
INSERT INTO raster_geos_rast VALUES (16, (
	SELECT
		ST_SetScale(
			ST_SetUpperLeft(rast, -0.1, 0.1),
			0.4, 0.4
		)
	FROM raster_geos_rast
	WHERE rid = 1
));

INSERT INTO raster_geos_rast VALUES (20, (
	SELECT
		ST_SetUpperLeft(rast, -2, -2)
	FROM raster_geos_rast
	WHERE rid = 2
));
INSERT INTO raster_geos_rast VALUES (21, (
	SELECT
		ST_SetValue(
			ST_SetValue(
				ST_SetValue(rast, 1, 1, 1, 0),
				1, 2, 2, 0
			),
			1, 3, 3, 0
		)
	FROM raster_geos_rast
	WHERE rid = 20
));
INSERT INTO raster_geos_rast VALUES (22, (
	SELECT
		ST_SetValue(
			ST_SetValue(
				rast, 1, 3, 2, 0
			),
			1, 2, 3, 0
		)
	FROM raster_geos_rast
	WHERE rid = 21
));
INSERT INTO raster_geos_rast VALUES (23, (
	SELECT
		ST_SetValue(
			ST_SetValue(
				rast, 1, 3, 1, 0
			),
			1, 1, 3, 0
		)
	FROM raster_geos_rast
	WHERE rid = 22
));

INSERT INTO raster_geos_rast VALUES (30, (
	SELECT
		ST_SetSkew(rast, -0.5, 0.5)
	FROM raster_geos_rast
	WHERE rid = 2
));
INSERT INTO raster_geos_rast VALUES (31, (
	SELECT
		ST_SetSkew(rast, -1, 1)
	FROM raster_geos_rast
	WHERE rid = 2
));
INSERT INTO raster_geos_rast VALUES (32, (
	SELECT
		ST_SetSkew(rast, 1, -1)
	FROM raster_geos_rast
	WHERE rid = 2
));

SELECT
	'1.1',
	r1.rid,
	r2.rid,
	ST_Contains(r1.rast, NULL, r2.rast, NULL),
	ST_ContainsProperly(r1.rast, NULL, r2.rast, NULL),
	ST_CoveredBy(r1.rast, NULL, r2.rast, NULL),
	ST_Covers(r1.rast, NULL, r2.rast, NULL),
	ST_Disjoint(r1.rast, NULL, r2.rast, NULL),
	ST_Overlaps(r1.rast, NULL, r2.rast, NULL),
	ST_Touches(r1.rast, NULL, r2.rast, NULL),
	ST_Within(r1.rast, NULL, r2.rast, NULL),
	ST_DWithin(r1.rast, NULL, r2.rast, NULL, 0),
	ST_DWithin(r1.rast, 1, r2.rast, 1, 0),
	ST_DWithin(r1.rast, 1, r2.rast, 1, 1),
	ST_DWithin(r1.rast, 1, r2.rast, 1, 2),
	ST_DWithin(r1.rast, 1, r2.rast, 1, 7),
	ST_DFullyWithin(r1.rast, NULL, r2.rast, NULL, 0),
	ST_DFullyWithin(r1.rast, 1, r2.rast, 1, 0),
	ST_DFullyWithin(r1.rast, 1, r2.rast, 1, 1),
	ST_DFullyWithin(r1.rast, 1, r2.rast, 1, 2),
	ST_DFullyWithin(r1.rast, 1, r2.rast, 1, 7)
FROM raster_geos_rast r1
CROSS JOIN raster_geos_rast r2
WHERE r1.rid = 0;

SELECT
	'1.2',
	r1.rid,
	r2.rid,
	ST_Contains(r1.rast, 1, r2.rast, 1),
	ST_ContainsProperly(r1.rast, 1, r2.rast, 1),
	ST_CoveredBy(r1.rast, 1, r2.rast, 1),
	ST_Covers(r1.rast, 1, r2.rast, 1),
	ST_Disjoint(r1.rast, 1, r2.rast, 1),
	ST_Overlaps(r1.rast, 1, r2.rast, 1),
	ST_Touches(r1.rast, 1, r2.rast, 1),
	ST_Within(r1.rast, 1, r2.rast, 1)
FROM raster_geos_rast r1
JOIN raster_geos_rast r2
	ON r1.rid != r2.rid
WHERE r1.rid = 0;

SELECT
	'1.3',
	r1.rid,
	r2.rid,
	ST_Contains(r1.rast, NULL, r2.rast, NULL),
	ST_ContainsProperly(r1.rast, NULL, r2.rast, NULL),
	ST_CoveredBy(r1.rast, NULL, r2.rast, NULL),
	ST_Covers(r1.rast, NULL, r2.rast, NULL),
	ST_Within(r1.rast, NULL, r2.rast, NULL)
FROM raster_geos_rast r1
JOIN raster_geos_rast r2
	ON r1.rid != r2.rid
WHERE r2.rid = 0;

SELECT
	'1.4',
	r1.rid,
	r2.rid,
	ST_Contains(r1.rast, 1, r2.rast, 1),
	ST_ContainsProperly(r1.rast, 1, r2.rast, 1),
	ST_CoveredBy(r1.rast, 1, r2.rast, 1),
	ST_Covers(r1.rast, 1, r2.rast, 1),
	ST_Within(r1.rast, 1, r2.rast, 1)
FROM raster_geos_rast r1
JOIN raster_geos_rast r2
	ON r1.rid != r2.rid
WHERE r2.rid = 0;

SELECT
	'2.1',
	r1.rid,
	r2.rid,
	NULL AS distance,
	ST_DWithin(r1.rast, NULL, r2.rast, NULL, NULL)
FROM raster_geos_rast r1
CROSS JOIN raster_geos_rast r2
WHERE r1.rid = 0;

SELECT
	'2.2',
	r1.rid,
	r2.rid,
	-1 AS distance,
	ST_DWithin(r1.rast, NULL, r2.rast, NULL, -1)
FROM raster_geos_rast r1
CROSS JOIN raster_geos_rast r2
WHERE r1.rid = 0;

SELECT
	'2.3',
	r1.rid,
	r2.rid,
	NULL AS distance,
	ST_DFullyWithin(r1.rast, NULL, r2.rast, NULL, NULL)
FROM raster_geos_rast r1
CROSS JOIN raster_geos_rast r2
WHERE r1.rid = 0;

SELECT
	'2.4',
	r1.rid,
	r2.rid,
	-1 AS distance,
	ST_DFullyWithin(r1.rast, NULL, r2.rast, NULL, -1)
FROM raster_geos_rast r1
CROSS JOIN raster_geos_rast r2
WHERE r1.rid = 0;

DROP TABLE IF EXISTS raster_geos_rast;