1-----------------------------------------------------------------------
2--
3-- Copyright (c) 2010 Pierre Racine <pierre.racine@sbf.ulaval.ca>
4--
5-- This program is free software; you can redistribute it and/or
6-- modify it under the terms of the GNU General Public License
7-- as published by the Free Software Foundation; either version 2
8-- of the License, or (at your option) any later version.
9--
10-- This program is distributed in the hope that it will be useful,
11-- but WITHOUT ANY WARRANTY; without even the implied warranty of
12-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13-- GNU General Public License for more details.
14--
15-- You should have received a copy of the GNU General Public License
16-- along with this program; if not, write to the Free Software Foundation,
17-- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18-----------------------------------------------------------------------
19
20CREATE TABLE rt_utility_test (
21    id numeric,
22    name text,
23    srid integer,
24    width integer,
25    height integer,
26    scalex double precision,
27    scaley double precision,
28    ipx double precision,
29    ipy double precision,
30    skewx double precision,
31    skewy double precision,
32    rast raster
33);
34
35INSERT INTO rt_utility_test
36VALUES ( 1, '1217x1156, ip:782325.5,26744042.5 scale:5,-5 skew:0,0 srid:9102707 width:1217 height:1156',
37        26919, 1217, 1156, --- SRID, width, height
38        5, -5, 782325.5, 26744042.5, 0, 0, --- georeference
39(
40'01' -- little endian (uint8 ndr)
41||
42'0000' -- version (uint16 0)
43||
44'0000' -- nBands (uint16 0)
45||
46'0000000000001440' -- scaleX (float64 5)
47||
48'00000000000014C0' -- scaleY (float64 -5)
49||
50'00000000EBDF2741' -- ipX (float64 782325.5)
51||
52'000000A84E817941' -- ipY (float64 26744042.5)
53||
54'0000000000000000' -- skewX (float64 0)
55||
56'0000000000000000' -- skewY (float64 0)
57||
58'27690000' -- SRID (int32 26919 - UTM 19N)
59||
60'C104' -- width (uint16 1217)
61||
62'8404' -- height (uint16 1156)
63)::raster
64);
65
66INSERT INTO rt_utility_test
67VALUES ( 2, '1217x1156, ip:782325.5,26744042.5 scale:5,-5 skew:3,3 srid:9102707 width:1217 height:1156',
68        26919, 1217, 1156, --- SRID, width, height
69        5, -5, 782325.5, 26744042.5, 3, 3, --- georeference
70(
71'01' -- little endian (uint8 ndr)
72||
73'0000' -- version (uint16 0)
74||
75'0000' -- nBands (uint16 0)
76||
77'0000000000001440' -- scaleX (float64 5)
78||
79'00000000000014C0' -- scaleY (float64 -5)
80||
81'00000000EBDF2741' -- ipX (float64 782325.5)
82||
83'000000A84E817941' -- ipY (float64 26744042.5)
84||
85'0000000000000840' -- skewX (float64 3)
86||
87'0000000000000840' -- skewY (float64 3)
88||
89'27690000' -- SRID (int32 26919 - UTM 19N)
90||
91'C104' -- width (uint16 1217)
92||
93'8404' -- height (uint16 1156)
94)::raster
95);
96
97INSERT INTO rt_utility_test
98VALUES ( 3, '6000x6000, ip:-75,50 scale:0.000833333333333333,-0.000833333333333333 skew:0,0 srid:4326 width:6000 height:6000',
99        4326, 6000, 6000, --- SRID, width, height
100        0.000833333333333333, -0.000833333333333333, -75, 50, 0, 0, --- georeference
101(
102'01' -- little endian (uint8 ndr)
103||
104'0000' -- version (uint16 0)
105||
106'0000' -- nBands (uint16 0)
107||
108'4F1BE8B4814E4B3F' -- scaleX (float64 0.000833333333333333)
109||
110'4F1BE8B4814E4BBF' -- scaleY (float64 -0.000833333333333333)
111||
112'0000000000C052C0' -- ipX (float64 -75)
113||
114'0000000000004940' -- ipY (float64 50)
115||
116'0000000000000000' -- skewX (float64 0)
117||
118'0000000000000000' -- skewY (float64 0)
119||
120'E6100000' -- SRID (int32 4326)
121||
122'7017' -- width (uint16 6000)
123||
124'7017' -- height (uint16 6000)
125)::raster
126);
127
128INSERT INTO rt_utility_test
129VALUES ( 4, '6000x6000, ip:-75.5533328537098,49.2824585505576 scale:0.000805965234044584,-0.00080596523404458 skew:0.000211812383858707,0.000211812383858704 srid:4326 width:6000 height:6000',
130        4326, 6000, 6000, --- SRID, width, height
131        0.000805965234044584, -0.00080596523404458, -75.5533328537098, 49.2824585505576, 0.000211812383858707, 0.000211812383858704, --- georeference
132(
133'01' -- little endian (uint8 ndr)
134||
135'0000' -- version (uint16 0)
136||
137'0000' -- nBands (uint16 0)
138||
139'17263529ED684A3F' -- scaleX (float64 0.000805965234044584)
140||
141'F9253529ED684ABF' -- scaleY (float64 -0.00080596523404458)
142||
143'1C9F33CE69E352C0' -- ipX (float64 -75.5533328537098)
144||
145'718F0E9A27A44840' -- ipY (float64 49.2824585505576)
146||
147'ED50EB853EC32B3F' -- skewX (float64 0.000211812383858707)
148||
149'7550EB853EC32B3F' -- skewY (float64 0.000211812383858704)
150||
151'E6100000' -- SRID (int32 4326)
152||
153'7017' -- width (uint16 6000)
154||
155'7017' -- height (uint16 6000)
156)::raster
157);
158
159-----------------------------------------------------------------------
160-- Test 1 - ST_WorldTorastercoordx(rast raster, xw float8, yw float8)
161-----------------------------------------------------------------------
162
163SELECT 'test 1.1', id, name
164    FROM rt_utility_test
165    WHERE COALESCE(ST_WorldTorastercoordx(rast,
166                                ipx,
167                                ipy
168                               ), 0) != 1;
169
170SELECT 'test 1.2', id, name
171    FROM rt_utility_test
172    WHERE COALESCE(ST_WorldTorastercoordx(rast,
173                                scalex * (width - 1) + skewx * (height - 1) + ipx,
174                                skewy * (width - 1) + scaley * (height - 1) + ipy
175                               ), 0) != width;
176
177SELECT 'test 1.3', id, name
178    FROM rt_utility_test
179    WHERE COALESCE(ST_WorldTorastercoordx(rast,
180                                scalex * width + skewx * height + ipx,
181                                skewy * width + scaley * height + ipy
182                               ), 0) != width + 1;
183
184-----------------------------------------------------------------------
185-- Test 2 - ST_WorldTorastercoordx(rast raster, xw float8)
186-----------------------------------------------------------------------
187
188SELECT 'test 2.1', id, name
189    FROM rt_utility_test
190    WHERE skewx = 0 and
191          COALESCE(ST_WorldTorastercoordx(rast,
192                                ipx
193                               ), 0) != 1;
194
195SELECT 'test 2.2', id, name
196    FROM rt_utility_test
197    WHERE skewx = 0 and
198          COALESCE(ST_WorldTorastercoordx(rast,
199                                scalex * (width - 1) + ipx
200                               ), 0) != width;
201
202SELECT 'test 2.3', id, name
203    FROM rt_utility_test
204    WHERE skewx = 0 and
205          COALESCE(ST_WorldTorastercoordx(rast,
206                                scalex * width + ipx
207                               ), 0) != width + 1;
208
209SELECT 'test 2.4', id, name
210    FROM rt_utility_test
211    WHERE COALESCE(ST_WorldTorastercoordx(rast,
212                                ipx
213                               ), 0) != 1;
214
215-----------------------------------------------------------------------
216-- Test 3 - ST_WorldTorastercoordx(rast raster, pt geometry)
217-----------------------------------------------------------------------
218
219SELECT 'test 3.1', id, name
220    FROM rt_utility_test
221    WHERE COALESCE(ST_WorldTorastercoordx(rast,
222                                st_makepoint(
223                                             ipx,
224                                             ipy
225                                            )
226                               ), 0) != 1;
227
228SELECT 'test 3.2', id, name
229    FROM rt_utility_test
230    WHERE COALESCE(ST_WorldTorastercoordx(rast,
231                                st_makepoint(
232                                             scalex * (width - 1) + skewx * (height - 1) + ipx,
233                                             skewy * (width - 1) + scaley * (height - 1) + ipy
234                                            )
235                               ), 0) != width;
236
237SELECT 'test 3.3', id, name
238    FROM rt_utility_test
239    WHERE COALESCE(ST_WorldTorastercoordx(rast,
240                                st_makepoint(
241                                             scalex * width + skewx * height + ipx,
242                                             skewy * width + scaley * height + ipy
243                                            )
244                               ), 0) != width + 1;
245
246-----------------------------------------------------------------------
247-- Test 4 - ST_WorldTorastercoordy(rast raster, xw float8, yw float8)
248-----------------------------------------------------------------------
249
250SELECT 'test 4.1', id, name
251    FROM rt_utility_test
252    WHERE COALESCE(ST_WorldTorastercoordy(rast,
253                                ipx,
254                                ipy
255                               ), 0) != 1;
256
257SELECT 'test 4.2', id, name
258    FROM rt_utility_test
259    WHERE COALESCE(ST_WorldTorastercoordy(rast,
260                                scalex * (width - 1) + skewx * (height - 1) + ipx,
261                                skewy * (width - 1) + scaley * (height - 1) + ipy
262                               ), 0) != height;
263
264SELECT 'test 4.3', id, name
265    FROM rt_utility_test
266    WHERE COALESCE(ST_WorldTorastercoordy(rast,
267                                scalex * width + skewx * height + ipx,
268                                skewy * width + scaley * height + ipy
269                               ), 0) != height + 1;
270
271-----------------------------------------------------------------------
272-- Test 5 - ST_WorldTorastercoordy(rast raster, yw float8)
273-----------------------------------------------------------------------
274
275SELECT 'test 5.1', id, name
276    FROM rt_utility_test
277    WHERE skewy = 0 and
278          COALESCE(ST_WorldTorastercoordy(rast,
279                                ipy
280                               ), 0) != 1;
281
282SELECT 'test 5.2', id, name
283    FROM rt_utility_test
284    WHERE skewy = 0 and
285          COALESCE(ST_WorldTorastercoordy(rast,
286                                scaley * (height - 1) + ipy
287                               ), 0) != height;
288
289SELECT 'test 5.3', id, name
290    FROM rt_utility_test
291    WHERE skewy = 0 and
292          COALESCE(ST_WorldTorastercoordy(rast,
293                                scaley * height + ipy
294                               ), 0) != height + 1;
295
296SELECT 'test 5.4', id, name
297    FROM rt_utility_test
298    WHERE COALESCE(ST_WorldTorastercoordy(rast,
299                                ipy
300                               ), 0) != 1;
301
302-----------------------------------------------------------------------
303-- Test 6 - ST_WorldTorastercoordy(rast raster, pt geometry)
304-----------------------------------------------------------------------
305
306SELECT 'test 6.1', id, name
307    FROM rt_utility_test
308    WHERE COALESCE(ST_WorldTorastercoordy(rast,
309                                st_makepoint(
310                                             ipx,
311                                             ipy
312                                            )
313                               ), 0) != 1;
314
315SELECT 'test 6.2', id, name
316    FROM rt_utility_test
317    WHERE COALESCE(ST_WorldTorastercoordy(rast,
318                                st_makepoint(
319                                             scalex * (width - 1) + skewx * (height - 1) + ipx,
320                                             skewy * (width - 1) + scaley * (height - 1) + ipy
321                                            )
322                               ), 0) != height;
323
324SELECT 'test 6.3', id, name
325    FROM rt_utility_test
326    WHERE COALESCE(ST_WorldTorastercoordy(rast,
327                                st_makepoint(
328                                             scalex * width + skewx * height + ipx,
329                                             skewy * width + scaley * height + ipy
330                                            )
331                               ), 0) != height + 1;
332
333-----------------------------------------------------------------------
334-- Test 7 - ST_RasterToworldcoordx(rast raster, xr int, yr int)
335-----------------------------------------------------------------------
336
337SELECT 'test 7.1', id, name
338    FROM rt_utility_test
339    WHERE COALESCE(ST_RasterToworldcoordx(rast, 1, 1), 0)::numeric != ipx::numeric;
340
341SELECT 'test 7.2', id, name
342    FROM rt_utility_test
343    WHERE COALESCE(ST_RasterToworldcoordx(rast, width, height), 0)::numeric != (scalex * (width - 1) + skewx * (height - 1) + ipx)::numeric;
344
345-----------------------------------------------------------------------
346-- Test 8 - ST_RasterToworldcoordx(rast raster, xr int)
347-----------------------------------------------------------------------
348
349SELECT 'test 8.1', id, name
350    FROM rt_utility_test
351    WHERE skewx = 0 and COALESCE(ST_RasterToworldcoordx(rast, 1), 0)::numeric != ipx::numeric;
352
353SELECT 'test 8.2', id, name
354    FROM rt_utility_test
355    WHERE skewx = 0 and COALESCE(ST_RasterToworldcoordx(rast, width), 0)::numeric != (scalex * (width - 1) + ipx)::numeric;
356
357SELECT 'test 8.3', id, name
358    FROM rt_utility_test
359    WHERE COALESCE(ST_RasterToworldcoordx(rast, 1), 0)::numeric != ipx::numeric;
360
361-----------------------------------------------------------------------
362-- Test 9 - ST_RasterToworldcoordy(rast raster, xr int, yr int)
363-----------------------------------------------------------------------
364
365SELECT 'test 9.1', id, name
366    FROM rt_utility_test
367    WHERE COALESCE(ST_RasterToworldcoordy(rast, 1, 1), 0)::numeric != ipy::numeric;
368
369SELECT 'test 9.2', id, name
370    FROM rt_utility_test
371    WHERE round(COALESCE(ST_RasterToworldcoordy(rast, width, height), 0)::numeric, 10) != round((skewy * (width - 1) + scaley * (height - 1) + ipy)::numeric, 10);
372
373-----------------------------------------------------------------------
374-- Test 10 - ST_RasterToworldcoordy(rast raster, yr int)
375-----------------------------------------------------------------------
376
377SELECT 'test 10.1', id, name
378    FROM rt_utility_test
379    WHERE skewy = 0 and COALESCE(ST_RasterToworldcoordy(rast, 1, 1), 0)::numeric != ipy::numeric;
380
381SELECT 'test 10.2', id, name
382    FROM rt_utility_test
383    WHERE skewy = 0 and COALESCE(ST_RasterToworldcoordy(rast, width, height), 0)::numeric != (scaley * (height - 1) + ipy)::numeric;
384
385SELECT 'test 10.3', id, name
386    FROM rt_utility_test
387    WHERE COALESCE(ST_RasterToworldcoordy(rast, 1), 0)::numeric != ipy::numeric;
388
389-----------------------------------------------------------------------
390-- Test 11 - st_minpossiblevalue(pixtype text)
391-----------------------------------------------------------------------
392
393SELECT 'test 11.1', st_minpossiblevalue('1BB') = 0.;
394SELECT 'test 11.2', st_minpossiblevalue('2BUI') = 0.;
395SELECT 'test 11.3', st_minpossiblevalue('4BUI') = 0.;
396SELECT 'test 11.4', st_minpossiblevalue('8BUI') = 0.;
397SELECT 'test 11.5', st_minpossiblevalue('8BSI') < 0.;
398SELECT 'test 11.6', st_minpossiblevalue('16BUI') = 0.;
399SELECT 'test 11.7', st_minpossiblevalue('16BSI') < 0.;
400SELECT 'test 11.8', st_minpossiblevalue('32BUI') = 0.;
401SELECT 'test 11.9', st_minpossiblevalue('32BSI') < 0.;
402SELECT 'test 11.10', st_minpossiblevalue('32BF') < 0.;
403SELECT 'test 11.11', st_minpossiblevalue('64BF') < 0.;
404SELECT '#4918', ST_MinPossibleValue('');
405
406DROP TABLE rt_utility_test;
407
408-----------------------------------------------------------------------
409-- st_summary()
410-----------------------------------------------------------------------
411
412SELECT ST_Summary(
413	ST_AddBand(
414		ST_AddBand(
415			ST_AddBand(
416				ST_MakeEmptyRaster(10, 10, 0, 0, 1, -1, 0, 0, 0)
417				, 1, '8BUI', 1, 0
418			)
419			, 2, '32BF', 0, -9999
420		)
421		, 3, '16BSI', 0, NULL
422	)
423);
424SELECT ST_Summary(
425	ST_AddBand(
426		ST_MakeEmptyRaster(10, 10, 0, 0, 1, -1, 0, 0.00001, 0)
427		, 1, '8BUI', 1, 0
428	)
429);
430SELECT
431	rid,
432	ST_Summary(rast)
433FROM raster_outdb_template
434ORDER BY rid;
435
436-----------------------------------------------------------------------
437-- st_memsize()
438-----------------------------------------------------------------------
439
440SELECT 'ms1', ST_MemSize(ST_MakeEmptyRaster(10, 10, 0, 0, 1, -1, 0, 0, 0));
441
442-----------------------------------------------------------------------
443-- st_bandpath()
444-----------------------------------------------------------------------
445
446SELECT 'bandpath1', right(ST_BandPath(ST_MakeEmptyRaster(10, 10, 0, 0, 1, -1, 0, 0, 0)), 14);
447SELECT 'bandpath2', right(ST_BandPath(rast), 14) from raster_outdb_template order by rid;
448