rt_reclass.sql 4.08 KB
Newer Older
Bborie Park's avatar
Bborie Park committed
1 2 3 4 5 6 7 8 9 10
SELECT
	ST_Value(t.rast, 1, 1, 1),
	ST_Value(t.rast, 1, 10, 10),
	ST_Value(t.rast, 1, 2, 10),
	ST_BandNoDataValue(rast, 1)
FROM (
	SELECT ST_Reclass(
		ST_SetValue(
			ST_SetValue(
				ST_AddBand(
11
					ST_MakeEmptyRaster(10, 10, 10, 10, 2, 2, 0, 0, 0),
Bborie Park's avatar
Bborie Park committed
12 13 14 15 16 17 18
					1, '32BUI', 0, 0
				),
				1, 1, 499
			),
			10, 10, 12
		),
		ROW(1, '0-100:1-10, 101-500:11-150,501 - 10000: 151-254', '8BUI', 255)
19
	) AS rast  OFFSET 0
Bborie Park's avatar
Bborie Park committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
) AS t;
SELECT
	ST_Value(t.rast, 1, 1, 1),
	ST_Value(t.rast, 1, 10, 10),
	ST_Value(t.rast, 1, 2, 10),
	ST_BandNoDataValue(rast, 1),
	ST_Value(t.rast, 2, 1, 1),
	ST_Value(t.rast, 2, 10, 10),
	ST_Value(t.rast, 2, 2, 10),
	ST_BandNoDataValue(rast, 2)
FROM (
	SELECT ST_Reclass(
		ST_SetValue(
			ST_SetValue(
				ST_AddBand(
					ST_AddBand(
36
						ST_MakeEmptyRaster(10, 10, 10, 10, 2, 2, 0, 0, 0),
Bborie Park's avatar
Bborie Park committed
37 38 39 40 41 42 43 44 45
						1, '8BUI', 0, 1
					),
					2, '32BUI', 0, 0
				),
				2, 1, 1, 499
			),
			2, 10, 10, 12
		),
		ROW(2, '0-100:1-10, 101-500:11-150,501 - 10000: 151-254', '8BUI', 255)
46
	) AS rast   OFFSET 0
Bborie Park's avatar
Bborie Park committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
) AS t;
SELECT
	ST_Value(t.rast, 1, 1, 1),
	ST_Value(t.rast, 1, 10, 10),
	ST_Value(t.rast, 1, 2, 10),
	ST_BandNoDataValue(rast, 1),
	ST_Value(t.rast, 2, 1, 1),
	ST_Value(t.rast, 2, 10, 10),
	ST_Value(t.rast, 2, 2, 10),
	ST_BandNoDataValue(rast, 2)
FROM (
	SELECT ST_Reclass(
		ST_SetValue(
			ST_SetValue(
				ST_AddBand(
					ST_AddBand(
63
						ST_MakeEmptyRaster(10, 10, 10, 10, 2, 2, 0, 0, 0),
Bborie Park's avatar
Bborie Park committed
64 65 66 67 68 69 70 71 72 73
						1, '8BUI', 0, 1
					),
					2, '32BUI', 0, 0
				),
				2, 1, 1, 499
			),
			2, 10, 10, 12
		),
		ROW(1, '0:1', '8BUI', 255),
		ROW(2, '0-100:1-10, 101-500:11-150,501 - 10000: 151-254', '8BUI', 255)
74
	) AS rast   OFFSET 0
Bborie Park's avatar
Bborie Park committed
75 76 77 78 79 80 81 82 83 84
) AS t;
SELECT
	ST_Value(t.rast, 1, 1, 1),
	ST_Value(t.rast, 1, 10, 10),
	ST_BandNoDataValue(rast, 1)
FROM (
	SELECT ST_Reclass(
		ST_SetValue(
			ST_SetValue(
				ST_AddBand(
85
					ST_MakeEmptyRaster(10, 10, 10, 10, 2, 2, 0, 0, 0),
Bborie Park's avatar
Bborie Park committed
86 87 88 89 90 91 92
					1, '8BUI', 0, 0
				),
				1, 1, 1, 255
			),
			1, 10, 10, 0
		),
		ROW(1, '0-100]:200-255,(100-200]:100-200,(200-255]:0-100', '8BUI', NULL)
93
	) AS rast  OFFSET 0
Bborie Park's avatar
Bborie Park committed
94 95 96 97 98 99 100 101 102 103
) AS t;
SELECT
	ST_Value(t.rast, 1, 1, 1),
	ST_Value(t.rast, 1, 10, 10),
	ST_BandNoDataValue(rast, 1)
FROM (
	SELECT ST_Reclass(
		ST_SetValue(
			ST_SetValue(
				ST_AddBand(
104
					ST_MakeEmptyRaster(100, 100, 10, 10, 2, 2, 0, 0, 0),
Bborie Park's avatar
Bborie Park committed
105 106 107 108 109 110 111
					1, '32BF', 1, 0
				),
				1, 1, 1, 3.14159
			),
			1, 10, 10, 2.71828
		),
		ROW(1, '-10000--100]:1-50,(-100-1000]:50-150,(1000-10000]:150-254', '8BUI', 0)
112
	) AS rast  OFFSET 0
Bborie Park's avatar
Bborie Park committed
113
) AS t;
114 115 116 117 118 119 120 121 122
SELECT
	ST_Value(t.rast, 1, 1, 1),
	ST_Value(t.rast, 1, 10, 10),
	ST_BandNoDataValue(rast, 1)
FROM (
	SELECT ST_Reclass(
		ST_SetValue(
			ST_SetValue(
				ST_AddBand(
123
					ST_MakeEmptyRaster(100, 100, 10, 10, 2, 2, 0, 0, 0),
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
					1, '32BF', 1, 0
				),
				1, 1, 1, 3.14159
			),
			1, 10, 10, 2.71828
		),
		ROW(1, '-10000--100]:50-1,(-100-1000]:150-50,(1000-10000]:254-150', '8BUI', 0)
	) AS rast
) AS t;
SELECT
	ST_Value(t.rast, 1, 1, 1),
	ST_Value(t.rast, 1, 10, 10),
	ST_BandNoDataValue(rast, 1)
FROM (
	SELECT ST_Reclass(
		ST_SetValue(
			ST_SetValue(
				ST_AddBand(
142
					ST_MakeEmptyRaster(100, 100, 10, 10, 2, 2, 0, 0, 0),
143 144 145 146 147 148 149
					1, '32BF', 1, 0
				),
				1, 1, 1, 3.14159
			),
			1, 10, 10, 2.71828
		),
		ROW(1, 'a-100]:50-1,(-100-1000]:150-50,(1000-10000]:254-150', '8BUI', 0)
150
	) AS rast OFFSET 0
151 152 153 154 155 156 157 158 159 160
) AS t;
SELECT
	ST_Value(t.rast, 1, 1, 1),
	ST_Value(t.rast, 1, 10, 10),
	ST_BandNoDataValue(rast, 1)
FROM (
	SELECT ST_Reclass(
		ST_SetValue(
			ST_SetValue(
				ST_AddBand(
161
					ST_MakeEmptyRaster(100, 100, 10, 10, 2, 2, 0, 0, 0),
162 163 164 165 166 167 168
					1, '32BF', 1, 0
				),
				1, 1, 1, 3.14159
			),
			1, 10, 10, 2.71828
		),
		ROW(2, '-10000--100]:50-1,(-100-1000]:150-50,(1000-10000]:254-150', '8BUI', 0)
169
	) AS rast OFFSET 0
170
) AS t;
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194

-- ticket #2555
SELECT
	ST_Value(rast, 1, 2, 2),
	ST_Value(rast, 1, 3, 3),
	ST_Value(rast, 1, 4, 4)
FROM (
	SELECT ST_Reclass(
		ST_SetValues(
		 	ST_AddBand(
			 	ST_MakeEmptyRaster(5, 5, 10, 10, 2, 2, 0, 0, 0),
				1, '32BF', 1, -9999
			),
			1, 1, 1,
			ARRAY[
				[1, 1, 1, 1, 1],
				[1, 9000, 1, 1, 1],
				[1, 1, -9000, 1, 1],
				[1, 1, 1, 9000, 1],
				[1, 1, 1, 1, 1]
			]::double precision[]
		),

		1, '[-9000-9000]:[-900-900]', '32BF'
195
	) AS rast OFFSET 0
196
) AS t;