Stochastic blockmodel approximation of a graphon: Theory and consistent estimation