The 3rd part of this vast article about geocoding is slated for discussion about another free geocoding tool for MS Excel, namely the OpenStreetMap Nominatim geocoding and other remaining tools, which could be worth attention.
- NOMINATIM GEOCODING TOOL
The usage of this small tool is very simple, even simpler than Bing Maps API geocoding, however it requires a bit of knowledge about the VBA Excel.
The situation looks analogically to the Bing Excel geocoding tool, which appears separately in the file, ready for quick work. The file is available here, along with the whole tutorial. Because everything has been explained roughly there likewise in the Bing Geocoding case I will go straight to the option, in which we can launch this tool in our own workbook. I would like just to point, that the file includes also the Google API geocoding, which is on the top. It’s not for free unlike the Nominatim tool underneath (Pic. 1), which we can use.
Unlike Bing geocoding tool, the Nominatim is in my opinion not comfortable enough to use externally. However, the tool is a perfect fit for our own worksheet, because it’s basically confined to one formula. The same as previously, the VBA Excel knowledge is required to make this tool running. I am going to show you shortly how to accomplish it.
Firstly we must open the Geocode file and launch the VBA console (Pic. 2), from where you will enter the module with functions (Pic. 3).
Because the Geocode file is tailored also for geocoding in Google, you will encounter the Google API geocoding functions on the top. Just move your slider down in order to see the Nominatim functions.
The second step is copying this code into our workbook. You don’t need to drag or export a whole module, as shown in the previous part of this article. You can just select the Nominatim function, marked red above (Pic. 3), and copy it into your own workbook creating a new module for it. The image below (Pic. 4) shows all these steps:
- Or own worksheet with examples of location.
- Creating (Inserting) a new module in the VBA console.
- The new module (default Module1) has been created, you can see it now empty with Option Explicit on the top.
- Select the whole NominatimGeocode function from your Geocode file and copy it.
- Paste this code into a module in your workbook.
Now theoretically you can start geocoding in your own worksheet. Theoretically, but in practice, it’s still impossible unless you have your code and VBA library prepared correctly. The major thing, which you should do here is loading the specified library in order to avoid the “User-defined type not defined” error.
In your VBA Excel console, you should select the “Tools” from the main toolbar and next choose the “References” at the very top. Next, you must find the Microsoft XML v3.0 library and switch it on (Pic. 5). It will be loaded shortly.
You can also add this reference programmatically if you are more skilled with VBA Excel. It’s quicker because you only must run the macro instead of searching in the library list.
The example of the VBA macro for attaching this library is below:
AddFromFile “C:\WINDOWS\system32\msxml3.dll” ‘ the file of Microsoft XML v3.0 library
If you run the following XML3library macro, your reference will be added.
Next, you can carry on with validating your code. It’s still not the proper time for geocoding I am afraid, as you might get an error stating that “Variable is not defined” as per in the image below(Pic. 6).
It simply means, that there is a lack of Dim statements for some variables. We should define one variable in our code:
Function NominatimGeocode(address As String) As String
Application.Caller.Font.ColorIndex = xlNone
Dim xDoc As New MSXML2.DOMDocument
Dim vbErr As String
xDoc.async = False
xDoc.Load (“https://nominatim.openstreetmap.org/search?format=xml&q=” + WorksheetFunction.EncodeURL(address))
If xDoc.parseError.ErrorCode <> 0 Then
Application.Caller.Font.ColorIndex = vbErr
NominatimGeocode = xDoc.parseError.Reason
xDoc.SetProperty “SelectionLanguage”, “XPath”
Dim Loc As MSXML2.IXMLDOMElement
Set Loc = xDoc.SelectSingleNode(“/searchresults/place”)
If Loc Is Nothing Then
Application.Caller.Font.ColorIndex = vbErr
NominatimGeocode = xDoc.XML
Application.Caller.Font.ColorIndex = vbOK
NominatimGeocode = Loc.getAttribute(“lat”) & “,” & Loc.getAttribute(“lon”)
The red line indicates the element, which you should add to your code in order to run it properly – simply define the variable, which appears to be missing at the initial stage.
Next, you can finally use the Nominatim geocoding function. In your formula bar or in the cell you can type the NominatimGeocode() and calculate the location like you see below (Pic. 7). Since now, the Nominatim geocoding tool is ready to use in your own workbook.
2. OTHER EXCEL GEOCODING TOOLS WORTH ATTENTION
Apart from the tools described by myself, there are other appliances useful in geocoding the addresses in MS Excel. One of them is provided by OpencageData, where you can register your API key and make 2500 requests per day. It’s very useful and much quicker than Nominatim. The geocoding can be done both with VBA Excel as well as via Google Sheets. Under these links, you can learn more about how to do it.
Another way of geocoding in Excel is the Mapcite add-in installation. You can do some geocoding for free, but registration is required. The amount of 5000 addresses monthly is not too big at all, but still, something, when you are run out of the other options. Once the plugin is installed you can see it in the main Excel ribbon (Pic 9).
In these, all parts of the big article fully dedicated to costless geocoding in Excel I shown all the useful tools, which help you to do it. Personally, I think, that the best is the Bing Excel geocoding tool, which we can conveniently integrate with our workbook and geocode 10k addresses. Creating the new profile in order to gain the new Bing Maps API code and input into our workbook won’t be a problem at all. If you wish to have no limit with your address geocoding, then Nominatim will be the best, but remember, that this tool is quite slow (1 request per second), so you will have to wait. It’s good to consider the OpenCage geocoding, which gives you 2500 records daily.
This is the geocoding, where coordinates are gained from the addresses. In the nearest future, I would like to find the best and explain to you the costless reverse geocoding appliances for MS Excel, where at the basis of coordinates, the address string will be provided.
- Kounadi O, et al., 2013, Accuracy and privacy aspects in free online reverse geocoding services, (in:) Cartography and Geographic Information Science, vol. 40, issue 2, p.140-153
- Zandbergen P.A., 2-11, Influence of street reference data on geocoding quality, (in:) Geocarto International 26(1), p.35-47
- Excel – geocoding with MapCite plugin