How to combine science and technology with the humanities in the research on ancient cities to reveal ancient peoples’ urban planning thoughts is worthy of in-depth study. The capitals of the Western Han dynasty as well as the Sui and Tang dynasties were some of the greatest cities in the world at the time. This paper takes them as its subjects and puts forward a method to study the spatial relationship between ancient cities and the natural environment by combining spatial information technology and cultural analysis. Firstly, satellite images, elevation maps, urban ichnographies, and literature materials were collected and sorted to deeply understand the cultural thoughts involved in ancient urban planning; based on this, key element points were marked and rechecked on the spot, and the above drawings were accurately superimposed by GIS technology to form a geographic information base that integrated multisource information. Then, Python was used to construct a “decision model of spatial relationship between urban elements and natural elements”, and rules as well as parameters were set through man–machine collaboration. The decision model was used to test the geographic information base, and the information of strong correlations between urban objects and natural objects was outputted. The drawings were exported after screening, and a visual expression was realized with Illustrator software. The research results indicated that this analysis method was feasible, effective, and easy to promote. The new archaeological discoveries included eight important line segments with a 9:6 proportional relationship (which represents the balance of Yin and Yang) and two important line segments with a 9:5 proportional relationship (which represents the supreme imperial power) in the capitals of the Western Han dynasty as well as the Sui and Tang dynasties, and 16 contraposition lines in a positive direction or oblique 45° direction (which reflects the close relationship between urban elements and natural elements). We consider that the two capitals were intentionally closely related to natural environments such as mountain peaks and valley entrances in the planning stage, and that proportions and scales with profound humanistic meaning were selected. The capital of the Sui and Tang dynasties was specially aligned with the capital of the Western Han dynasty in space. These characteristics embody ancient Chinese Confucian cultural thoughts such as the “integration of yang and yin”, “harmony between nature and humans”, the “supremacy of emperors”, and the “use of numbers and shapes to convey meaning”.