This study employs the Muller geological accumulation index method and the Hakanson risk assessment method in combination with ArcGIS technology to assess the potential heavy metal pollution in soil. The study aims to investigate the geochemical characteristics, pollution degree, and potential ecological risks associated with soil heavy metal element content and distribution across various geological formations. The concentrations of eight heavy metals, namely Cu, Cd, Ni, Pb, Zn, Hg, As, and Cr, were analysed by collecting samples of the soil layer, parent material layer, and parent rock layer. The proportions of samples with different risk levels are accurately calculated to locate areas with high pollution risks. The findings are as follows: Firstly, the soil pH value in the study area is low, and the Cd and Cr concentrations are 1.38 and 1.20 times the background concentrations in soil in Sichuan Province, respectively. Moreover, Cu, Cd, Ni, Zn, and Cr concentrations are 1.23, 1.10, 1.20, 1.10, and 1.55 times the background concentrations in soil in China. Secondly, the distribution of heavy metal elements varies across different geological formation units, and the heavy metal contents of different samples from the same formation also varies significantly. The concentrations of heavy metal elements are influenced by different geological formations, with the pedogenic parent rock in the soil determining the initial concentrations of heavy metal elements. Thirdly, the spatial distribution of heavy metal elements indicates a good spatial distribution coupling relationship among the soil layer, parent material layer, and rock layer. The study suggests that the contents of the eight heavy metal elements in the soil inherited the characteristics of the parent material to a large extent and are influenced and controlled by the pedogenic parent rock (geological formation). Finally, the evaluation results reveal that all eight heavy metal elements exhibit moderate pollution, with a relatively large distribution area exhibiting moderate Cd, Hg, and As pollution and above. The overall study area exhibits a mild potential ecological risk level, with some areas at a moderate potential ecological risk level, distributed in patches across the study area. Cd and Hg exhibit relatively high potential ecological risks. The potential ecological risks of heavy metals are relatively high in the JKms and Tss units. While the overall quality of the soil in the study area is good, heavy metal pollution and potential ecological risks of some elements are still above ideal levels.