TLDR; a few years ago vegetables grown naturally and then transported by truck over a distance of 1000-1500 km had a lower carbon footprint than vegetables grown locally in heated greenhouses. However due to technical innovations things have changed and the footprint is now equal. Expectations are that in a few years heated greenhouses will have a neutral carbon footprint.
Generally speaking, the production phase of a food makes up the larger part of it's total environmental impact. According to this published Carnegie Mellon University study from 2008
GHG emissions associated with food are dominated by the production phase, contributing 83% of the average U.S.
household’s 8.1 t CO 2 e/yr footprint for food consumption. Transportation as a whole represents only 11% of life-cycle
GHG emissions, and final delivery from producer to retail contributes only 4%
I'm not sure if similar results also apply to both tomato-scenarios you describe. It probably depends on the exact geographical location, the time of year and the technology used for growing the tomatoes. Nevertheless a while back on a Dutch television program they asked and answered a similar question for 2 types of vegetables. The question was which would be more sustainable in the winter; fresh endive grown locally in a greenhouse, or grown in the ground in Spain (about 1300km from here) and then transport it by truck. According to research they had done the answer was that the endive grown in Spain had a lower CO2 footprint because the local greenhouse requires lots of gas for heating.
However, the same television show also mentioned that fresh green beans which are transported by plane (from Kenia) have a far higher CO2 footprint than the ones transported by boat and/or truck (from Senegal, Marocco or Spain), so the type of transport does make a difference when all else is equal.
Locally grown vegetables that are grown in the summertime, when you don't need a greenhouse, have the lowest CO2 footprint.
For Dutch speakers, here is the fragment about endive and the one about green beans
UPDATE June 2016: Now a few years later, the same television show did an update and again investigated the footprint, this time of tomatoes grown locally in heated greenhouses in The Netherlands versus tomatoes grown outside in Spain or Morocco and then transported by truck to The Netherlands. Due to technical innovations in greenhouses, the carbon footprint is now more or less equal. Dutch greenhouse owners are trying to make their greenhouses CO2-neutral by 2020. Here's the tv fragment (in Dutch).