The Run Python Script task allows you to programmatically execute most GeoAnalytics Tools with Python using an API that is available when you run the task. A geoanalytics
object is instantiated automatically and gives you access to each tool using the syntax shown in the example and table below. Each tool accepts input layers as Spark DataFrames and will return results as a Spark DataFrame or collection of Spark DataFrames. To learn more, see Reading and writing layers in pyspark. DataFrames are held in memory and can be written to a data store at any time. This allows you to chain together multiple GeoAnalytics Tools without writing out intermediate results.
In the example below, the Detect Incidents task and Find Hot Spots task are used together and only the final DataFrame is written to a data store as a feature service layer. The input layer (represented in the example below by layers[0]
) is a big data file share dataset of city bus locations recorded at 1-minute intervals for 15 days. To learn more about using layers, see Reading and writing layers in pyspark.
import time
# Run Detect Incidents to find all bus locations where delay status has changed from False to True
exp = "var dly = $track.field[\"dly\"].history(-2); return dly[0]==\"False\" && dly[1]==\"True\""
delay_incidents = geoanalytics.detect_incidents(
input_layer = layers[0],
track_fields = ["vid"],
start_condition_expression = exp,
output_mode = "Incidents")
# Use the resulting DataFrame as input to the Find Hot Spots task
delay_hotspots = geoanalytics.find_hot_spots(
point_layer = delay_incidents,
bin_size = 0.1,
bin_size_unit = "Miles",
neighborhood_distance = 1,
neighborhood_distance_unit = "Miles",
time_step_interval = 1,
time_step_interval_unit = "Days")
# Write the Find Hot Spots result to the spatiotemporal big data store
delay_hotspots.write.format("webgis").save("Bus_Delay_HS_{0}".format(time.time()))
For more examples, see Examples: Scripting custom analysis with the Run Python Script task.
The table below describes the method signature for GeoAnalytics Tools in Run Python Script. All tools can be called except for Copy To Data Store and Append Data. The parameter syntax is the same as that of the REST API except where noted. See the documentation for each tool for descriptions of parameter syntax and tool outputs.
Tool | Syntax | Returns | Notes |
---|---|---|---|
| DataFrame | ||
| DataFrame |
| |
| DataFrame | ||
| DataFrame | ||
| DataFrame | ||
| DataFrame | ||
| DataFrame | ||
| String | Returns the local path to the resulting space-time cube on a ArcGIS GeoAnalytics Server machine. The cube is written to a temp directory and will be deleted if not copied to a different location. | |
| Dictionary | Example result:
| |
| DataFrame | ||
| DataFrame | ||
| DataFrame | ||
| DataFrame | ||
| DataFrame | ||
| DataFrame | ||
| Dictionary | Example result:
| |
| Dictionary | Example result:
| |
| Dictionary | Example result:
| |
| DataFrame | ||
| DataFrame | ||
| DataFrame | ||
| DataFrame | ||
| DataFrame | ||
| DataFrame | ||
| DataFrame | ||
| DataFrame | ||
| Dictionary | Example result:
| |
| Dictionary | Example result:
| |
| Dictionary | Example result:
|
In addition to the tools listed above, a project
tool is provided with the geoanalytics
package that allows you to project the geometry of a DataFrame into the specified spatial reference.
Tool | Syntax | Returns | Notes |
---|---|---|---|
Project |
| DataFrame |
Example:
|