Current limitation
The FeatureLayer.calculate() method currently supports calculating field values using SQL expressions or scalar values. However, there is no direct way to apply an Arcade expression through this method.
This creates a gap for workflows that rely on Arcade for attribute calculation logic, particularly when the same expressions are already used in web maps, pop-ups, field calculations, attribute rules, or other ArcGIS applications.
Proposed enhancement
Add support for an Arcade expression parameter to FeatureLayer.calculate(), allowing users to calculate field values using Arcade in addition to the existing SQL and scalar-value options.
For example, an API implementation could support a pattern such as:
feature_layer.calculate(
where="1=1",
calc_expression={
"field": "TargetField",
"expression": "$feature.FieldA + $feature.FieldB"
}
)
Ideally, the method would support:
- Arcade expressions referencing fields in the current feature.
- Arcade functions and conditional logic.
- Consistent behavior with Arcade calculations available elsewhere in ArcGIS.
- Clear documentation and examples showing how to use Arcade expressions.
- Appropriate validation and error handling for unsupported expressions or data types.
Why this would be valuable
Consistency across the ArcGIS platform
Arcade is a core expression language in the ArcGIS ecosystem. Supporting it in the ArcGIS API for Python would provide a more consistent experience between Python-based workflows and other ArcGIS applications that already use Arcade.
For example, with ArcPy, you can easily count Points in Polygons with an Arcade expression:
arcpy.management.CalculateField(
in_table = polygon_features,
field = count_field,
expression = f"""var points = Filter(FeatureSetByName($datastore, "{point_features}", ["{where_clause.split(" ")[0]}"], false), "{where_clause}")
return Count(Intersects(points, $feature))""",
expression_type = "ARCADE"
)
However, an equivalent is not readily available with the ArcGIS API for Python.
More expressive calculation logic
SQL expressions and scalar values are useful, but Arcade provides additional capabilities for conditional logic, string manipulation, date handling, geometry-related calculations, and other feature-level operations. Users could perform more sophisticated calculations without having to construct complex SQL statements or write separate Python processing logic.
Reuse of existing Arcade expressions
Organizations often maintain Arcade expressions for web maps, pop-ups, attribute rules, and other applications. Being able to reuse that logic in Python workflows would reduce duplication and help ensure that calculations remain consistent across applications.
Enhanced processing
Without Arcade support, users need to retrieve features, calculate values in Python, and write the results back to the feature layer. Supporting Arcade would allow calculations to be performed more efficiently and could reduce data transfer, processing overhead, and the complexity of scripts.
The example shown with ArcPy above requires a more convoluted workflow with the ArcGIS API for Python querying features, creating and using geometry filters, storing the results in a feature set, and then applying the updates back to the original feature layer.
See this blog post for example.
Suggested outcome
Enhance the FeatureLayer.calculate() method to support Arcade expressions alongside the existing SQL and scalar-value calculation options, using a syntax consistent with the ArcGIS REST API.
This would make attribute calculation workflows more consistent, expressive, and maintainable across the ArcGIS platform.