rt_worldtorastercoord.sql 3.85 KB
Newer Older
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
CREATE TABLE raster_world2raster (
	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,
	initvalue double precision DEFAULT 1,
	nodataval 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', initvalue, nodataval);

		INSERT INTO raster_world2raster VALUES (rid, rast);

		RETURN;
	END;
	$$ LANGUAGE 'plpgsql';

-- no skew
SELECT make_test_raster(0, 4, 4, -2, -2);
SELECT make_test_raster(1, 2, 2, 0, 0, 0, 0, 2);
SELECT make_test_raster(2, 2, 2, 1, -1, 0, 0, 3);
SELECT make_test_raster(3, 2, 2, 1, 1, 0, 0, 4);
SELECT make_test_raster(4, 2, 2, 2, 2, 0, 0, 5);

-- skew
SELECT make_test_raster(10, 4, 4, -2, -2, 1, -1);
SELECT make_test_raster(11, 2, 2, 0, 0, 1, -1, 2);
SELECT make_test_raster(12, 2, 2, 1, -1, 1, -1, 3);
SELECT make_test_raster(13, 2, 2, 1, 1, 1, -1, 4);
SELECT make_test_raster(14, 2, 2, 2, 2, 1, -1, 5);

DROP FUNCTION make_test_raster(integer, integer, integer, double precision, double precision, double precision, double precision, double precision, double precision);

SELECT
	rid,
50
	(ST_WorldToRasterCoord(rast, -2, -2)).*
51 52 53
FROM raster_world2raster;
SELECT
	rid,
54
	(ST_WorldToRasterCoord(rast, 0, 0)).*
55 56 57
FROM raster_world2raster;
SELECT
	rid,
58
	(ST_WorldToRasterCoord(rast, 1, -1)).*
59 60 61
FROM raster_world2raster;
SELECT
	rid,
62
	(ST_WorldToRasterCoord(rast, 1, 1)).*
63 64 65
FROM raster_world2raster;
SELECT
	rid,
66
	(ST_WorldToRasterCoord(rast, 2, 2)).*
67 68
FROM raster_world2raster;

69 70
SELECT
	rid,
71
	(ST_WorldToRasterCoord(rast, ST_MakePoint(-2, -2))).*
72 73 74
FROM raster_world2raster;
SELECT
	rid,
75
	(ST_WorldToRasterCoord(rast, ST_MakePoint(0, 0))).*
76 77 78
FROM raster_world2raster;
SELECT
	rid,
79
	(ST_WorldToRasterCoord(rast, ST_MakePoint(1, -1))).*
80 81 82
FROM raster_world2raster;
SELECT
	rid,
83
	(ST_WorldToRasterCoord(rast, ST_MakePoint(1, 1))).*
84 85 86
FROM raster_world2raster;
SELECT
	rid,
87
	(ST_WorldToRasterCoord(rast, ST_MakePoint(2, 2))).*
88 89 90 91
FROM raster_world2raster;

SELECT
	rid,
92
	ST_WorldToRasterCoordX(rast, -2, -2)
93 94 95
FROM raster_world2raster;
SELECT
	rid,
96
	ST_WorldToRasterCoordX(rast, 0, 0)
97 98 99
FROM raster_world2raster;
SELECT
	rid,
100
	ST_WorldToRasterCoordX(rast, 1, -1)
101 102 103
FROM raster_world2raster;
SELECT
	rid,
104
	ST_WorldToRasterCoordX(rast, 1, 1)
105 106 107
FROM raster_world2raster;
SELECT
	rid,
108
	ST_WorldToRasterCoordX(rast, 2, 2)
109 110 111 112
FROM raster_world2raster;

SELECT
	rid,
113
	ST_WorldToRasterCoordX(rast, ST_MakePoint(-2, -2))
114 115 116 117
FROM raster_world2raster;

SELECT
	rid,
118
	ST_WorldToRasterCoordX(rast, -2)
119 120 121
FROM raster_world2raster;
SELECT
	rid,
122
	ST_WorldToRasterCoordX(rast, 0)
123 124 125
FROM raster_world2raster;
SELECT
	rid,
126
	ST_WorldToRasterCoordX(rast, 1)
127 128 129
FROM raster_world2raster;
SELECT
	rid,
130
	ST_WorldToRasterCoordX(rast, 1)
131 132 133
FROM raster_world2raster;
SELECT
	rid,
134
	ST_WorldToRasterCoordX(rast, 2)
135 136 137 138
FROM raster_world2raster;

SELECT
	rid,
139
	ST_WorldToRasterCoordY(rast, -2, -2)
140 141 142
FROM raster_world2raster;
SELECT
	rid,
143
	ST_WorldToRasterCoordY(rast, 0, 0)
144 145 146
FROM raster_world2raster;
SELECT
	rid,
147
	ST_WorldToRasterCoordY(rast, 1, -1)
148 149 150
FROM raster_world2raster;
SELECT
	rid,
151
	ST_WorldToRasterCoordY(rast, 1, 1)
152 153 154
FROM raster_world2raster;
SELECT
	rid,
155
	ST_WorldToRasterCoordY(rast, 2, 2)
156 157 158 159
FROM raster_world2raster;

SELECT
	rid,
160
	ST_WorldToRasterCoordX(rast, ST_MakePoint(-2, -2))
161 162 163 164
FROM raster_world2raster;

SELECT
	rid,
165
	ST_WorldToRasterCoordY(rast, -2)
166 167 168
FROM raster_world2raster;
SELECT
	rid,
169
	ST_WorldToRasterCoordY(rast, 0)
170 171 172
FROM raster_world2raster;
SELECT
	rid,
173
	ST_WorldToRasterCoordY(rast, 1)
174 175 176
FROM raster_world2raster;
SELECT
	rid,
177
	ST_WorldToRasterCoordY(rast, 1)
178 179 180
FROM raster_world2raster;
SELECT
	rid,
181
	ST_WorldToRasterCoordY(rast, 2)
182 183
FROM raster_world2raster;

184
DROP TABLE raster_world2raster;