Creating a python code to geocode addresses from a .CSV and append

3781
1
01-29-2019 08:59 AM
VanceRenforth2
New Contributor III

I am trying to create a script to:

  1. Geocode a .CSV file using ArcGIS World Geocoding Service
  2. Add global IDS
  3. Append the new feature layer to an existing feature layer

Here is the code I have come up with by going through the various tool reference's

# Import module
import arcpy
import sys
import os

# Set work environment
arcpy.env.workspace = r"C:\Users\vmrenfor\EIRP\EIRP_Sewer_Locates\EIRP_Sewer_Locates\Dapps 2019\Dapps 2019.gdb"

# Set local variables:
address_table = r"C:\Users\vmrenfor\CSVs\CIVIC\Dapp#_16365.csv"
address_locator = "ArcGIS_World_Geocoding_Service.loc"
address_fields = "Address Address;City City;County County;State State;ZIP Postal Code"
geocode_result = "Dapp16365"

#Geocode Addresses from csv
arcpy.GeocodeAddresses_geocoding(address_table, address_locator, address_fields,
                                 geocode_result, 'STATIC')

#Add Global IDs
arcpy.env.workspace = r"C:\Users\vmrenfor\EIRP\EIRP_Sewer_Locates\EIRP_Sewer_Locates\Dapps 2019\Dapps 2019.gdb"
arcpy.AddGlobalIDs_management("Dapp16365")

#Append
arcpy.env.workspace = r"https://services.arcgis.com/T2graiaSQnlmwwmp/arcgis/rest/services/2019_Taplin/FeatureServer"
arcpy.Append_management(["Dapp16365"],
                        "Sewer Locate Card")

But I get the following error:

Traceback (most recent call last):
  File "<string>", line 17, in <module>
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geocoding.py", line 332, in GeocodeAddresses
    raise e
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geocoding.py", line 329, in GeocodeAddresses
    retval = convertArcObjectToPythonObject(gp.GeocodeAddresses_geocoding(*gp_fixargs((in_table, address_locator, in_address_fields, out_feature_class, out_relationship_type, country, location_type, category), True)))
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 496, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Address Locator: Dataset ArcGIS_World_Geocoding_Service.loc does not exist or is not supported
ERROR 000005: Could not open the address locator.
Failed to execute (GeocodeAddresses).

So it appears I am not properly accessing the geocoder to begin with.

Skipping ahead to the Append, I am not sure how to include matching the schema's? The tool reference guide is pretty confusing. 

In the Geoprocessing tool window I have:

GlobalID               GlobalID

Status                   USER_Sewer_Status

Address                USER_Address

Work_Group         USER_Work_Group

City                       USER_City

Gas_Constr          USER_Gas_Construction_Status

.............

Tags (1)
0 Kudos
1 Reply
MorganWaterman
New Contributor III

Hi Vance Renforth‌,

I believe the problem is related to the fact that the ArcGIS Online World Geocoding Service is not a .loc file, but a REST service. Perhaps it needs to be accessed via URL (http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer)?

I think you may also need to generate a token that provides the identity of a user who has the needed permissions to access the service: geocodeAddresses—ArcGIS REST API: World Geocoding Service | ArcGIS for Developers 

Best,

Morgan