It is shown that the Cuntz semigroup of a space with dimension at most two, and with second cohomology of its compact subsets equal to zero, is isomorphic to the ordered semigroup of lower semicontinuous functions on the space with values in the natural numbers with the infinity adjoined. This computation is then used to obtain the Cuntz semigroup of all compact surfaces. A converse to the first computation is also proven: if the Cuntz semigroup of a separable C*-algebra is isomorphic to the lower semicontinuous functions on a topological space with values in the extended natural numbers, then the C*-algebra is commutative up to stability, and its spectrum satisfies the dimensional and cohomological conditions mentioned above.