Select to view content in your preferred language

Arcade Data Expression

279
3
03-05-2024 12:06 PM
Labels (1)
LJackson29
Occasional Contributor III

Hello -

I am working in ArcGIS Online Dashboards, and am using the Social Vulnerability Index service from CDC. I would like to create an arcade data expression in dashboards that selects the census tracts that intersect our service area (polygon) and display the number of census tracts in an indicator.

Is this possible?

Thanks,

Leila

0 Kudos
3 Replies
KenBuja
MVP Esteemed Contributor

Esri has a Github page containing a number of different Arcade expressions. The Aggregate by Spatial Relationship example in the Dashboard section might be what you're looking for.

0 Kudos
LJackson29
Occasional Contributor III

Thanks @KenBuja - I have seen that, but am still relatively new to arcade especially in dashboards so not quite sure how to implement that. 

0 Kudos
jcarlson
MVP Esteemed Contributor

It is possible. Here's a basic template. Just swap in your layer IDs and field names.

// service areas layer
var fs1 = FeatureSetByPortalItem(
  Portal("https://www.arcgis.com"),
  // portal item id
  "7b1fb95ab77f40bf8aa09c8b59045449",
  0, // layer id
  ["*"], // fields to include
  false // include or exclude geometry
)

// census tracts layer
var fs2 = FeatureSetByPortalItem(
  Portal("https://www.arcgis.com"),
  // portal item id
  "6200db0b80de4341ae8ee2b62d606e67",
  0, // layer id
  ["*"], // fields to include
  true // include or exclude geometry
);

// output dictionary
var out_dict = {
  fields: [
    {
      name: 'service_area_id', type: 'esriFieldTypeString'
    },
    {
      name: 'number_of_tracts', type: 'esriFieldTypeInteger'
    }
  ],
  geometryType: '',
  features: []
}

// loop through service areas
for (var f in fs1) {

  // get intersected tracts
  var xs_tracts = Intersects(f, fs2)

  // push service area and count into the output dict
  Push(
    out_dict['features'],
    {
      attributes: {
        service_area_id: f['service_area_id'],
        number_of_tracts: Count(xs_tracts)
      }
    }
  )
}

// return featureset
return FeatureSet(out_dict)

 

- Josh Carlson
Kendall County GIS
0 Kudos