We get information on an author's affiliation from many sources (e.g., Crossref, PDFs, repositories) but always as text, not linked to specific institutions or countries. We use algorithmic approaches to match that text to known institutions in ROR (more on that here). ROR records have an affiliation country in their metadata and so we assign country based on that matching.
Sometimes, we get affiliation text that we cannot match to known ROR records but there might still be information on the country in the address field that we are able to identify. In those cases, we directly assign a country code without using ROR.