Hi,
I am trying to write a python script which will calculate a field data from one table to another table in a hosted feature service which is hosted in AGOL. The both table has 90K+ records and has a joinID field. which I use as query to calculate the data. I am using below code -
from arcgis import *
username = "user"
password = "password"
gis = GIS("https://www.arcgis.com", username=username, password=password)
# Get the feature service item ID
feature_service_item_id = "item_id"
# Access the feature service item
feature_service_item = gis.content.get(feature_service_item_id)
feature_service_tables = feature_service_item.tables
feature_service_layers = feature_service_item.layers
data_table = None
feat_layer = None
joinTable = None
for table in feature_service_tables:
if table.properties.name == 'feat_DataTable':
data_table = table
print("Table found: {}".format(data_table.properties.name))
elif table.properties.name == 'feat_linear_interpolation':
joinTable = table
print("Table found: {}".format(joinTable.properties.name))
for layer in feature_service_item.layers:
if layer.properties.name == 'featurelayer':
feat_layer = layer
print("Layer found: {}".format(feat_layer.properties.name))
query = "year = 1995"
result_set = joinTable.query(where=query,out_fields = ["joinID,year,F01_human_field"])
for feature in result_set.features:
joinID = feature.attributes["joinID"]
year = feature.attributes["year"]
dataValue = feature.attributes["F01_human_field"]
innerquery = "joinID = "+joinID
data_table.calculate(where=innerquery,
calc_expression={"field": "Data_Value", "value": dataValue})
data_table.calculate(where=innerquery,
calc_expression={"field": "year", "value": year})
the code is working but the issue is it is taking 25 minutes to calculate 3000 features which is impractical. is there any better approach to make the calculation efficient? Any code suggestions would be highly appreciated. I haven't find any method in API reference which batch calculate the whole lot in one go.
Thanks is advance.
Regards,
Tauhid