垣 is a literary or classical term for a wall, especially a low or enclosing wall. In modern Chinese it mainly appears in compounds like 断垣 (broken wall) or place names.
土 (earth) is the indexing radical. A 垣 is a low earthen wall — the kind of rammed-earth or mud-brick boundary that once enclosed villages and yards. Compare 城 (city wall), 墙 (wall), 坝 (dam) — all earth-radical structures pressed up from the ground.
亘 (gèn) supplies the sound, drifted to yuán. There's a useful semantic echo: 亘 means stretching unbroken across distance, exactly what a long boundary wall does. Same phonetic also gives 桓 (literary name), 恒 (constant — historically related).