An automatic optimization method based on weighted A* search algorithm is proposed. The main process can be divided into four steps:the first step is to generate the initial seam-line network using standard Voronoi map; and then use the digital surface model (DSM) data to generate the corresponding elevation gradient map (also known as edge map); then the initial nodes of the seam-line network are automatically adjusted, the nodes located on the building are moved to the near ground; finally a weighted A* algorithm combined with the elevation gradient map are used to pilot all the seam-lines to avoid high buildings, and obtain the optimal seam-line network. This method is tested with three real UAV dataset. Preliminary result has shown that our method is suitable for unmanned aerial vehicle imagery, and acceptable mosaic image is produced. The result is proved to be better than the result of OrthoVista for dataset 1.