Using a first-principles approach, we investigate the origin of the fine structure in Si 2p photoelectron spectra at the Si(100)-(2x1) surface and at the Si(100)-SiO2 interface. Calculated and measured shifts show very good agreement for both systems. By using maximally localized Wannier functions, we clearly identify the shifts resulting from the electronegativity of second-neighbor atoms. The other shifts are then found to be proportional to the average bond-length variation around the Si atom. Hence, in combination with accurate modeling, photoelectron spectroscopy can provide a direct measure of the strain field at the atomic scale.