"jams": [
{
"country": "AS",
"city": "Deception Bay",
"level": 5,
"line": [
{
"x": 153.029946,
"y": -27.193773
},
{
"x": 153.029894,
"y": -27.194082
}
],
"speedKMH": 0,
"length": 35,
"turnType": "NONE",
"type": "NONE",
"uuid": 74115178,
"speed": 0,
"segments": [
{}
],
"blockingAlertUuid": "d390204c-634f-4a2f-832e-54bbb14131e6",
"roadType": 20,
"delay": -1,
"pubMillis": 1667099170082
},
[{"x":152.516454,"y":-27.51705},{"x":152.50828,"y":-27.515946}] |
However, due to how the coordinates are currently formatted, I get the following error in the logs:
WARN: Failed to parse geometry field 'line'. Please make sure your geometry field string is valid. |
What would the optimal way to parse this JSON feed so that I can ingest it and persist the lines into a spatiotemporal feature layer?
Solved! Go to Solution.
@brudo Thanks much for your reply and these ideas, I was just discussing with a coworker the use of a for loop workflow to generate the path array and what you proposed should work as expected.
@SimonGIS As an FYI, these are alternate solutions that would better scale to variable length polylines when compared to the solution I provided that only accommodated a two-point polyline.
Coming back to edit, the following Arcade structure worked in test:
var path = [];
var i = 0;
var lineArray = FromJSON($feature.line)
for (var linePoint in lineArray) {
var xVal = lineArray[i]["x"];
var yVal = lineArray[i]["y"];
path[i] = [xVal, yVal]
i++
}
return Polyline({
"hasM": false,
"hasZ": false,
"paths": [path],
"spatialReference": {"wkid": 4326}
})
@SimonGIS Thanks for reaching out with the question! I have an answer/solution below, but it depends on a few elements. Overall, the answer is that Velocity "single geometry field" supports EsriJSON, GeoJSON, WKT, and Coordinates (point). This Waze format is not any of those, therefore you would need to use an Arcade expression to build the geometry.
https://doc.arcgis.com/en/iot/ingest/define-location-properties.htm
Additional considerations:
var lineArray = FromJSON($feature.line);
var x1 = lineArray[0]["x"];
var y1 = lineArray[0]["y"];
var x2 = lineArray[1]["x"];
var y2 = lineArray[1]["y"];
return Polyline({
"hasM": false,
"hasZ": false,
"paths": [
[
[x1,y1],
[x2,y2]
]
],
"spatialReference": {"wkid": 4326}
})
As you can see above, we use the "FromJSON" function to convert the JSON string to a proper object, we parse the desired elements out, and then we send that into a "Polyline" function using the EsriJSON format. This is configured in the Calculate Fields or Map Fields tool for the geometry configuration.
If the line can contain more vertices, here are a few options:
var path = Replace(Replace(Replace(Replace($feature.line,
'{', '['), '}', ']'), '"x":',''), '"y":','')
return Polyline({
"hasM": false,
"hasZ": false,
"paths": [FromJSON(path)],
"spatialReference": {"wkid": 4326}
})
var path = []
var i = 0
for (var c in FromJSON($feature.line)) {
path[i] = [c.x, c.y]
i++
}
return Polyline({
"hasM": false,
"hasZ": false,
"paths": [path],
"spatialReference": {"wkid": 4326}
})
@brudo Thanks much for your reply and these ideas, I was just discussing with a coworker the use of a for loop workflow to generate the path array and what you proposed should work as expected.
@SimonGIS As an FYI, these are alternate solutions that would better scale to variable length polylines when compared to the solution I provided that only accommodated a two-point polyline.
Coming back to edit, the following Arcade structure worked in test:
var path = [];
var i = 0;
var lineArray = FromJSON($feature.line)
for (var linePoint in lineArray) {
var xVal = lineArray[i]["x"];
var yVal = lineArray[i]["y"];
path[i] = [xVal, yVal]
i++
}
return Polyline({
"hasM": false,
"hasZ": false,
"paths": [path],
"spatialReference": {"wkid": 4326}
})
I have lines! Thanks @brudo and @PeterNasuti
I ended up using Peter's arcade snippet. Working well so far. No performance issues from my side.
Thanks again.
Hi Peter,
I tried to do the same thing with the ARCADE from REAL TIME analytics to calculate the GEOMETRY field. Somehow, when you click the $feature.line, it shows as "pacific" instead of "X,Y" string arrays like your screen shot displayed on the right content. The feeds come in OK and I use Location as NONE. Do you think I miss something? Thanks
Hey @chunguangWayneZhang - I missed that out, and I had same issue. Peter saved the day:
Pacific is the Arcade “sample value” for a string field, which line is a string field
To resolve this, in the Arcade editor on the right click the Globals tab, click the arrow at the right of the $feature element, find $feature.line, click the edit pencil, and paste the valid JSON of the line element (not wrapped in quotations).
Then, testing the Arcade expression will evaluate against that sample:
For example, try this test string to use in place of Pacific under $feature.line
[{"x":153.029946,"y":-27.193773},{"x":154.029894,"y":-28.194082},{"x":155.029894,"y":-29.194082}]