File: rt_nearestvalue.sql

package info (click to toggle)
postgis 2.3.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 58,660 kB
  • ctags: 10,181
  • sloc: ansic: 132,858; sql: 131,148; xml: 46,460; sh: 4,832; perl: 4,476; makefile: 2,749; python: 1,198; yacc: 442; lex: 131
file content (125 lines) | stat: -rw-r--r-- 3,168 bytes parent folder | download | duplicates (4)
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
DROP TABLE IF EXISTS raster_nearestvalue;
CREATE TABLE raster_nearestvalue (
	rast raster
);
CREATE OR REPLACE FUNCTION make_test_raster()
	RETURNS void
	AS $$
	DECLARE
		width int := 10;
		height int := 10;
		x int;
		y int;
		rast raster;
		valset double precision[][];
	BEGIN
		rast := ST_MakeEmptyRaster(width, height, 0, 0, 1, -1, 0, 0, 0);
		rast := ST_AddBand(rast, 1, '8BUI', 1, 0);


		valset := array_fill(0., ARRAY[height, width]);
		FOR y IN 1..height LOOP
			FOR x IN 1..width LOOP
				valset[y][x] := 2 * x + (1/3) * y;
			END LOOP;
		END LOOP;
		rast := ST_SetValues(rast, 1, 1, 1, valset);

		rast := ST_SetValue(rast, 1, 1, 0);
		rast := ST_SetValue(rast, 4, 1, 0);
		rast := ST_SetValue(rast, 7, 1, 0);
		rast := ST_SetValue(rast, 10, 1, 0);
		rast := ST_SetValue(rast, 2, 3, 0);
		rast := ST_SetValue(rast, 5, 3, 0);
		rast := ST_SetValue(rast, 8, 3, 0);
		rast := ST_SetValue(rast, 3, 5, 0);
		rast := ST_SetValue(rast, 6, 5, 0);
		rast := ST_SetValue(rast, 9, 5, 0);
		rast := ST_SetValue(rast, 1, 7, 0);
		rast := ST_SetValue(rast, 4, 7, 0);
		rast := ST_SetValue(rast, 7, 7, 0);
		rast := ST_SetValue(rast, 10, 7, 0);
		rast := ST_SetValue(rast, 2, 9, 0);
		rast := ST_SetValue(rast, 5, 9, 0);
		rast := ST_SetValue(rast, 8, 9, 0);

		INSERT INTO raster_nearestvalue VALUES (rast);

		RETURN;
	END;
	$$ LANGUAGE 'plpgsql';
SELECT make_test_raster();
DROP FUNCTION IF EXISTS make_test_raster();

SELECT
	ST_NearestValue(rast, 1, 1, 1)
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(ST_SetBandNoDataValue(rast, NULL), 1, 1, 1)
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, 2, 2)
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, 5, 5)
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, 5, 5)
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, 11, 11)
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, 12, 12)
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, 0, 0)
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, 0, 2)
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, -1, 3)
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, -9, 3)
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, -9, 3, FALSE)
FROM raster_nearestvalue;

SELECT
	ST_NearestValue(rast, 1, ST_MakePoint(1, 1))
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, ST_MakePoint(2, 2))
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, ST_MakePoint(5, 5))
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, ST_MakePoint(5, 5))
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, ST_MakePoint(11, 11))
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, ST_MakePoint(12, 12))
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, ST_MakePoint(0, 0))
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, ST_MakePoint(0, 2))
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, ST_MakePoint(-1, 3))
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, ST_MakePoint(-9, 3))
FROM raster_nearestvalue;
SELECT
	ST_NearestValue(rast, 1, ST_MakePoint(-9, 3), FALSE)
FROM raster_nearestvalue;

DROP TABLE IF EXISTS raster_nearestvalue;