How to render a shadow without the object in the scene
If your computer is unable to render an image (insufficient RAM?) with the train included then it will most likely have the same issue if you try to use it to render the shadows. You may want to render the entire image on another computer that can cope with the entire scene in one go.

One thing that can work is to create a low poly mesh for the train, a simple outline of the shape that will cast a visually matching shadow. By rendering the background with the low poly train you can get the ground with shadows and then later composite the train over the top.

Using cycles you can have an object cast shadows and not be visible to the camera by setting the Ray Visibility options, found under object properties. By turning off camera the object will not be visible to the camera but it will still cast shadows and reflections on other objects. If you want to merge this into your materials you can add a Light Path node.



For blender internal the material settings have a similar option called cast only under shadow options.



Edit: In a cycles material you can use the light path node to control the mix amount to get an object that is transparent to the camera but still casts shadows.



The advantage of using a material is that you can alter the shadows. By using a translucent or glass node instead of diffuse you get softer shadows and the ability to add a colour tint. You may also want to use the original object material so that reflections also look correct.