"wrth" can also mean "from". For example, "oddi wrth" is frequently used when writing letters etc.
Just to clarify this... wrth on its own does not usually mean 'from' - it is the compound oddi wrth which is used to mean 'from' in certain contexts, such as receiving a letter or e-mail 'from' someone.
In what context is this? E.g., what makes it different from gyda (by a), etc?
Is there a general rule to tell which preposition should be used in a given context, or is there no set rules? If for instance I used "gan" instead of "wrth" in a sentence, would I still be understood, or is it considered wrong?
It is quite variable, I am afraid. As you learn more Welsh you may pick out some patterns. We may be able to include more examples in Tree2 - they are a key point to learn in intermediate level Welsh.
A handy, thin and cheap reference book is 'Pa Adroddiad', which shows which prepositions combine with verb-nouns to create which meanings. A more in-depth but out of print book is 'Y Geiriau Bach'.