My dogs pee competitively. If one pees on something then other will go up, sniff it, and pee on it even if he's out of urine. They both run out of urine they continue to do the same thing, going through the motions.
Now sometimes I'm out walking them and I pee too. When I do they try to drink it. Yeah it's gross but it's what they do. Failing that, Tweeter, who tends to be dominant about most of the time, will sniff and then pee right where I did. Boomer doesn't do that. So I think not only does it mark territory for non-pack members, but it's also a competitive act among pack members.
As to what to pee on, in the morning they don't care much and will just go on the grass, but otherwise they will pull me to someplace that really interests them. Usually it's something tall like a rock or a plant and yeah, I think that's so other dogs will be able to easily smell it. Part of that is mating as well. Female dogs can detect testosterone in the urine the same way males can smell estrogen in females. This lets females know that eligible males are in the area and warns non-pack males to stay out.
But why one tree over another? I don't know. Maybe they're looking for something with very little scent of its own so theirs stands out, but if they find something with another dog's scent, they try to cover it with their own.