Digital Geography

17. July 2016

Geocoding in GIS: ArcGIS, QGIS, Leaflet

The recent move from the Mongolian Post to use W3W as their new address system shed a new light on the question: Where are addresses located and how to get the correct position of an address in your GIS. In this article I would like to show different possibilities in QGIS, ArcGIS and Leaflet. This post references also mappinggis.
If you geocode addresses you try to find the spatial location of a specific address. Therefore you need a database of addresses and corresponding geodata and a tool to transform addresses into geographical coordinates (geocoding) or coordinates into addresses (reverse geocoding). The definition in ArcGIS states:
Geocoding is the process of assigning a location, usually in the form of coordinate values, to an address by comparing the descriptive location elements in the address to those present in the reference material. Addresses come in many forms, ranging from the common address format of house number followed by the street name and succeeding information to other location descriptions such as postal zone or census tract. In essence, an address includes any type of information that distinguishes a place.
Some of the APIs that offer those services are from ESRI, HERE, GoogleMaps, Nominatim (based on OpenStreetMap) or Geonames and many more… In this post I’ll show how to geocode addresses in QGIS, ArcGIS and Leaflet.

Geoding in QGIS

There are two plugins in QGIS that can be used for Geocoding: MMQGIS and Geocoding.

Geocoding

Let’s state it: A very basic plugin with limited functionality. You can geocode one address at a time and the result is placed as a one-point layer in QGIS and reverse geocode a point from the map using Nominatim or GoogleMaps (be aware of the EULA of GoogleMaps geocoding…).

Washington DC search in GeoCoding


If there are more than one location the plugin will inform you and let’s you choose the proper entry. Reverse Geocoding can be accessed via Plugins->GeoCode->Reverse GeoCode.

result of reverse Geocoding


Then you click a location on your map and it will show the address in a popup. Unfortunately that does not work in every Coordinate Reference System (CRS) as I was trying it with EPSG:31467.

MMQGIS

MMQGIS is one of the most downloaded plugins for QGIS. It is much more than just a simple geocoding plugin:
MMQGIS is a set of Python plugins for manipulating vector map layers in Quantum GIS: CSV input/output/join, Geocoding, Geometry Conversion, Buffering, Hub Analysis, Simplification Column Modification, Color Ramps, and Simple Animation. MMQGIS provides an alternative to the native QGIS vector plugin set and Sextente, with verbose progress reporting, an intuitive user interface, direct shapefile/CSV-file access, and some additional capabilities missing from other plugin sets.
With MMQGIS we are able to geocode several addresses at once. We simply need a csv file containing our addresses. We can create this in an editor:

addresses for geocoding with MMQGIS


This file serves as input for the transaction MMQGIS->Geocode->Geocode CSV with Google / OpenStreetMap:

File selection in MMQGIS


Make sure to use UTF8 as the encoding. The result is saved as a shapefile and is imported in QGIS right away:

MMQIS Geocode results


Geocoding in ArcGIS

First import the txt file using the Add Data transaction. Once you have that table, simply make a right-click on the table in the “Table of Contents” and choose Geocode Addresses…” :

Choose a Geocoder


Now you need to choose the geocoding service and define the fields to geocode:

Define the properties of your file for geocoding


After a few second you will get the result and a nice point layer on your map:

B&B Hostels in Germany geocoded with ArcGIS



GeoCoding results in ArcGIS


You will need an ArcGIS online account for this action and the price is 40 credits per 1’000 geocodes. I’ve also written a tutorial on how to get coordinates for addresses with Python for free.

Leaflet

Leaflet is a nice framework for a webmap as it allows you to embed plugins to enhance the functionality of a webmap. In our case we will work with the Leaflet GeoSearch plugin to get geocoding functionality into a leaflet webmap. First of all: download the github source or use the following CDN. Once the map is initiated, you can add the control to your map:
var geocodeControl = new L.Control.GeoSearch({
    provider: new L.GeoSearch.Provider.OpenStreetMap()
}).addTo(map); 
This will enhance this basic webmap and create something like this:
There are other plugins like opencage or Geocoder.