Geocoding Using QGIS

(Download Files for this Tutorial Here)


Part 0 - Introduction

Geocoding is the process of taking addresses and converting them into points. There are a couple of methods available for this process in QGIS; the following is a rough guide of how to do two of them. Geocoding was done in QGIS 2.18.3 Las Palmas. When you open up QGIS, you’ll see the version number at the top of the window. In this exercise, we will take addresses of restaurants in Cambridge and locate them as points on our map.

Follow these steps to get started:

  1. To geocode, you'll have to install the MMQGIS plugin (check out the MMQGIS homepage for more information). In QGIS, click on Plugins > Manage and Install Plug-ins. Scroll down, select mmqgis, and click Install.
  2. Installing the MMQGIS Plugin
  3. Once installed, you should see "MMQGIS" in the menu bar.
  4. Also, install the Open Layers plugin, if you don't already have it installed. Again, click Plugins > Manage and Install Plug-ins. Scroll down, select OpenLayers, and click Install.
  5. Installing the Open Layers Plugin
  6. Load your favorite basemap from the Open Layers plugin under the "Web" menu
  7. Loading an Open Layers basemap

We are going to explore two methods of geocoding - the first will use a street file that we designate while the second will use a web service like Google Maps.


Part 1 - Finding locations using a City of Cambridge streets file

the first method we are going to use is to utilize information from the City of Cambridge, a street network file, and locate our addresses on the network according to the attributes of the file. This is the most common geocoding method, and uses address ranges and street names to interpolate locations on a street network.

The process is pretty straightforward:

  1. Let's start by inspecting our data - load the cambridge_centerlines.shp file into your map (click "Add Vector Layer" from the side toolbar). Once it's loaded, you can right-click and select "Zoom to Layer" to adjust your view.
  2. Loading the street file
  3. Open the MMQGIS menu at the top of the screen and select Geocode > Geocode from Street Layer.
  4. Opening the street layer geocoding dialog box
  5. Fill out the form as shown below. You'll need to browse to the cambridge_restaurants.txt file for the "Input CSV File" and browse to a good location for your Output Shapefile and Not Found Output List. (The Output Shapefile will be a point file containing all matched addresses. the Not Found Output List is a CSV of all addressses that were unable to be located using the street network file.)
  6. Inputting street layer geocoding data
  7. Click "OK". Your geocoding process will run - it may take a few minutes. Note: If your address file's street numbers contain invalid characters (like letters), you'll get a fatal error and your geocoding won't run at all. You'll need to clean these up in the original CSV first.
  8. When completed, you will see your points added to the map (if you don't, you can add the vector file manually).
  9. Resulting point file from street layer geocoding
  10. You can open the Attribute Table to see how many successful matches you got. Mine only got 361 out of 514 - yikes! This is to be expected however, since the matching algorithm is very fragile. That is, it looks for essentially exact matched between the "street" field of your addresses file and the "street" field of your streets file. Any discrepencies ("First St" vs "1st St", abbreviations, etc) won't be matched.
  11. To troubleshoot, you'll need to manualy adjust your data. Open the notfound.csv file that was saved during the geocoding process and look for potential discrepencies and errors Some hints:
    1. Look for street names that might be different between the files (e.g. "Mass Ave" vs "Massachusetts Avenue").
    2. Remove apartment numbers - the geocoder thinks they are part of the street name.
    3. Look for misspellings or other errors.

After making your changes, you can repeat the geocoding process to see if your matching has improved.


Part 2 - Find locations using Google Maps API

There is another method you can use that utilizes the Google Maps Geocoding API. This grabs point locations from Google. The following steps will set you on your way. Warning: this method is slow and buggy, so the first method is preferred.

  1. Open the MMQGIS menu and select Geocode > Gecode CSV with Google/OpenStreetMap.
  2. Opening the Google/OSM geocoding dialog box
  3. Fill out the form as follows. Again, you'll need to manually browse to the cambridge_restaurants.txt Input File and select a location to save your Output File and Not Found Output List. Warning: Google Maps can only do 2,500 records per day (per ID Address) while OpenStreetMap has no limits. However, Google Maps is much more robust.
  4. Inputting Google/OSM geocoding information
  5. Click OK to run the geocoding process. Warning: it took mine over ten minutes to complete!!
  6. Once completed, the geocoded points file will automatically be added to the map (or you may have to load it manually). Note: QGIS can be upredictable, so if the process stalls, or seems to be taking too long (e.g. more than 20 minutes), try it again.
  7. Google/OSM geocoding results
  8. Open the attribute table to see how well you've matched addresses. Mine found 504 of 514 places - much better than the previous method (though it also took much longer). You can open the notfound.csv to examine potential errors with the few addresses that were not matched.

Credits

Prepared by Mike Foster & Luke Mich


Return to DUSPviz tutorials page
>