With the growth of global trade, port shipping is becoming more and more important. In this paper, an analysis of a ship’s inbound and outbound track characteristics is conducted using the OD–Hausdorff distance. The accuracy and efficiency of trajectory data analysis have been enhanced through clustering analysis. Trajectories are arranged in a time sequence, and representative port segments are selected. An improved OD–Hausdorff distance method is employed to capture the dynamic characteristics of a ship’s movements, such as speed and heading. Additionally, the DBSCAN algorithm is utilized for clustering, allowing for the processing of multidimensional AIS data. Data cleaning and preprocessing have ensured the reliability of the AIS data, and the Douglas–Peucker algorithm is used for trajectory simplification. Significant improvements in the accuracy and efficiency of trajectory clustering have been observed. Therefore, the main channel of the Guan River and the right side of Yanwei Port are usually followed by ships greater than 60 m in length, with a lateral Relative Mean Deviation (RMD) of 7.06%. Vessels shorter than 60 m have been shown to have greater path variability, with a lateral RMD of 7.94%. Additionally, a crossing pattern at Xiangshui Port is exhibited by ships shorter than 60 m due to the extension of berths and their positions at turns. Enhanced clustering accuracy has provided more precise trajectory patterns, which aids in better channel management.