[Solved] Auto parse a ton of nested data?

geofence
workflow

#1

I have an HTTP node that is replying with a ton of nested values (233 in this case). I’d like to parse them out automatically so that I can quickly pass all the GPS values to a geofence polygon.
I know its possible but cant figure out how. Any help welcome


#2

I would recommend a Loop Node and pass it the shell array as the input. Inside the loop you’d add a Geofence Node to do the check. The Geofence Node takes a template, so you can combine the lat and lng values using the following template as the input to the Geofence Node:

{{ working.item.value.lat }}, {{ working.item.value.lng }}

The above template makes an assumption that you put each object in the array on the working.item payload path in the Loop Node configuration.


#3

I had actually read your question as “How do I construct a geofence out of all these coordinates”, instead of how Brandon read it (“How do I check each coordinate against a geofence”). If the former is what you were after, then I built a simple workflow that would do what you’re looking for: deep looping over each of the arrays on your payload and building one geofence object. You can then reference that value by payload path in the Geofence Node.

Sample workflow is attached.

coordinate-conversion-develop (1).flow (6.6 KB)


#4

Excellent thank you @Dylan_Schuster and @Brandon_Cannaday. Going to try the flow out - hadnt considered the deep loop. To be clear though I was hoping to pull all the separate “lat” “lng” values into a single object that could be passed to the geofence node to dynamically build a fence with one API call.
Specifically passing into the geofence node: Polygonal Geofence (Payload Path) mode.

So, from the above image API return into below image automatically.


#5

@Christopher_Penney if results and shapes will each only ever have one item - as they do in your original example - you could dramatically simplify that workflow to just have one Loop Node, iterating over data.body.results.0.shapes.0.shell. I just built the nested loops in case your screenshot wasn’t of a typical workflow run in your application.


#6

Great works perfectly now thank you!
I didnt realize that the payload path method of the geofence node would not return an image/embedded map like the other two methods - makes sense that it doesnt though as its payload dependent.
That makes me wonder now if there is an easy way to transform the data.myGeofence values to an output that we can use in a mapbox embed (see code below)
I feel like thats another loop on the data.myGeofence list and a transform to add the [ ] brackets, push to experience pageData, embed mapbox on a page, and pass it in with the {{ }} guys.

Is there any limit to loop layers? Is 4 too many? Feels like inception

   map.addLayer({
        'id': 'maine',
        'type': 'fill',
        'source': {
            'type': 'geojson',
            'data': {
                'type': 'Feature',
                'geometry': {
                    'type': 'Polygon',
                    'coordinates': [[[-67.13734351262877, 45.137451890638886],
                        [-66.96466, 44.8097],
                        [-68.03252, 44.3252],
                        [-69.06, 43.98],
                        [-70.11617, 43.68405],
                        [-70.64573401557249, 43.090083319667144],
                        [-70.75102474636725, 43.08003225358635],
                        [-70.79761105007827, 43.21973948828747],
                        [-70.98176001655037, 43.36789581966826],
                        [-70.94416541205806, 43.46633942318431],
                        [-71.08482, 45.3052400000002],
                        [-70.6600225491012, 45.46022288673396],
                        [-70.30495378282376, 45.914794623389355],
                        [-70.00014034695016, 46.69317088478567],
                        [-69.23708614772835, 47.44777598732787],
                        [-68.90478084987546, 47.184794623394396],
                        [-68.23430497910454, 47.35462921812177],
                        [-67.79035274928509, 47.066248887716995],
                        [-67.79141211614706, 45.702585354182816],
                        [-67.13734351262877, 45.137451890638886]]]
                }

#7

It looks like Mapbox expects the format to be an array of arrays of arrays …

[ // these are each a separate polygon
  [ // these are sets of points that make a polygon
    [ longitudeAsNumber, latitudeAsNumber ], // each of these is a point
    ...
  ]
]

So yes, it would be quite easy to build this array using a modified version of the workflow I provided before. You’d want to create a new array within the innermost loop, cast your latitude and longitude to numbers (as they’re strings in your original data set), and insert them in the proper order (longitude first). Then push that new array into your data.myGeofence array (which itself should become an array nested in another array).