A list of health facilities might give you a full street address for one hospital and only a name and town for the next. You can use either to look up latitude and longitude, a process called (forward) geocoding. This guide shows how to use overpass.ch to find coordinates from OpenStreetMap and save the results in a spreadsheet. Overpass allows you to geocode 100,000 addresses per month for free; no credit card required.
Download the Python script and spreadsheet (ZIP) and extract both files into the same folder. Keep their names, geocode.py and addresses.xlsx. You can also view the Python source on GitHub.
Prepare your address list
Both worksheets contain the same five practice locations. You can try either sheet as it comes. For your own list, choose the sheet that fits your data and replace its example rows. Enter the two-letter country code on each row so the script searches in the right country. If your sites already have IDs, copy them into the optional site_id column so you can match results back to your records.
Free text
Use the Free text worksheet if the address is already in one cell or your list has a mixture of addresses and named places. Each site needs a value in the country_code and address column. In address, enter what you would type into a map search. If you know the town, include it with the name.
| country_code | address | site_id |
|---|---|---|
| BR | Hospital Regional do Juruá | BR-HOSP-01 |
| PH | Hermogenes Bautista Elementary School, Marikina | PH-EVAC-01 |
Structured
Use the Structured worksheet if you have the address already in separate columns. Each row needs country_code and a place name, a street, or both. The script uses place_name and street together when you fill in both, and includes city and postal_code whenever you supply them. Keep the house number with the street name.
| country_code | place_name | street | city | postal_code | site_id |
|---|---|---|---|---|---|
| KE | Kenya Red Cross Society | Ruring’u off Othaya Road | Nyeri | 10100 | KE-BRANCH-01 |
| PH | Hermogenes Bautista Elementary School | Marikina | PH-EVAC-01 | ||
| PL | Polski Czerwony Krzyż | Mokotowska 14 | Warszawa | PL-HQ-01 |
On either worksheet, the second line of each header tells you what’s required. You can reorder columns, remove unused optional columns, and add your own. Keep the field names in row 1. The template formats postal_code as Text to preserve possible leading zeros. If you’ve used a formula in any of the columns, use Paste Special > Values before running the script.
The script sends the search fields and country code to overpass.ch. Site IDs and extra reference columns stay in the workbook. If the list includes private residences or sensitive sites, check with the person responsible for the data and follow the IFRC guidance on protecting personal data before sending those addresses to an external service.
Get an API key
Create an overpass.ch account (you don’t need a credit card), confirm your email address, and create a key under API keys in the dashboard. You’ll use the key the first time the script needs to contact overpass.ch.
The free geocoding plan includes 100,000 requests per month and allows 300 per minute across the account’s keys. An answered search counts once, even if it finds no match. The script sends at most four requests per second. Geocoding 1,000 addresses takes approximately 4-5 minutes.
Run the script
Install Python 3 if you don’t already have one. Open a terminal in the folder containing geocode.py and addresses.xlsx. On Windows 11, right-click the folder, choose Open in Terminal, and use PowerShell. On macOS, open Terminal, type cd followed by a space, drag the folder into the window, and press Return.
Run the two commands below. The first creates a virtual environment named .venv in the project folder. The second installs this script’s packages there, so other projects can use their own versions.
Windows (PowerShell)
py -m venv .venv
.\.venv\Scripts\python.exe -m pip install openpyxl requests rich iso3166 keyring
macOS (Terminal)
python3 -m venv .venv
.venv/bin/python -m pip install openpyxl requests rich iso3166 keyring
If you prefer shorter commands, activate the environment for the current session with source .venv/bin/activate on macOS or .\.venv\Scripts\Activate.ps1 in PowerShell. You can then type python geocode.py and add any of the options below. Type deactivate when you’re done.
Save your API key for future runs (optional)
You can save the overpass.ch API key once in Keychain on macOS or Credential Manager on Windows.
| What you want to do | Windows (PowerShell) | macOS (Terminal) |
|---|---|---|
| Save or replace the key | .\.venv\Scripts\python.exe geocode.py --save-key | .venv/bin/python geocode.py --save-key |
| Remove the saved key | .\.venv\Scripts\python.exe geocode.py --forget-key | .venv/bin/python geocode.py --forget-key |
When prompted, paste the key and press Enter. The terminal hides it as you paste. If you skip saving it, the script asks for the API key every time you geocode new addresses.
Choose a worksheet and run the command
| Worksheet | Windows (PowerShell) | macOS (Terminal) |
|---|---|---|
| Free text | .\.venv\Scripts\python.exe geocode.py | .venv/bin/python geocode.py |
| Structured | .\.venv\Scripts\python.exe geocode.py --structured | .venv/bin/python geocode.py --structured |
The command selects the worksheet by name. The default mode reads the address column values on the Free text worksheet. The --structured option reads the various address search fields on the Structured worksheet. The script checks the country codes before sending any requests and tells you if you’ve entered invalid country codes.
The script prints a status row while it works. Here’s how it looked at the end of a first run with the five practice rows in the provided addresses.xlsx.
5/5 0 left Cache 0 API 5 ✅ 5 matched ❌ 0 no match 0 blank
Cache counts rows that reused a saved answer. API counts rows that received a new answer from overpass.ch. Run the same command again and you’ll see Cache 5 and API 0. A search with no match also gets cached. Blank and pending rows count toward neither total. The script reports HTTP attempts separately when it retries a request or a lookup fails.
The cache, geocoding-cache.sqlite3, stays in the script folder. Rows can reuse an answer when the mode, country, and search details match, even within the same run. Switching to --structured for the first time starts a separate set of lookups because it sends the address in a different form.
With the five-country template, the results file is geocoded.xlsx or geocoded_structured.xlsx. A list covering addresses only from Kenya would produce geocoded_ke.xlsx or geocoded_ke_structured.xlsx. Each file contains just the worksheet you searched, with your rows in their original order and the results beside them. Later runs add _2, _3, and so on if the output filename already exists to avoid overwriting your previous results.
Check the matches
All five example rows returned coordinates in both modes when we checked them. Four matched the intended facility. For Port Alice in Canada, reading match_address and match_type columns in the output file revealed that the coordinates belonged to a road. See the table below for insights on the results. Your results may change as contributors update OpenStreetMap.
| Example location | What to look for in the results |
|---|---|
| Kenya Red Cross Society, Nyeri County branch | The name, local street description, town, and postal code found the Nyeri branch office. The returned name includes “Nyeri Office.” |
| Hospital Regional do Juruá, Brazil | The hospital name and BR were enough to find the hospital in Cruzeiro do Sul, Acre. |
| Hermogenes Bautista Elementary School, Philippines | The name and city found the school in Concepcion Uno, Marikina (the school served as an evacuation center during Typhoon Ulysses). |
| Polish Red Cross national headquarters | The name, street, and city found Polski Czerwony Krzyż at Mokotowska 14 in Warsaw. You can check the house number against the Polish Red Cross address. |
| Canadian Red Cross health equipment loan service, Port Alice | The workbook purposefully gives only the street and the town to demonstrate how an incomplete address will introduce inaccuracies to geocoding results. The search results were sections of road, 1-6 km from the actual location. The Canadian Red Cross directory lists the service at Seaview Activity Centre, 901 Marine Drive. |
The script keeps up to two candidates in the order overpass.ch returns them. The first appears in the match_ columns and the second, if present, in the alt_ columns. The geocode_source column tells you whether each completed search came from the cache or the API.
| geocode_status | How to read it |
|---|---|
| One candidate | Compare the returned name, locality, and feature type with your records. A single candidate can still be a road or town. |
| Multiple candidates | Compare match_address and alt_address, their feature types, and their positions on a map. |
| No match | Check the spelling or try the local name. Add the town or district if you know it, then run the corrected search. |
| Blank address | The row has no address on Free text worksheet, or neither place_name nor street on Structured worksheet. |
| Pending | The script paused before completing the lookup. The terminal output explains why. Run the same command again after you resolve the issue. |
Viewing the results in QGIS
To check the sites on a map, drag the results workbook into QGIS and select its worksheet. In the Processing Toolbox, open Create points layer from table. Choose the worksheet as the input, set X field to match_longitude and Y field to match_latitude, and use WGS 84 (EPSG:4326) as the target CRS.
Viewing the results in Google My Maps
Open Google My Maps in your browser. My Maps accepts up to 2,000 rows per import.
- Sign in and click Create a new map. Click Untitled map to give it a name.
- Under Untitled layer, click Import and upload the results spreadsheet, such as
geocoded.xlsxorgeocoded_structured.xlsx. - When Google asks which columns to use for the pin locations, select
match_latitudeandmatch_longitude, then click Continue. This places each pin at the coordinates the script returned. - Choose
site_idas the pin title if you used site IDs. Otherwise, choosematch_address. Click Finish and rename the layer First matches.
To compare alternate matches, click Add layer and import the workbook again. This time, use alt_latitude and alt_longitude for the pin locations and site_id or alt_address for the titles. If only some rows have alternate coordinates, copy those rows and the column headers into a separate workbook for this import. Name the layer Alternate matches and give it a different pin color so you can tell the two results apart.
To find your map later, open Google Maps and go to Saved > Maps.
Credits
Remember to credit © OpenStreetMap contributors in the final product, and include the Open Database License when you share the coordinate data.
The original SIMS guide written by Jonathan Garro drew on geocoding work that Pinar Öner shared with the network while working with the IFRC Türkiye delegation.

1 Comment