Noncommutative geometry on trees and buildings