First, you could look at ControlPlane
https://www.controlplaneapp.com/
which can automatically switch your WiFi network based on evidence it can detect around it. For example, if you ONLY see a "Dogs and Cats" in one location, and "Wild Frontier" in another, then ControlPlane can see which is available and automatically switch your WiFi network for you, along with changing other location related configuration settings.
You can look at /usr/sbin/scselect which can switch to a different System Preferences -> Network -> Location and you can configure each Location with specify network preferences.
As MrHoffman says, you can use /usr/sbin/networksetup to make network changes.
You can use
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s
to find all available WiFi networks your Mac can see