In practical implementations of density-functional theory, the only term where an orbital description is needed is the kinetic one. Even this term in principle depends on the density only, but its explicit form is unknown. We provide a novel solution of the N-representability problem for an extended system, which implies an explicit form for the Kohn-Sham kinetic energy in terms of the density. Our approach is based on a periodic coordinate mapping, uniquely defined by the Fourier coefficients of the metric. The density functional is thus expressed as an explicit functional of the metric tensor: since N-representability is enforced, our constructive recipe provides a variational approximation. Furthermore, we show that our geometric viewpoint is quite naturally related to the electron localization function (ELF), which provides a very informative analysis of the electron distribution. Studies of ELF, as obtained from accurate Kohn-Sham orbitals in real materials, allow an appraisal of the variational approximate density functional. We show that the value of an approximate functional-either the present geometric-based one or some previous ones based on different constructive recipes-strongly depends on the nature of the chemical bonding in the material.