Polling a GTFS-Realtime feed. Have some logic in Node to decode the Protocol Buffer and manually massage into a format suitable for pushing into an ArcGIS Online Hosted feature service.
- Two example messages from my source back-end shown below. (typically around 3000-4000 messages in each packet)
- Created logic to push this into an destination ArcGIS Online Hosted Feature Service with same schema, currently using ApplyEdits.
- This push would happen every 30 seconds - (we need to be as efficient as possible)
- We only require the current location of each unique transit vehicle in the hosted feature service
- i.e. We do not care about its previous history/breadcrumb trail.
We are trying to push the real time vehicle locations from the GTFS-Realtime feed into a hosted feature service.
Problem is, we keep creating duplicate points, when we need to:
- Create new feature if the vehicle_id does not exist in destination feature service
- Update existing features if the vehicle_id does exist
I was initially looking at ApplyEdits, but then stumbled across Append Upsert capability on the root REST endpoint for a feature service.
But, struggling to get it to work.
The unique ID is going to be the vehicle_id on both sides.
Problem: Getting duplicate records every time we push the JSON using ApplyEdits.
The Append Upsert endpoint sounded like it was a better operation to use:
"Upsert is used to add new features and updating existing features at the same time. It is a high performance API capable of handling large volume of data."
"The destination objectId or globalId fields do not need to be mapped to source fields of the same type. Source featureId can come from different field type as long as the values are acceptable destination featureId value."
However, we have tried a few different approacheswe are struggling to get this to work.
It sounds like we can push our response to a hosted feature service and use our source ID of
vehicle_id (string), and potentially push this into a GlobalID (string)? We have a GlobalID on the destination feature service.
What would the params looks like for an Append Upsert with a foreign ID on the source?
A copy of the test service is here with the Append operation available and fully open:
We have also been pondering if we should be looking at leveraging ArcGIS-REST-JS? This does not appear to have an append function, but the updatefeatures approach might be a better approach to deal with responses, especially when we move this to using a secure hosted feature service.
Any tips or suggestions would be really appreciated.
This service will later be available for all to use via a view layer.