You could certainly do that. By that measure San Francisco is actually denser than New York at 6,266 per square mile versus 5,319 per square mile (and 3,524 for Chicago). L.A. wins it all at 6,999 per square mile. Which really puts a hole in the arguments that the Bay Area and L.A. are not dense enough for commuter rail.
It depends on what you're trying to measure, really. If you're talking about space constraints driving up housing prices in the core city, I think it's useful to look at density in the core city and whether it could be higher to create more supply.
Surely these utterly fall apart (perhaps that is what you meant to begin with) when considering actual usage rather than arbitrary geographical boundaries.
Oakland is very much not the geographical equivalent of Brooklyn (you might be able to make some sort of argument for the Bronx or Staten Island). San Francisco is not more densely populated than Manhattan, neither is, by a long stretch LA.
It depends on what you're trying to measure, really. If you're talking about space constraints driving up housing prices in the core city, I think it's useful to look at density in the core city and whether it could be higher to create more supply.