Latham was 156* with Kane Williamson on 32 as New Zealand went to tea at 326/1.
At lunch, New Zealand were 197 without loss with Raval on 109 and Tom Latham on 83.
A five-wicket haul to Wagner ripped through Bangladesh to dismiss them for 234.
With the exception of Wellington batting all-rounder Rachin Ravindra, players participating in the Burger King Super Smash were not considered for selection in order to avoid compromising the integrity of the competition.
Latham and Nicholls put on 214 for the fourth wicket with Latham achieving his eighth century and Nicholls his fourth.
Sri Lanka's hopes of taking the series-deciding Test were severely dented in a 15-ball masterclass of swing bowling from Boult when he took six wickets for four runs
A sublime 6-wicket haul by Boult and 50s from Latham and Raval gave NZ a vice-like grip on the 2nd Test vs SL
With Raval on 72 and Latham on 40, New Zealand are 191 runs ahead at tea.
Southee claimed 6/68 as Sri Lanka were bowled out for 282 on the second morning in Wellington.
Sohail knocked a snail-paced 147 in nine hours and 34 minutes while Azam made an unbeaten 127.