Select to view content in your preferred language

ERROR 999999 With arcpy.geocoding.CreateFeatureLocator()

215
1
08-22-2024 08:57 AM
MichaelAscher
New Contributor

I am trying to automate the process of updating feature locators for our ArcGIS Pro desktop apps. The goal is to take the layer from ArcGIS Online and make the locators, then put them in a folder on a local network drive. I have this code, but `GasCurbValveLocator` always errors with error 999999, failed to execute and no other description.

import os
import zipfile
from arcgis.gis import GIS

import arcpy



if __name__ == '__main__':
    print('Start')
    locators = [
        {
            "name": "AddressLocator",
            "link": 'https://services5.arcgis.com/g3r4E4Xlpygk5wEz/arcgis/rest/services/Addresses/FeatureServer/0',
            "map": """
                "'*Name' FullStName VISIBLE NONE" 
            """,
            "etc": """
                "'UnitNumber' UnitNum;
                'StreetAddress' Address;
                'CityName' City;
                'PostalCode' Zip;
                'LocationName' PlaceName;
                'PINNumber' PIN;
                'Subdiv' Subdivision;
                'AddressNumber' AddrNum"
            """
        },
        {
            "name": "BuildingNameLocator",
            "link": 'https://services5.arcgis.com/g3r4E4Xlpygk5wEz/arcgis/rest/services/Buildings_Footprints/FeatureServer/8',
            "map": "'*Name' BldgName VISIBLE NONE"
        },
        {
            "name": "GasCurbValveLocator",
            "link": 'https://services5.arcgis.com/g3r4E4Xlpygk5wEz/arcgis/rest/services/Gas_Curb_Valve_GPS/FeatureServer/0',
            "map": "'*Name' ValveID VISIBLE NONE"
        },
        {
            "name": "GasMainValveLocator",
            "link": 'https://services5.arcgis.com/g3r4E4Xlpygk5wEz/arcgis/rest/services/GasValveLive/FeatureServer/0',
            "map": "'*Name' ValveID VISIBLE NONE"
        },
        {
            "name": "HydrantLocator",
            "link": 'https://services5.arcgis.com/g3r4E4Xlpygk5wEz/arcgis/rest/services/Hydrants/FeatureServer/3',
            "map": "*Name FACILITYID VISIBLE NONE"
        },
        {
            "name": "RoadIntersectionLocator",
            "link": 'https://services5.arcgis.com/g3r4E4Xlpygk5wEz/arcgis/rest/services/Roads/FeatureServer/31',
            "map": "*Name Alphatag VISIBLE NONE"
        },
        {
            "name": "WaterLateralValveLocator",
            "link": 'https://services5.arcgis.com/g3r4E4Xlpygk5wEz/arcgis/rest/services/Water_All_Valves/FeatureServer/2',
            "map": "*Name FACILITYID VISIBLE NONE"
        },
        {
            "name": "WaterMainValveLocator",
            "link": 'https://services5.arcgis.com/g3r4E4Xlpygk5wEz/arcgis/rest/services/Water_All_Valves/FeatureServer/2',
            "map": "*Name FACILITYID VISIBLE NONE"
        },
        {
            "name": "WaterTowerLocator",
            "link": 'https://services5.arcgis.com/g3r4E4Xlpygk5wEz/arcgis/rest/services/Water_Tower/FeatureServer/0',
            "map": "*Name FacilityID VISIBLE NONE"
        } 
    ]
    gis = GIS(profile='python_arcgis_credentials')
    arcpy.SignInToPortal("https://www.cfu.maps.arcgis.com")
    for locator in [locators[2]]:
        try:
            print(locator['name'])
            arcpy.geocoding.CreateFeatureLocator(
            in_features=locator['link'],
            output_locator=os.path.join(r"G:\Water_and_Gas_Operations\ArcGIS\Feature Locator Files", locator['name']),
            search_fields=locator['map'],            # Unique identifier field
            locator_fields=locator.get('etc')
        )
        except Exception as e:
            print(e)
    print('End')
0 Kudos
1 Reply
TonyAlmeida
Frequent Contributor

If the portal uses built-in security, provide a username and password.

gis = GIS(" portal_url", "username", "password")

 

Also, maybe use,

from arcgis.features import FeatureLayer

for locator in [locators[2]]:
    try:
        print(f"Creating locator for: {locator['name']}")
        layer = FeatureLayer(locator['link'])
        output_fc = "temp_layer"
        arcpy.conversion.FeatureClassToFeatureClass(layer, "in_memory", output_fc)

        arcpy.geocoding.CreateFeatureLocator(
            in_features=output_fc,
            output_locator=os.path.join(r"G:\Water_and_Gas_Operations\ArcGIS\Feature Locator Files", locator['name']),
            search_fields=locator['map'], 
            locator_fields=locator.get('etc')
        )
    except Exception as e:
        print(f"Error creating locator for {locator['name']}: {e}")
0 Kudos