With the widespread coverage of location-based services (LBS), privacy protection of trajectory data is increasingly important. The starting and ending locations of trajectories often contain rich sensitive information. In order to avoid the unnecessary information loss caused by the large anonymous area of published trajectory datasets and protect semantic information of the starting and ending locations, this paper proposes a privacy protection method based on trajectory segment graph division. The method takes into account direction, shape and semantic differences of trajectory segments to measure the spatiotemporal and semantic relationships of trajectory segments. Firstly, the initial and final trajectory segment equivalence classes are constructed with different time stamps. Secondly, we propose a grid filtering method to calculate the shape distance matrix of equivalence class, meanwhile a location semantic classification tree is built to store the semantic information of locations. Finally, the graph division method is used to construct K-anonymous sets of trajectory segments and publish them. Experimental results in real datasets show that the proposed scheme can improve data availability while ensuring a certain degree of data privacy.