Viewed from AIS (Automatic Identification System) data, ship trajectories comprise a non-continuous series of spatiotemporal positions. Subject to the quality of the raw data, e.g. error, anomaly, it is challenging to reconstruct an original and continuous trajectory for further safety and efficiency analysis. This paper presents a novel method to detect data anomaly, identify line type, and restore ship trajectory based on vector analysis. Ship trajectory is segmented into underway and mooring sub-trajectories by analyzing characteristics of AIS data. A base vector, which represents the trend of the trajectory, is established on the basis of position vectors. With comparison of the vectors, Anomaly data is detected and filtered. A sparse sampling technique is employed to identify the linetsype of the rest sub-trajectory. Linear interpolation and cubic spline interpolation are finally applied for straight and curve sub-trajectories respectively to reconstruct a new smooth trajectory. A case study is performed and the results indicate that the reconstructed trajectory meets the layout of fairway well, with mean errors of 2.86 X 10(-4) degrees in longitude, 2.30 X 10(-4) degrees latitude and 2.35 X 10(-2) nautical miles distance. This algorithm can effectively detect abnormal data points, and approximate the original movement of the ship.