Transportation and distribution networks are a class of spatial networks that have been of interest in recent years. These networks are often characterized by the presence of complex structures such as central loops paired with peripheral branches, which can appear both in natural and manmade systems, such as subway and railway networks. In this study, we investigate the conditions for the emergence of these nontrivial topological structures in the context of human transportation in cities. We propose a simple model for spatial networks generation, where a network lattice acts as a planar substrate and edge speeds define an effective temporal distance which we aim to optimize and quantifies the efficiency in exploring the urban space. Complex network topologies can be recovered from the optimization of edges’ speeds and we study how the interplay between a flow probability between two nodes in space and the associated travel cost influences the resulting optimal network. In the perspective of urban transportation we simulate these flows by means of human mobility models to obtain origin-destination matrices. We find that when using simple lattices, the obtained optimal topologies transition from treelike structures to more regular networks, depending on the spatial range of flows. Remarkably, we find that branches paired to large loops structures appear as optimal structures when the network is optimized for an interplay between heterogeneous mobility patterns of small range travels and longer-range ones typical of commuting. Moreover, when congestion dynamics in traffic routing is considered, we study the emergence of additional edges from the tree structure to mitigate temporal delays. Finally, we show that our framework is able to recover the statistical spatial properties of the Greater London area subway network. Published by the American Physical Society 2024