This paper addresses the problem of minimizing the energy consumption of data gathering from a set of Internet-of-things (IoT) devices using an unmanned aerial vehicle (UAV). The spatial correlation among the data of the IoT devices is considered. A framework is provided, in which a subset of devices are selected to contribute, and the optimal path that the UAV should follow, along with the aggregation points at which the UAV stops and aggregates the data in an energy-efficient fashion is also considered. In this framework, an optimization problem is formulated to minimize the energy expenditure of the IoT devices and UAV while the latter tours to aggregate the required information from the former. A solution based on a greedy algorithm is provided, in which the optimization problem is decomposed into two complementary sub-problems. The first sub-problem selects the contributing devices using a genetic algorithm. The second sub-problem optimizes the locations of the data aggregation points and assigns the active devices to each aggregation point. Simulation results show that the proposed framework can save significant energy.