load_outdb-pre.pl 1.65 KB
Newer Older
1 2 3 4 5 6 7
use File::Basename;
use Cwd 'abs_path';

my $REGDIR = abs_path(dirname($0));
my $RASTERDIR = abs_path($REGDIR . "/../raster/test/regress");
my $FILERASTER = $RASTERDIR . "/loader/testraster.tif";

8 9 10 11 12 13 14
# special handling for msys
if (lc($^O) eq "msys") {
	$FILERASTER = `cmd //c echo "$FILERASTER"`;
	$FILERASTER =~ s/^\s+//;
	$FILERASTER =~ s/\s+$//;
}

15
my $sql = <<"END";
16 17 18 19
WITH foo AS (
	SELECT postgis_raster_lib_version()
)
SELECT NULL FROM foo;
20
SET postgis.gdal_enabled_drivers = 'GTiff';
21 22 23 24
DROP TABLE IF EXISTS raster_outdb_template;
CREATE TABLE raster_outdb_template AS
SELECT
	1 AS rid,
25
	ST_AddBand( -- insert all three bands of out-db raster at index 1
26
		ST_MakeEmptyRaster(90, 50, 0., 0., 1, -1, 0, 0, 0),
27 28 29 30 31
		1, '$FILERASTER'::text, NULL::int[]
	) AS rast
UNION ALL
SELECT
	2 AS rid,
32
	ST_AddBand( -- append all three bands of out-db raster
33
		ST_MakeEmptyRaster(90, 50, 0., 0., 1, -1, 0, 0, 0),
34 35 36 37 38
		'$FILERASTER'::text, NULL::int[]
	) AS rast
UNION ALL
SELECT
	3 AS rid,
39 40
	ST_AddBand( -- append out-db band 2
		ST_AddBand( -- in-db band
41
			ST_MakeEmptyRaster(90, 50, 0., 0., 1, -1, 0, 0, 0),
42 43 44 45 46 47 48
			1, '8BUI', 1, 0
		),
		'$FILERASTER'::text, ARRAY[2]::int[]
	) AS rast
UNION ALL
SELECT
	4 AS rid,
49 50
	ST_AddBand( -- append out-db band 2
		ST_AddBand( -- in-db band
51
			ST_MakeEmptyRaster(90, 50, 0., 0., 1, -1, 0, 0, 0),
52 53 54 55 56 57 58 59 60 61 62 63
			1, '8BUI', 1, 0
		),
		'$FILERASTER'::text, ARRAY[2]::int[],
		1,
		255
	) AS rast
END

open(PRESQL, '>', $RASTERDIR . '/' . $TEST . '-pre.sql');
print PRESQL $sql;
close(PRESQL);

64 65 66 67
# no longer needed as the "clean" test takes care of it
#open(POSTSQL, '>', $RASTERDIR . '/' . $TEST . '-post.sql');
#print POSTSQL "DROP TABLE IF EXISTS raster_outdb_template;\n";
#close(POSTSQL);