private TileMatrix buildTileMatrix( SpatialMetadata envelopeAndCrs, Band overview ) {
int tw = overview.GetBlockXSize();
int th = overview.GetBlockYSize();
int width = overview.getXSize();
int height = overview.getYSize();
int numx = (int) Math.ceil( (double) width / (double) tw );
int numy = (int) Math.ceil( (double) height / (double) th );
Envelope env = envelopeAndCrs.getEnvelope();
double res = Math.max( env.getSpan0() / width, env.getSpan1() / height );
String id = Double.toString( res / DEFAULT_PIXEL_SIZE );
return new TileMatrix( id, envelopeAndCrs, BigInteger.valueOf( tw ), BigInteger.valueOf( th ), res,
BigInteger.valueOf( numx ), BigInteger.valueOf( numy ) );
}
}