I am not sure there’s a logical explanation in every case for those things, you just end up having to know when to use it in certain instances. You could avoid it by saying La iglesia queda al lado del rio. My spanish is rusty. I took it from 7th grade all through HS and majored in it in college. Also did two stints in Colombia, SA, in college, doing a research project and living with a family. These days my only use of spanish is talking to my cleaning lady and my lawn guys. Embarrassing!