Inland waterways, characterized by their complex, narrow paths, see significantly higher traffic volumes compared to maritime routes, increasing the regulatory demands on traffic management. Predictive modeling of ship traffic flows, utilizing real AIS historical data, enhances route and docking planning for ships and port managers. This approach boosts transportation efficiency and safety in inland waterway navigation. Nevertheless, AIS data are flawed, marred by noise, disjointed paths, anomalies, and inconsistent timing between points. This study introduces a data processing technique to refine AIS data, encompassing segmentation, outlier elimination, missing point interpolation, and uniform interval resampling, aiming to enhance trajectory analysis reliability. Utilizing this refined data processing approach on ship trajectory data yields independent, complete motion profiles with uniform timing. Leveraging the Transformer model, denoted TRFM, this research integrates processed AIS data from the Yangtze River to create a predictive dataset, validating the efficacy of our prediction methodology. A comparative analysis with advanced models such as LSTM and its variants demonstrates TRFM’s superior accuracy, showcasing lower errors in multiple metrics. TRFM’s alignment with actual trajectories underscores its potential for enhancing navigational planning. This validation not only underscores the method’s precision in forecasting ship movements but also its utility in risk management and decision-making, contributing significantly to the advancement in maritime traffic safety and efficiency.