Introduction
In Part 1, we built a system that ingests moving vehicle location data using AWS IoT Core, snaps it to a road network using ArcGIS Velocity's [Snap to Network] tool, and outputs the corrected data to an Amazon MSK Kafka topic.
Part 1:Building a Real-Time Processing Platform for Moving Vehicle Data with ArcGIS Velocity and AWS (Part 1)
In Part 2, we aggregate this snapped vehicle data using a Python program running on Amazon ECS Fargate and calculate the number of vehicles on each road. We also show how to ingest the aggregated results into ArcGIS Velocity, publish them as a stream layer, and dynamically visualize them in ArcGIS Online Map Viewer.
The overall architecture of the processing platform described in Parts 1 and 2 is as follows.
Let's start by looking at how to aggregate the data received from Amazon MSK by road name.
Custom Processing on Amazon ECS
First, we'll deploy custom processing to read the snapped vehicle data output to Amazon MSK in Part 1 and aggregate the number of vehicles by road name.
For this project, we created the custom processing in Python and ran it as a container on Amazon ECS Fargate. Using Amazon ECS Fargate lets us run containerized processing continuously without having to manage EC2 instances individually.
This article uses kafka-python as the module for connecting Python to Kafka. kafka-python provides KafkaConsumer for reading messages from Kafka topics and KafkaProducer for sending messages to Kafka topics. In this custom processing, KafkaConsumer reads the velocity-snapped-vehicles topic, and KafkaProducer sends the aggregated results by road name to the velocity-name-counts topic.
Specifically, we created processing logic like the following:
- Read the Amazon MSK velocity-snapped-vehicles topic
- Track which road each vehicle is currently on
- Aggregate the current vehicle count for each road name
- Send the aggregated results to the Amazon MSK velocity-name-counts topic
This processing uses Python dictionaries to track each vehicle's current location and the number of vehicles on each road. Specifically, the first dictionary uses deviceId as the key and stores which road each vehicle is currently on and when its data was last received. The second dictionary uses the road name as the key and stores the number of vehicles currently on that road.
The aggregated results sent to the Amazon MSK topic use the following JSON format:
{
"name": "Road name",
"count": 5,
"updated_at": "2026-06-17T00:00:00Z"
}
In this prototype, we used a dictionary in the Python program to make it easier to understand how the current state of each vehicle is tracked. However, the dictionary contents are lost if the container restarts, so a different approach to state management should be considered for production use. For a more robust architecture, one option is to use Amazon DynamoDB or Amazon ElastiCache for Redis instead of a dictionary, and store each vehicle's current state and the aggregated values for each road externally.
In addition to creating custom processing in Python and running it on Amazon ECS Fargate as we did here, AWS also offers services for stream data processing. For example, Amazon Managed Service for Apache Flink can be used to implement time-window aggregations and stateful processing on stream data in a way that is more purpose-built for stream processing.
Ingesting Aggregated Results into ArcGIS Velocity and Converting Them to a Stream Layer
As a final step, we'll ingest the results aggregated by road name and output from the custom processing on Amazon ECS to Amazon MSK back into ArcGIS Velocity, andstream layerconvert them to a
In ArcGIS Velocity, you can receive messages sent to a Kafka topic in real time by selecting Kafka as the feed type. Here, we'll create a Kafka feed that reads the Amazon MSK velocity-name-counts topic.
For the Kafka feed settings, use the same values for the broker and authentication information as when configuring the Kafka output in the previous step. For the topic, specify velocity-name-counts, which receives the aggregation results from the custom Python processing.
Next, we'll join the aggregated results by road name received through the Kafka feed with the road network feature layer, then output the road network with the vehicle aggregation results as a stream layer. Here, we join the name field in the road network with the name field in the aggregated results received through the Kafka feed.
* Because this is a one-to-one join, create a separate road network feature layer for the join, with one feature per road name, if needed.
Visualizing Real-Time Aggregated Results by Road Name on a Map
We'll send test data to AWS IoT Core, the entry point for the processing platform prototyped here, then add the resulting stream layer to ArcGIS Online Map Viewer to verify that everything works.
We created test data representing vehicle trajectories with simulated GPS location accuracy errors using the following steps, and sent it to AWS IoT Core.
- Use the [Create Random Points] tool in ArcGIS Pro to create multiple sets of point data representing starting and ending points
- Using the starting and ending point data as input, repeatedly run route searches against the ArcGIS Geo Suite road network with vehicle-specific restrictions to create line data representing each vehicle's route
- Use the [Densify] tool in ArcGIS Pro to add vertices to the line data
- Read the vertex information in a Python script, then randomly offset the longitude and latitude of each vertex using the ArcPy, math, and random modules
- Use boto3's IoTDataPlane.Client.publish() to sequentially send each vertex's longitude and latitude to AWS IoT Core as MQTT messages representing vehicle trajectory data
In ArcGIS Online Map Viewer, you can visualize the stream layer so that road line symbols and labels change in real time according to the number of vehicles on each road by applying settings such as the following.
- Symbol Styling
- Under Select attribute, select count (number of vehicles); under Select style, select Counts and Amounts (Size). Under Symbol style, select Animated.
- Effects
- For the entire layer, enable “Bloom” and “Drop shadow.” For individual features, enable “Bloom + Gray” and set the threshold for displaying features based on count (number of vehicles).
- Labels
- Enable labels and set the label fields to name (road name) and count (number of vehicles). Under Edit label filter, set the threshold for displaying labels based on count (number of vehicles).
Summary
In this project, we aggregated by road name the vehicle data that was snapped to the road network and output to Amazon MSK in Part 1, using a Python program on Amazon ECS Fargate, then published it as a stream layer using ArcGIS Velocity. We also used ArcGIS Online Map Viewer to verify real-time symbol and label styling based on the number of vehicles on each road.
By integrating ArcGIS Velocity real-time analytics with custom stream processing using Amazon MSK and Amazon ECS Fargate, we were able to build an end-to-end process from snapping locations to a road network and aggregating by road name to visualizing the results on a map.
Across Parts 1 and 2, we presented an example of a real-time GIS processing platform that combines ArcGIS Velocity with AWS managed services and extends functionality externally as needed. Combining these services is one effective option for building GIS data processing workflows tailored to your objectives.
Related Links
- ArcGIS
- Amazon Web Services
- Python