Select to view content in your preferred language

ArcGIS World Geocoding Service Request URL

3672
4
12-10-2021 09:19 AM
JaredPilbeam2
MVP Regular Contributor

Hello,

I'm using example 4 of this help page to go off of: https://pro.arcgis.com/en/pro-app/latest/tool-reference/geocoding/geocode-addresses.htm#

Excuse my ignorance, but I'm not sure what the full URL should be to access the ArcGIS World Geocoding Service. I'm guessing this is just a base URL in the example, so I'm looking for some direction as to what a complete URL would like?

 

#ArcGIS World Geocoding Service URL
locator = r"https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/ArcGIS World Geocoding Service"
#Locator parameters
fieldMap = ("\'Address or Place\' adcal VISIBLE NONE;Address2 <None> VISIBLE NONE;Address3 <None> VISIBLE NONE;" +
                  "Neighborhood <None> VISIBLE NONE;City city VISIBLE NONE;County <None> VISIBLE NONE;" +
                  "State state VISIBLE NONE;ZIP ZIP zip VISIBLE NONE;ZIP4 <None> VISIBLE NONE;" +
                  "Country <None> VISIBLE NONE")
gcName = "wasteRecyclingReport_geocode"
geocodeResult = os.path.join(out_location, gcName)
arcpy.geocoding.GeocodeAddresses(intable, locator, fieldMap, geocodeResult)

 

If you run that you get:

 

---------------------------------------------------------------------------
ExecuteError                              Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_15300/42733642.py in <module>
      7 gcName = "wasteRecyclingReport_geocode"
      8 geocodeResult = os.path.join(out_location, gcName)
----> 9 arcpy.geocoding.GeocodeAddresses(intable, locator, fieldMap, geocodeResult)

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geocoding.py in GeocodeAddresses(in_table, address_locator, in_address_fields, out_feature_class, out_relationship_type, country, location_type, category, output_fields)
    517         return retval
    518     except Exception as e:
--> 519         raise e
    520 
    521 @gptooldoc('PackageLocator_geocoding', None)

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geocoding.py in GeocodeAddresses(in_table, address_locator, in_address_fields, out_feature_class, out_relationship_type, country, location_type, category, output_fields)
    514     from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
    515     try:
--> 516         retval = convertArcObjectToPythonObject(gp.GeocodeAddresses_geocoding(*gp_fixargs((in_table, address_locator, in_address_fields, out_feature_class, out_relationship_type, country, location_type, category, output_fields), True)))
    517         return retval
    518     except Exception as e:

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py in <lambda>(*args)
    510         val = getattr(self._gp, attr)
    511         if callable(val):
--> 512             return lambda *args: val(*gp_fixargs(args, True))
    513         else:
    514             return convertArcObjectToPythonObject(val)

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000005: Could not open the address locator.
Failed to execute (GeocodeAddresses).

 

 

0 Kudos
4 Replies
ABishop
MVP Regular Contributor

Hello Jared,

I did some research on this because I was also curious why you couldn't access the world geocode service and looks like they now require you to create a token and authenticate using your AGOL account.  This is because it is a service provided by ESRI based on credit usage.  See link below.

https://developers.arcgis.com/rest/geocode/api-reference/geocoding-authenticate-a-request.htm 

Amanda Bishop, GISP
JaredPilbeam2
MVP Regular Contributor

@ABishopThanks, that is an option I have to explore.

I just stumbled onto something that works. Run the Geocode Addresses geoprocessing tool with your parameters. Right click the "completed" green ribbon > Copy Python Command. Then copy this into your script.

JaredPilbeam2_0-1639691250994.png

This is how it looks after setting the results to variables. Funny, the URL never changed. But the parameters don't look the same as the help page example.

 

#ArcGIS World Geocoding Service URL
locator = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/ArcGIS World Geocoding Service"
#Locator parameters
fieldMap = ("'Address or Place' adcal VISIBLE NONE;Address2 <None> VISIBLE NONE;Address3 <None> VISIBLE NONE;Neighborhood <None> VISIBLE NONE;City city VISIBLE NONE;County <None> VISIBLE NONE;State state VISIBLE NONE;ZIP zip VISIBLE NONE;ZIP4 <None> VISIBLE NONE;Country <None> VISIBLE NONE")
gcName = "wasteRecyclingReport_geocode"
in_table = os.path.join(defaultDB, "wasteRecyclingReport")
geocodeResult = os.path.join(defaultDB, gcName)
arcpy.geocoding.GeocodeAddresses(in_table,locator,fieldMap, geocodeResult, "STATIC", None, "ROUTING_LOCATION", None, "ALL")

 

ShanaBritt
Esri Regular Contributor

@JaredPilbeam2 Have you tried using the SignIntoPortal function as part of your script so that you are signed into ArcGIS Online? There is a note about it above the code in sample 4 in the Geocode Addresses topic, https://pro.arcgis.com/en/pro-app/latest/tool-reference/geocoding/geocode-addresses.htm#GUID-D92B5478-6B6E-4A79-9ECE-1C24BE984FF1.

0 Kudos
JaredPilbeam2
MVP Regular Contributor

Hi @ShanaBritt ,

Yes, I've seen that too. It was in my script already, actually. I understood that it should be used especially in a stand-alone script outside of Pro.

0 Kudos