Wednesday, August 20, 2014

How to geocode points in QGIS with Google Maps and OpenStreetMap

The following tutorial will review the process of geocoding data points in QGIS with GoogleMap and OpenStreetMap through the MMQGIS plugin.

                                                                                       

I have collected NFL Stadium location data and will be plotting the stadiums on the US State and Boundary map from NaturalEarth. You can find the stadium location data here.

If you have not downloaded the MMQGIS plugin previously, click the Plugins tab and Manage and Install Plugins.

The MMQGIS plugin has many functions, one of which is the Geocode tool which I will review today.

Once the MMQGIS plugin is installed we can move forward with creating our geocoded map of NFL stadiums. First we will need to add out base map. To access our US State and Boundary map, select the Layer tab and Add Vector Layer.


You will then be prompted to add your dataset. For the NaturalEarth maps, I extracted them to a local folder.


Once you find the folder and map you wish to use, in this case the 110m_admin_1_states_provinces.shp file, select and open the shp file.

You will now see the vector layer base map present in the layer and map views. As you can see in the map view Alaska and Hawaii are present in the map view.

Since there are no NFL teams in Alaska or Hawaii, I have focused the map view on to the continental US map. Additionally I have updated the background to blue and US base map to green using the QGIS properties. Next I use the MMQGIS Geocode tool. Click the MMQGIS tab and Geocode. As you can see from the screen shot there are two options within the Geocode tool, Geocode CSV with Google/OpenStreetMap and Geocode from Street Layer. Since we are working with point data, I will only be utilizing the Geocode CSV tool and comparing the output based on the Google and OpenStreetMap API's.


Once you select Geocode CSV with Google/OpenStreetMap, you will be prompted to select an Input CSV File. This is where we will select the Stadium Location data provided at the beginning of the tutorial. For all input files an address, city, state and country are required for the MMQGIS Geocode tool. We will begin by using the Google Maps under Web Service and finally we will need to specify the Output Shapefile and Not Found Output List location. I would recommend using the same file for each.


Once the Google geocoding is completed, the resulting points with attribute data will be provided in the layers view and the map view will plot the geocoded points. Within the bottom left hand corner of QGIS you will also so the number of points successfully geocoded. For the NFL Stadiums, 29 of 31 were successful. Next I will perform the same analysis using the OpenStreetMap.

Repeat the previous steps to select Geocode CSV with Google/OpenStreetMap. When selecting the Web Service we will now select OpenStreetMap/Nominatim function from the drop down menu.

Once the OpenStreetMap/Nominatim geocoding is completed, the resulting points with attribute data will be provided in the layers view and the map view will plot the geocoded points. Within the bottom left hand corner of QGIS you will find the number of points successfully geocoded for OpenStreetMap/Nominatim are 21 of 31.

Both datasets contained points the were not geocoded. To find which data points are not present on the map view, find the file location previously specified for the Not Found Output List location. The csv file generated by the MMQGIS plugin will provide the points the tool was unable to geocode.

To see which data points were geocoded. Select the Layer tab and Open Attribute Table.

The resulting table will provide the stadiums that were geocoded. The resulting shp files created by the MMQGIS tool can be located in the previously specified Output Shapefile location.

To find out more about the Google API and OpenStreetMap API select the appropriate links.

Hope this was helpful and forward any questions to qgis.tutorial@gmail.com


No comments:

Post a Comment