It's interesting to see partitioning of GiST tree. Using gevel contrib module it's easy task.
createdb rtree psql rtree < rtree.sql psql rtree < gevel.sql
create table cities (id int4, b box); \copy cities from 'cities_mbr.copy' with delimiter as '|'
rtree=# \d bix Index "public.bix" Column | Type --------+------ b | box gist, for table "public.cities"
rtree=# select gist_stat('bix');
Number of levels: 2
Number of pages: 64
Number of leaf pages: 63
Number of tuples: 6782
Number of leaf tuples: 6719
Total size of tuples: 298408 bytes
Total size of leaf tuples: 295636 bytes
Total size of index: 524288 bytes
\pset tuples_only
\o cities-l-1.leaf
select * from gist_print('bix') as t(level int, a box) where level =1;
similarly, for level 2 (leaf).
use GD;
my $DX = 600;
my $DY = 600;
$im = new GD::Image($DX,$DY);
$black = $im->colorAllocate(0,0,0);
$white = $im->colorAllocate(255,255,255);
$im->transparent($white);
$im->interlaced('true');
$xmin = 104063.96875;
$xmax = 1007864.0;
$dx = ($xmax - $xmin)/$DX;
$ymin = 3850990;
$ymax = 4623849.0;
$dy = ($ymax - $ymin)/$DY;
binmode STDOUT;
while (<>) {
chomp;
@a = split(/\s+/);
$a[0] = ($a[0]-$xmin)/$dx;
$a[2] = ($a[2]-$xmin)/$dx;
$a[1] = ($a[1]-$ymin)/$dy;
$a[3] = ($a[3]-$ymin)/$dy;
$im->rectangle(@a,$white);
}
print $im->gif;
Final pictures:
Please, note, described script is just a sketch and better scripts are welcome !