Find places

Place finding is the process of searching for a place name or POI to find its address and location.

In this tutorial, you will create a script to search and display different places around the Santa Monica Mountains area.

The ArcGIS World Geocoding Service can find addresses and places, convert addresses to coordinates, and perform batch geocoding. If you want to add POIs (Points of Interest) to your analytical workflows, you can search for places such as coffee shops, gas stations, or restaurants. To find places, use the geocode function and pass in a location and search category (e.g. "Coffee Shop").

You can then visualize the results on a map, manipulate the results in a Pandas Dataframe, and more.

Prerequisites

The ArcGIS API for Python tutorials use Jupyter Notebooks to execute Python code. If you are new to this environment, please see the guide to install the API and use notebooks locally.

Steps

  1. Add the following code to model a GIS portal and import the geocode function from the ArcGIS API for Python.

    Use dark colors for code blocks
                            
    Add line.Add line.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    
    from arcgis.gis import GIS
    from arcgis.geocoding import geocode
    
    
  2. Create an anonymous connection to ArcGIS Online. Since the results are not stored, you do not need credentials to call the geocoding service.

    Use dark colors for code blocks
                            
    Add line.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    
    from arcgis.gis import GIS
    from arcgis.geocoding import geocode
    
    gis = GIS()
    
    
  3. Pass the relevant parameters into the geocode function and get a FeatureSet as the result. In this example, the call requests the names, addresses, and locations of 25 coffee shops near a point in the Santa Monica Mountains. It also requests the results as a feature set so that they can be easily converted to a dataframe and mapped.

    Use dark colors for code blocks
                            
    Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    
    from arcgis.gis import GIS
    from arcgis.geocoding import geocode
    
    gis = GIS()
    
    geocoded_features = geocode(
        address=None,
        location=[-118.71511, 34.09042],
        category="Coffee shop",
        out_fields="Place_addr, PlaceName",
        max_locations=25,
        as_featureset=True,
    )
    
    
  4. Convert the results to a Pandas Dataframe by calling the sdf property of a FeatureSet and show the first two locations.

    Use dark colors for code blocks
                            
    Add line.Add line.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    
    from arcgis.gis import GIS
    from arcgis.geocoding import geocode
    
    gis = GIS()
    
    geocoded_features = geocode(
        address=None,
        location=[-118.71511, 34.09042],
        category="Coffee shop",
        out_fields="Place_addr, PlaceName",
        max_locations=25,
        as_featureset=True,
    )
    
    geocoded_df = geocoded_features.sdf
    geocoded_df.head(2)
    
    
  5. Create a map to display the results.

    Use dark colors for code blocks
                            
    Add line.Add line.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    
    from arcgis.gis import GIS
    from arcgis.geocoding import geocode
    
    gis = GIS()
    
    geocoded_features = geocode(
        address=None,
        location=[-118.71511, 34.09042],
        category="Coffee shop",
        out_fields="Place_addr, PlaceName",
        max_locations=25,
        as_featureset=True,
    )
    
    geocoded_df = geocoded_features.sdf
    geocoded_df.head(2)
    
    m = gis.map()
    m
    
    
  6. Once the map has loaded, draw the results.

    Use dark colors for code blocks
                            
    Add line.Add line.Add line.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    
    from arcgis.gis import GIS
    from arcgis.geocoding import geocode
    
    gis = GIS()
    
    geocoded_features = geocode(
        address=None,
        location=[-118.71511, 34.09042],
        category="Coffee shop",
        out_fields="Place_addr, PlaceName",
        max_locations=25,
        as_featureset=True,
    )
    
    geocoded_df = geocoded_features.sdf
    geocoded_df.head(2)
    
    m = gis.map()
    m
    
    m.center = [34.09042, -118.71511]
    m.zoom = 11
    m.draw(geocoded_features)
Estimated time
5 minutes

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.