Hello,
I am trying to develop a python script that calls data from an API and updates a pre-existing hosted table in AGOL. I have the script updating the table correctly. The issue I have is the data points are not geocoding even with lat/long provided by the API. I have tried to geocode it a few ways and converting it to a feature layer but haven't had much luck. Anyone have tips for geocoding the updated data in the hosted table? What specific geocode operation should I use?
Here is what I have so far:
from arcgis.geocoding import geocode_from_items
import requests, json
from arcgis import GIS
# Variables
username = "" # AGOL Username
password = "" # AGOL Password
itemID = '' # AGOL Table Item ID
dataURL = 'API Key'
# Disable warnings
requests.packages.urllib3.disable_warnings()
# Connect to AGOL
print("Connecting to AGOL")
gis = GIS('https://www.arcgis.com', username, password)
# Get Table
print("Get Hosted Table")
fLayer = gis.content.get(itemID)
editTable = fLayer.tables[0]
# Truncate Table
print("Truncate table")
editTable.manager.truncate()
# Get Data
print("Retrieving Data")
r = requests.get(dataURL, verify=False)
response = json.loads(r.content)
data = response['results']
# Create Dictionary of attributes and update table
print("Updating hosted table")
for attr in data:
addFeatures = {
"attributes" : {
"id" : attr['id'],
"latitude" : attr['latitude'],
"longitude" : attr['longitude'],
"location" : attr['location'],
"description": attr['description'],
"gategory": attr['category'],
"direction": attr['direction'],
"routeName": attr['routeName'],
"roadStatus":attr['roadStatus'],
}
}
# Update Table
editTable.edit_features(adds=[addFeatures])
print("Updated")
locate_item = editTable
locate_item
fl_item = geocode_from_items(locate_item, output_type='Feature Layer',
output_name="locate_OHGOapi",
gis=gis)
Thanks!