Public transportation is a vital means to alleviate urban congestion. Despite substantial investments in public transit infrastructure in China, the development of urban public transportation has been unsatisfactory, with many city residents still favoring car travel. The extensive use of personal vehicles occupies limited road resources, thus exacerbating traffic congestion and environmental pollution. The built environment extensively influences residents' travel choices. Existing studies often describe the characteristics of the built environment from the perspective of the origin, destination, and public transit stops, lacking attention to the out-of-vehicle segments before and after using public transit; moreover, they mainly focus on the built environment faced by transit riders, without fully considering the alternative transit chains for car travelers. Accordingly, this study adopts a trip chain perspective. Combining resident travel surveys and streetscape data from the main urban area of Wuhan, and simulating travel paths using Baidu Maps, this study uses a random forest model to comprehensively analyze the impact of the built environment at the origin, destination, and out-of-vehicle segments on the choice between public transit and private vehicle. The results indicate the following: (1) The performance of the random forest model is superior to that of the traditional Logistic model, and it can reveal the nonlinear relationship between the built environment and travel behavior. At the same time, considering the out-of-vehicle environment also better understands the competitive environment between public transit and private vehicle, thereby improving the model's predictive ability. (2) the built environment is the main factor influencing the preference for public transit, and the out-of-vehicle environment's influence on travelers is no less than that of the built environment at the origin and destination. The preference for transit and built environment factors exhibit a nonlinear relationship, with some factors having different impacts at the origin and destination. Specifically, the population density, intersection density, and transit stop density at the origin and destination have very similar effects on the preference for transit, while the land use mix and job density differ. The proportion of roads and fences in the out-of-vehicle environment show a clear threshold effect, while the proportion of sidewalks and visible green index exhibit a saturation effect. (3) The mechanisms by which the built environment influences the choice of public transit and private vehicle can be summarized into three categories: elastic adjustment, limited support, and direct drive. These findings reveal the effective range of built environment factors in enhancing the attractiveness of transit, providing more rational and precise targeting for policy-making. This study addresses the issue of insufficient detail in the built environment in current research, incorporating the out-of-vehicle environment and alternative modes of travel into the analysis framework of transit preference, providing more intervenable built environment factors to enhance the attractiveness of transit, and offering insights for integrating nonlinear impact relationships into urban planning practice.