Creating hurricane tracks using Geoanalytics¶
The sample code below uses big data analytics (GeoAnalytics) to reconstruct hurricane tracks using data registered on a big data file share in the GIS. Note that this functionality is currently available on ArcGIS Enterprise 10.5 and not yet with ArcGIS Online.
Reconstruct tracks¶
Reconstruct tracks is a type of data aggregation tool available in the arcgis.geoanalytics
module. This tool works with a layer of point features or polygon features that are time enabled. It first determines which points belong to a track using an identification number or identification string. Using the time at each location, the tracks are ordered sequentially and transformed into a line representing the path of movement.
Data used¶
For this sample, hurricane data from over a period of 50 years, totalling about 150,000 points split into 5 shape files was used. The National Hurricane Center provides similar datasets that can be used for exploratory purposes.
To illustrate the nature of the data a subset was published as a feature service and can be visualized as below:
from arcgis.gis import GIS
# Create an anonymous connection to ArcGIS Online
arcgis_online = GIS()
hurricane_pts = arcgis_online.content.search("Hurricane_tracks_points AND owner:atma.mani", "Feature Layer")[0]
hurricane_pts
subset_map = arcgis_online.map("USA")
subset_map
subset_map.add_layer(hurricane_pts)
Inspect the data attributes¶
Let us query the first layer in hurricane_pts and view its attribute table as a Pandas dataframe.
hurricane_pts.layers[0].query().df.head()
Create a data store¶
For the GeoAnalytics server to process your big data, it needs the data to be registered as a data store. In our case, the data is in multiple shape files and we will register the folder containing the files as a data store of type bigDataFileShare
.
Let us connect to an ArcGIS Enterprise
gis = GIS("https://yourportal.domain.com/webcontext", "username", "password")
Get the geoanalytics datastores and search it for the registered datasets:
# Query the data stores available
import arcgis
datastores = arcgis.geoanalytics.get_datastores()
bigdata_fileshares = datastores.search()
bigdata_fileshares
The dataset hurricanes_all
data is registered as a big data file share with the Geoanalytics datastore, so we can reference it:
data_item = bigdata_fileshares[3]
If there is no big data file share for hurricane track data registered on the server, we can register one that points to the shared folder containing the shape files.
data_item = datastores.add_bigdata("Hurricane_tracks", r"\\path_to_hurricane_data")
Once a big data file share is registered, the GeoAnalytics server processes all the valid file types to discern the schema of the data, including information about the geometry in a dataset. If the dataset is time-enabled, as is required to use some GeoAnalytics Tools, the manifest reports the necessary metadata about how time information is stored as well.
This process can take a few minutes depending on the size of your data. Once processed, querying the manifest property returns the schema. As you can see from below, the schema is similar to the subset we observed earlier in this sample.
data_item.manifest['datasets'][0] #for brevity only a portion is printed
Perform data aggregation using reconstruct tracks tool¶
When you add a big data file share, a corresponding item gets created in your GIS. You can search for it like a regular item and query its layers.
search_result = gis.content.search("", item_type = "big data file share")
search_result
data_item = search_result[4]
data_item
years_50 = data_item.layers[0]
years_50
Reconstruct tracks tool¶
The reconstruct_tracks()
function is available in the arcgis.geoanalytics.summarize_data
module. In this example, we are using this tool to aggregate the numerous points into line segments showing the tracks followed by the hurricanes. The tool creates a feature layer item as an output which can be accessed once the processing is complete.
from arcgis.geoanalytics.summarize_data import reconstruct_tracks
agg_result = reconstruct_tracks(years_50,
track_fields='Serial_Num',
method='GEODESIC')
Inspect the results¶
Let us create a map and load the processed result which is a feature service
processed_map = gis.map("USA")
processed_map