Scheme for calculating the electronic structure of polar surfaces