One of my former jobs was stormwater research, which consisted of walking up and down every mile of river and creek of a particular city in middle TN with a handheld GPS and a clipboard.
The project was for the city, and they printed multiple notices in the paper, etc, telling the good citizens that some weirdo in chest waders with a GPS may be wandering in the local creeks and rivers, including next to their backyards, don't be alarmed, etc.
I carried with me a copy of the state law that gave my full legal right to trespass anywhere I needed to, and I only had to show it to people 2 or 3x in a 3 month period. I tried to be as quiet as possible, not sneaky, but no reason to get people all riled up if it could be avoided. And yes I realize that a piece of paper doesn't protect me from getting shot or bitten by a dog. Most of the time when people saw me I introduced myself, told them what I was doing, who for, and they were friendly about it.
Oh yeah, this was about dogs.
So one day I'm at the edge of the creek (which is right-of-way of the city/county), and an adult Rottie from the backyard next door comes at me full speed, snarling, teeth bared, etc. Nothing between me and it but a grass lawn. I stayed in the neighbor's backyard, stood my ground, and grabbed the range pole (39" long 1" diameter metal pole with a sharp point on one end) in both hands ready to spear the dog if it didn't stop.
The dog's owner was screaming something at me from across the yard, but I was paying so much attention to the black streak headed towards me I couldn't process what the owner was screaming.
About 7' from me the dog skids to a stop at the property line, still going nuts with the snarling, teeth, etc.
The dogs owner comes running up, grabs the dog and pulls it away, and as I start to calm down a bit I decipher the owner telling me that the dog has one of those (invisible) underground electric fences that it would not have gone outside.
The owner was semi-understandably a little pissed that I was going to spear his dog, and I sure didn't want to, but if his dog goes off his property to attack me, I didn't have a lot of options open at the time.
My points:
1)You never know where one of those pesky underground fences is
2)You never know if the dog would 100% certainly stop at the fence anyway
3)Dogs are a lot harder to read than humans, and it's hard to tell (at least for me) if they're going to actually attack or just bark and act mean or territorial etc. I don't know how you could know for sure they were going to attack.
4)You're going to be in a mess of legal trouble in most situations if you shoot an animal for anything other than protecting your own animals/family on your land. IIRC Animal Cruelty is a felony in many places. Obviously that's better than being dead, but I would prefer to explore all available options before using a gun.
5) You're looking at a decent probability of an equally serious confrontation with the dog owner if you shoot it. To a lot of people it's like shooting their child.
6)Not that I was carrying while working a city job on city property, but even if I was I'm about 95% sure I couldn't have drawn a handgun and shot the dog before it got to me. I wouldn't have the speed, or the accuracy. Even a big dog like a rottie had a fairly small frontal area (target) exposed to you when they are stretched out low and running directly towards you. Even if I had shot it, that's certainly no guarantee it would have stopped before it had a chance to take at least one big chunk out of me.