Accurate prediction of ship traffic flow is essential for developing intelligent maritime transportation systems. To address the complexity of ship traffic flow data in the port and the challenges of capturing its dynamic spatiotemporal dependencies, a dynamic spatiotemporal model called Temporal convolutional network-bidirectional Gated recurrent unit-Pearson correlation coefficient-Graph Attention Network (TG-PGAT) is proposed for predicting traffic flow in port waters. This model extracts spatial features of traffic flow by combining the adjacency matrix and spatial dynamic coefficient correlation matrix within the Graph Attention Network (GAT) and captures temporal features through the concatenation of the Temporal Convolutional Network (TCN) and Bidirectional Gated Recurrent Unit (BiGRU). The proposed TG-PGAT model demonstrates higher prediction accuracy and stability than other classic traffic flow prediction methods. The experimental results from multiple angles, such as ablation experiments and robustness tests, further validate the critical role and strong noise resistance of different modules in the TG-PGAT model. The experimental results of visualization demonstrate that this model not only exhibits significant predictive advantages in densely trafficked areas of the port but also outperforms other models in surrounding areas with sparse traffic flow data.