Skip to main content

Collections

How to work with multiple items as a data structure

Holly Conrad Smith avatar
Written by Holly Conrad Smith
Updated this week

When we talk about collections in programming, we mean any structure that holds together multiple items — like a container for data. Collections make it easier for software to manage, organize, and work with groups of things.

Think of a collection like a physical box where you can store things. But depending on how the box is built, what you store in it, and how you use it, that box behaves very differently. In code, “how the box works” depends on what type of collection you choose.

Take a herd (or tower) of Giraffes, for example. You could consider each Giraffe an item within the list (or herd). A scientist studying Giraffes would likely study groups of animals rather than treating each Giraffe individually - the same is true of a computer program processing collections.

This is not a collection. it is a single item - one Giraffe

This is a collection - a herd of Giraffes.

Types of Collections

Here are some common kinds of collections you might encounter with Flow, and how they differ:

Lists

  • Ordered: The order in which items are added matters.

  • Allows duplicates: You can have the same item multiple times.

Example use: The lengths of multiple lines, the areas of multiple polygons

Sets

  • Unordered: There’s no meaningful “first” or “last.”

  • Unique items only: Duplicate entries are not allowed.

Example use: The usages in your project, the IDs of the geometries in your project

Dictionary

  • Stores pairs of information: each item has a key (like a label) and a value (the data attached to that label).

  • Great for fast lookup: you don’t search through a list — you jump straight to the value using its key.

Example use: Looking up values by their key - ie the height of a building by its building id

Working with collections

Collections, by virtue of being a data structure containing multiple items, are more efficient for computation than processing lots of unique individual items. However, working with collections does require some additional logic in the set up of our Flows to process.

Identify a collection

Simply, you can tell if a data structure is a collection if it contains multiple items. You might ask, how can I tell if a structure contains multiple items?

The easiest way to know is if what you would expect to see resulting on the map is more than one basic geometry. For instance:

This is not a collection.

It is a single rectangle.

This is a collection.

This is the same rectangle with the subdivide lots transform applied, which divides the original geometry into multiple sub-geometries.

Any processing is done to just the single element

Any processing must lop through all of the items in the list

Here is what these elements look like in code:

    {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"color": "#8A9BA8",
"stroke": "black",
"strokeWidth": 1,
"projectId": "scratchpad",
"appId": "1",
"public": true,
"layerId": "default",
"id": "GVG_t5vibWZ1AaUWW3CtF",
"_opacity": 1,
"perimeter": 243.83944968436765,
"area": 3716.104826340844,
"grossArea": 3716.104826340844,
"ix": 0,
"_baseHeight": 0,
"_height": 0,
"_baseElevation": 0
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-75.16261944,
39.95553125
],
[
-75.16261941,
39.95498223
],
[
-75.16190601,
39.95498225
],
[
-75.16190603,
39.95553127
],
[
-75.16261944,
39.95553125
]
]
]
},
"_projected": [
[
[
-359.69540145467204,
44.281470220535994
],
[
-359.6957140980458,
-16.67819932755083
],
[
-298.73584231855097,
-16.6786110624671
],
[
-298.7351626179548,
44.281058450229466
],
[
-359.69540145467204,
44.281470220535994
]
]
]
}
]
}

Notice how the original rectangle has only 1 feature?

Here is what these elements look like in code:

    {      "type": "FeatureCollection",      "features": [        {          "type": "Feature",          "properties": {            "color": "#8A9BA8",            "stroke": "black",            "strokeWidth": 1,            "id": "41icmmcHIIbHZ1c6ZCxTN",            "projectId": "scratchpad",            "appId": "1",            "public": true,            "layerId": "default",            "frontage": 20.32007959519211,            "area": 619.3517359209018,            "frontageCenter": [              -240.15567800114138,              44.28105754498392            ],            "isEndcap": false,            "ix": 0,            "_opacity": 1,            "perimeter": 101.59976752863466,            "grossArea": 619.3517359209018,            "_baseHeight": 0,            "_height": 0,            "_baseElevation": 0          },          "_projected": [            [              [                -250.31572164984112,                13.801384840160608              ],              [                -229.99570323406883,                13.801060691475868              ],              [                -229.9956382048387,                44.28089544828981              ],              [                -250.31571779697003,                44.2812195988372              ],              [                -250.31572164984112,                13.801384840160608              ]            ]          ],          "geometry": {            "type": "Polygon",            "coordinates": [              [                [                  -75.16133937166664,                  39.9552567771608                ],                [                  -75.16110156999996,                  39.95525678000636                ],                [                  -75.16110158,                  39.95553128999981                ],                [                  -75.16133938333334,                  39.955531287154265                ],                [                  -75.16133937166664,                  39.9552567771608                ]              ]            ]          }        },        {          "type": "Feature",          "properties": {            "color": "#8A9BA8",            "stroke": "black",            "strokeWidth": 1,            "id": "41icmmcHIIbHZ1c6ZCxTN",            "projectId": "scratchpad",            "appId": "1",            "public": true,            "layerId": "default",            "frontage": 20.32007959519211,            "area": 619.3517360561436,            "frontageCenter": [              -260.475757593748,              44.281381697393954            ],            "isEndcap": false,            "ix": 1,            "_opacity": 1,            "perimeter": 101.59976754314064,            "grossArea": 619.3517360561436,            "_baseHeight": 0,            "_height": 0,            "_baseElevation": 0          },          "_projected": [            [              [                -270.63574006635497,                13.801708983257413              ],              [                -250.31572164984112,                13.801384840160608              ],              [                -250.31571779697003,                44.2812195988372              ],              [                -270.63579738984276,                44.28154375310987              ],              [                -270.63574006635497,                13.801708983257413              ]            ]          ],          "geometry": {            "type": "Polygon",            "coordinates": [              [                [                  -75.1615771733333,                  39.955256773827436                ],                [                  -75.16133937166664,                  39.9552567771608                ],                [                  -75.16133938333334,                  39.955531287154265                ],                [                  -75.16157718666669,                  39.95553128382094                ],                [                  -75.1615771733333,                  39.955256773827436                ]              ]            ]          }        },        {          "type": "Feature",          "properties": {            "color": "#8A9BA8",            "stroke": "black",            "strokeWidth": 1,            "id": "41icmmcHIIbHZ1c6ZCxTN",            "projectId": "scratchpad",            "appId": "1",            "public": true,            "layerId": "default",            "frontage": 20.320079595192137,            "area": 619.3517362049015,            "frontageCenter": [              -280.7958371863547,              44.281705849803984            ],            "isEndcap": false,            "ix": 2,            "_opacity": 1,            "perimeter": 101.5997675600209,            "grossArea": 619.3517362049015,            "_baseHeight": 0,            "_height": 0,            "_baseElevation": 0          },          "_projected": [            [              [                -290.95575848281186,                13.802033130079508              ],              [                -270.63574006635497,                13.801708983257413              ],              [                -270.63579738984276,                44.28154375310987              ],              [                -290.95587698265876,                44.2818679055199              ],              [                -290.95575848281186,                13.802033130079508              ]            ]          ],          "geometry": {            "type": "Polygon",            "coordinates": [              [                [                  -75.16181497499994,                  39.955256770006315                ],                [                  -75.1615771733333,                  39.955256773827436                ],                [                  -75.16157718666669,                  39.95553128382094                ],                [                  -75.16181499,                  39.95553127999982                ],                [                  -75.16181497499994,                  39.955256770006315                ]              ]            ]          }        },        {          "type": "Feature",          "properties": {            "color": "#8A9BA8",            "stroke": "black",            "strokeWidth": 1,            "id": "41icmmcHIIbHZ1c6ZCxTN",            "projectId": "scratchpad",            "appId": "1",            "public": true,            "layerId": "default",            "frontage": 20.31995724242227,            "area": 619.349871414377,            "frontageCenter": [              -240.15574688290704,              -16.678611977491528            ],            "isEndcap": false,            "ix": 3,            "_opacity": 1,            "perimeter": 101.59964518905917,            "grossArea": 619.349871414377,            "_baseHeight": 0,            "_height": 0,            "_baseElevation": 0          },          "_projected": [            [              [                -250.31572550343796,                -16.678449926897883              ],              [                -229.9957682629892,                -16.678774069063365              ],              [                -229.99570323406883,                13.801060691475868              ],              [                -250.31572164984112,                13.801384840160608              ],              [                -250.31572550343796,                -16.678449926897883              ]            ]          ],          "geometry": {            "type": "Polygon",            "coordinates": [              [                [                  -75.16133936000003,                  39.95498226715426                ],                [                  -75.16110156,                  39.95498226999982                ],                [                  -75.16110156999996,                  39.95525678000636                ],                [                  -75.16133937166664,                  39.9552567771608                ],                [                  -75.16133936000003,                  39.95498226715426                ]              ]            ]          }        },        {          "type": "Feature",          "properties": {            "color": "#8A9BA8",            "stroke": "black",            "strokeWidth": 1,            "id": "41icmmcHIIbHZ1c6ZCxTN",            "projectId": "scratchpad",            "appId": "1",            "public": true,            "layerId": "default",            "frontage": 20.31995724242227,            "area": 619.3498714502466,            "frontageCenter": [              -260.475704122744,              -16.678287835326046            ],            "isEndcap": false,            "ix": 4,            "_opacity": 1,            "perimeter": 101.5996451948716,            "grossArea": 619.3498714502466,            "_baseHeight": 0,            "_height": 0,            "_baseElevation": 0          },          "_projected": [            [              [                -270.63568274245387,                -16.67812578380108              ],              [                -250.31572550343796,                -16.678449926897883              ],              [                -250.31572164984112,                13.801384840160608              ],              [                -270.63574006635497,                13.801708983257413              ],              [                -270.63568274245387,                -16.67812578380108              ]            ]          ],          "geometry": {            "type": "Polygon",            "coordinates": [              [                [                  -75.16157716000002,                  39.95498226382094                ],                [                  -75.16133936000003,                  39.95498226715426                ],                [                  -75.16133937166664,                  39.9552567771608                ],                [                  -75.1615771733333,                  39.955256773827436                ],                [                  -75.16157716000002,                  39.95498226382094                ]              ]            ]          }        },        {          "type": "Feature",          "properties": {            "color": "#8A9BA8",            "stroke": "black",            "strokeWidth": 1,            "id": "41icmmcHIIbHZ1c6ZCxTN",            "projectId": "scratchpad",            "appId": "1",            "public": true,            "layerId": "default",            "frontage": 20.31995724242227,            "area": 619.349871502026,            "frontageCenter": [              -280.79566136258086,              -16.677963693160564            ],            "isEndcap": false,            "ix": 5,            "_opacity": 1,            "perimeter": 101.5996452016631,            "grossArea": 619.349871502026,            "_baseHeight": 0,            "_height": 0,            "_baseElevation": 0          },          "_projected": [            [              [                -290.95563998250014,                -16.67780164256692              ],              [                -270.63568274245387,                -16.67812578380108              ],              [                -270.63574006635497,                13.801708983257413              ],              [                -290.95575848281186,                13.802033130079508              ],              [                -290.95563998250014,                -16.67780164256692              ]            ]          ],          "geometry": {            "type": "Polygon",            "coordinates": [              [                [                  -75.16181496,                  39.95498225999981                ],                [                  -75.16157716000002,                  39.95498226382094                ],                [                  -75.1615771733333,                  39.955256773827436                ],                [                  -75.16181497499994,                  39.955256770006315                ],                [                  -75.16181496,                  39.95498225999981                ]              ]            ]          }        },        {          "type": "Feature",          "properties": {            "color": "#8A9BA8",            "stroke": "black",            "strokeWidth": 1,            "id": "41icmmcHIIbHZ1c6ZCxTN",            "projectId": "scratchpad",            "appId": "1",            "public": true,            "layerId": "default",            "ix": 6,            "_opacity": 1,            "perimeter": 85.59976000591527,            "area": 432.15214961654146,            "grossArea": 432.15214961654146,            "_baseHeight": 0,            "_height": 0,            "_baseElevation": 0          },          "_projected": [            [              [                -231.99564000012893,                42.28091997932643              ],              [                -248.31571000040273,                42.28117998223752              ],              [                -248.3157200001323,                15.80134998075664              ],              [                -231.99568999978123,                15.801089979708195              ],              [                -231.99564000012893,                42.28091997932643              ]            ]          ],          "geometry": {            "type": "Polygon",            "coordinates": [              [                [                  -75.16112498505697,                  39.955513277110946                ],                [                  -75.16131597673153,                  39.95551327482248                ],                [                  -75.16131596675504,                  39.95527479000072                ],                [                  -75.16112497621197,                  39.955274792289174                ],                [                  -75.16112498505697,                  39.955513277110946                ]              ]            ]          }        },        {          "type": "Feature",          "properties": {            "color": "#8A9BA8",            "stroke": "black",            "strokeWidth": 1,            "id": "41icmmcHIIbHZ1c6ZCxTN",            "projectId": "scratchpad",            "appId": "1",            "public": true,            "layerId": "default",            "ix": 7,            "_opacity": 1,            "perimeter": 85.5997600033381,            "area": 432.15214957748503,            "grossArea": 432.15214957748503,            "_baseHeight": 0,            "_height": 0,            "_baseElevation": 0          },          "_projected": [            [              [                -252.31570999958197,                42.28123997990042              ],              [                -268.6357799998948,                42.28150998055935              ],              [                -268.635749999838,                15.801679979078472              ],              [                -252.31572000053495,                15.801409982144833              ],              [                -252.31570999958197,                42.28123997990042              ]            ]          ],          "geometry": {            "type": "Polygon",            "coordinates": [              [                [                  -75.16136278821567,                  39.955513274180014                ],                [                  -75.16155377989021,                  39.95551327158983                ],                [                  -75.16155376861965,                  39.95527478676809                ],                [                  -75.16136277807661,                  39.95527478935827                ],                [                  -75.16136278821567,                  39.955513274180014                ]              ]            ]          }        },        {          "type": "Feature",          "properties": {            "color": "#8A9BA8",            "stroke": "black",            "strokeWidth": 1,            "id": "41icmmcHIIbHZ1c6ZCxTN",            "projectId": "scratchpad",            "appId": "1",            "public": true,            "layerId": "default",            "ix": 8,            "_opacity": 1,            "perimeter": 85.59975000757865,            "area": 432.1520172079113,            "grossArea": 432.1520172079113,            "_baseHeight": 0,            "_height": 0,            "_baseElevation": 0          },          "_projected": [            [              [                -272.6357799994694,                42.28156998194754              ],              [                -288.9558599999041,                42.281829978339374              ],              [                -288.9557600003147,                15.80199997778982              ],              [                -272.63574999954903,                15.801739980466664              ],              [                -272.6357799994694,                42.28156998194754              ]            ]          ],          "geometry": {            "type": "Polygon",            "coordinates": [              [                [                  -75.16160059137435,                  39.95551327085135                ],                [                  -75.16179158316591,                  39.95551326777931                ],                [                  -75.16179157025019,                  39.95527478295763                ],                [                  -75.16160057994121,                  39.95527478602962                ],                [                  -75.16160059137435,                  39.95551327085135                ]              ]            ]          }        },        {          "type": "Feature",          "properties": {            "color": "#8A9BA8",            "stroke": "black",            "strokeWidth": 1,            "id": "41icmmcHIIbHZ1c6ZCxTN",            "projectId": "scratchpad",            "appId": "1",            "public": true,            "layerId": "default",            "ix": 9,            "_opacity": 1,            "perimeter": 85.59963999962554,            "area": 432.1505607647723,            "grossArea": 432.1505607647723,            "_baseHeight": 0,            "_height": 0,            "_baseElevation": 0          },          "_projected": [            [              [                -231.9957100004565,                11.801089980639517              ],              [                -248.31571999979053,                11.801349978893995              ],              [                -248.3157199999787,                -14.67848001793027              ],              [                -231.99575000030205,                -14.678740018978715              ],              [                -231.9957100004565,                11.801089980639517              ]            ]          ],          "geometry": {            "type": "Polygon",            "coordinates": [              [                [                  -75.16112497502154,                  39.955238767159486                ],                [                  -75.16131596523033,                  39.955238764871034                ],                [                  -75.16131595513691,                  39.95500028003796                ],                [                  -75.16112496605959,                  39.95500028232638                ],                [                  -75.16112497502154,                  39.955238767159486                ]              ]            ]          }        },        {          "type": "Feature",          "properties": {            "color": "#8A9BA8",            "stroke": "black",            "strokeWidth": 1,            "id": "41icmmcHIIbHZ1c6ZCxTN",            "projectId": "scratchpad",            "appId": "1",            "public": true,            "layerId": "default",            "ix": 10,            "_opacity": 1,            "perimeter": 85.5996400056161,            "area": 432.1505608008001,            "grossArea": 432.1505608008001,            "_baseHeight": 0,            "_height": 0,            "_baseElevation": 0          },          "_projected": [            [              [                -252.31572000077725,                11.801409980282187              ],              [                -268.6357300012373,                11.801679980009794              ],              [                -268.63568999961944,                -14.67815002053976              ],              [                -252.31572000099095,                -14.67842002119869              ],              [                -252.31572000077725,                11.801409980282187              ]            ]          ],          "geometry": {            "type": "Polygon",            "coordinates": [              [                [                  -75.16136277652734,                  39.955238764228575                ],                [                  -75.16155376673613,                  39.95523876163843                ],                [                  -75.16155375534862,                  39.95500027680537                ],                [                  -75.16136276627132,                  39.955000279395485                ],                [                  -75.16136277652734,                  39.955238764228575                ]              ]            ]          }        },        {          "type": "Feature",          "properties": {            "color": "#8A9BA8",            "stroke": "black",            "strokeWidth": 1,            "id": "41icmmcHIIbHZ1c6ZCxTN",            "projectId": "scratchpad",            "appId": "1",            "public": true,            "layerId": "default",            "ix": 11,            "_opacity": 1,            "perimeter": 85.5996200028487,            "area": 432.1502959690529,            "grossArea": 432.1502959690529,            "_baseHeight": 0,            "_height": 0,            "_baseElevation": 0          },          "_projected": [            [              [                -272.63573000044534,                11.801739979535341              ],              [                -288.9557399996853,                11.801999979652464              ],              [                -288.9556399999509,                -14.677830019034445              ],              [                -272.63568999993987,                -14.678090021014214              ],              [                -272.63573000044534,                11.801739979535341              ]            ]          ],          "geometry": {            "type": "Polygon",            "coordinates": [              [                [                  -75.16160057803313,                  39.95523876089995                ],                [                  -75.16179156824188,                  39.95523875782798                ],                [                  -75.16179155532626,                  39.95500027299497                ],                [                  -75.16160056648303,                  39.9550002760669                ],                [                  -75.16160057803313,                  39.95523876089995                ]              ]            ]          }        }      ]    }

While the subdivide rectangle has 6 features?

How to know if a node expects or creates a collection?

You will see the [ ] brackets next to the connector on the node if it works with lists.

A node with collection input

A node with collection outputs

A node with collection inputs and outputs

Did this answer your question?