A wide-area sensor system is a complex, dynamic, resource-rich cloud of Internet-connected sensing devices. In this paper, we propose X-Tree Programming, a novel database-centric programming model for wide-area sensor systems designed to achieve the seemingly conflicting goals of expressiveness, ease of programming, and efficient distributed execution. To demonstrate the effectiveness of X-Tree Programming in achieving these goals, we have incorporated the model into IrisNet, a shared infrastructure for wide-area sensing, and developed three widely different applications, including a distributed infrastructure monitor running on 473 machines worldwide.