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…).
geocoding with 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.
reverse GeoCoding
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:
geocoding addresses with mmqgis
addresses for geocoding with MMQGIS

This file serves as input for the transaction MMQGIS->Geocode->Geocode CSV with Google / OpenStreetMap:
file selection in MMQGIS
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
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
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
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
B&B Hostels in Germany geocoded with ArcGIS


Geocoding results in 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.
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

10 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Yoel
Yoel
7 years ago

Is there a limit of records to geocode in MMQGIS? I think MMQGIS use the service of Google to geocode…

Riccardo
7 years ago
Reply to  Yoel

Hi Yoel, you can choose between OSM and Google.
Google limit is:
2,500 free requests per day, calculated as the sum of
client-side
and server-side queries.

50 requests per second, calculated as the sum of
client-side
and server-side queries.

OSM limit is: 1 per second (check limits here: http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy )

Pablo
Pablo
7 years ago
Reply to  Riccardo

In MMQGIS you can geocode with a shp file to. If you have the street shp with the numbers of the address (for even and uneven numbers you can use 4 columns: fromleft, fromright, toleft, toright) and is very quickly and dont need internet conection. Sorry for my english

Eduardo de Oliveira
Eduardo de Oliveira
7 years ago

Geocoding in PostGIS

CREATE OR REPLACE FUNCTION geocode_osm(address text)

RETURNS geometry AS

$BODY$

from sys import path

path.append(‘C:Python34Libsite-packages’)

from geopy.geocoders.osm import Nominatim

g = Nominatim()

place, (lat, lng) = g.geocode(address, timeout=5000)

plpy.info(‘Geocoded %s for the address: %s’ % (place, address))

plpy.info(‘Longitude is %s, Latitude is %s.’ % (lng, lat))

plpy.info(“SELECT ST_GeomFromText(‘POINT(%s %s)’, 4326)” % (lng, lat))

result = plpy.execute(“SELECT ST_GeomFromText(‘POINT(%s %s)’, 4326) AS point_geocoded” % (lng, lat))

geometry = result[0][“point_geocoded”]

return geometry

$BODY$

LANGUAGE plpython3u VOLATILE

COST 100;

ALTER FUNCTION geocode_osm(text)

OWNER TO postgres;

SELECT ST_ASTEXT(GEOCODE_OSM(‘address’)) AS LOCAL;

BusinessFirstFamily.com

Hey Riccardo,

Great info on geocoding. Definitely took a lot of new info away from this post about where addresses are located.

Thanks,
Dennis

Simon Lühr
Simon Lühr
7 years ago

Hi Riccardo, pretty interesting article! In my daily work I recognized manual post-processing and address purging as a big challenge. My company developed a very nice webbased tool which enables you to do so easily: https://www.wigeogis.com/en/whatsnew/geocoder_online_new_JoinAddress_web_client
For a free Testaccount (geocoding and purging 200 Addresses) please just contact me sl@wigeogis.com.
Thanks for this very interesting Page!
Regards Simon

Barra
Barra
7 years ago

Hallo Riccardo, It’s really interesting article ans in the same case I need your opinion. I would geocode the name of streets from an existing file file.txt to the road shape that exists to. I would update my two existing files automatically via a geocoding process. when we have a new name of exesting road or a new road we add to new name frome a spesific interface to file.txt, then i would like to update or to generate a geocoding of this new name of road in my road.shp (polyligne). it’is possible and how? Please I really need your… Read more »

Riccardo
7 years ago
Reply to  Barra

Hi @disqus_iQNpvFDVsf:disqus , The link to the “sigterritoires” page is broken. Have you tried the solution proposed here? There is also another approached I described in this article: https://digital-geography.com%20.www378.your-server.de/diggeo/geocoding-addresses-in-arcgis-the-other-approach/#.WATQpo-LRhG
If you compare the locations of the geopy folder in this image http://i0.wp.com/www.digital-geography.com/wp-content/uploads/2015/03/2015-03-11-21_49_13-site-packages.jpg you will see: it needs to be in : “Python27/ArcGIS10.3/Lib/site-packages”
Yours is in a folder above.

Barra
Barra
7 years ago
Reply to  Riccardo

i want to thank you for your quick response. the links is : (http://www.sigterritoires.fr/index.php/arcmap-un-script-python-pour-geocoder-des-adresses-avec-openstreetmap/)
The geopy stell don’t work 🙁comment image

I will read your article and I will come back to ask your help/opinion 🙂

thank you

Barra
Barra
7 years ago
Reply to  Barra

comment image
the link work 🙁