Geocoding

geopandas supports geocoding (i.e., converting place names to location on Earth) through geopy, an optional dependency of geopandas. The following example shows how to use the Google geocoding API to get the locations of boroughs in New York City, and plots those locations along with the detailed borough boundary file included within geopandas.

In [1]: boros = gpd.read_file(gpd.datasets.get_path("nybb"))

In [2]: boros.BoroName
Out[2]: 
0    Staten Island
1           Queens
2         Brooklyn
3        Manhattan
4            Bronx
Name: BoroName, dtype: object

In [3]: boro_locations = gpd.tools.geocode(boros.BoroName, provider="google")

In [4]: boro_locations
Out[4]: 
                        address                               geometry
0        Staten Island, NY, USA         POINT (-74.1502007 40.5795317)
1               Queens, NY, USA         POINT (-73.7948516 40.7282239)
2             Brooklyn, NY, USA  POINT (-73.94415789999999 40.6781784)
3  Manhattan, New York, NY, USA         POINT (-73.9712488 40.7830603)
4                Bronx, NY, USA         POINT (-73.8648268 40.8447819)

In [5]: import matplotlib.pyplot as plt

In [6]: fig, ax = plt.subplots()

In [7]: boros.to_crs({"init": "epsg:4326"}).plot(ax=ax, color="white", edgecolor="black");

In [8]: boro_locations.plot(ax=ax, color="red");
_images/boro_centers_over_bounds.png

The argument to provider can either be a string referencing geocoding services, such as 'google', 'bing', 'yahoo', and 'openmapquest', or an instance of a Geocoder from geopy. See geopy.geocoders.SERVICE_TO_GEOCODER for the full list. For many providers, parameters such as API keys need to be passed as **kwargs in the geocode call.

Please consult the Terms of Service for the chosen provider.