This idiom originates from feng shui terminology. Mountain ranges were called
龙脉 (dragon veins), and geomancers traced where the 'dragon' came from and where its 'veins' went to find auspicious sites. The idiom preserved this imagery while its meaning generalized.