A 2.5D analysis is presented of the vibration reduction of buildings alongside the railway by open or infilled trenches. Assuming the soil-structure system to be uniform along the railway direction, the 2D profile is used for obtaining the 3D response of the system by the 2.5D approach. Unlike most previous studies, the effect of self oscillation frequencies of the train due to wheel-rail interaction associated with rail irregularity is duly taken into account, in addition to the train and trench parameters. Focus is placed on the difference between the 2D and 2.5D results and on the mechanism of isolation of for the building. Contrary to the 2D analysis, the 2.5D response for the floor is found to be higher than the ceiling, implying that the wave transmission effect along the railway direction is greater than the amplification effect of the building structure. In addition, the 2.5D results are generally smaller than the 2D ones due to confinement of energy on the 2D plane. Both open and in-filled trenches are good for reducing building vibrations induced by trains, especially by those with higher self-oscillation frequencies when moving over irregular railways.