Select to view content in your preferred language

Use Arcade to Sum Results of Different Feature Classes and Display via Indicator

1126
6
Jump to solution
10-30-2023 03:53 PM
Labels (1)
HaydenHarrison1
Emerging Contributor

Hello! 

I am creating a dashboard in Portal that shows the total length of our four important pipe feature classes. I created an indicator for each of these layers showing the calculated sum of the Shape__Length field. 

I now need a way to create a new indicator showing the simple sum of the four existing ones. How can I do this?

I did some research and started creating a data expression that looked back to the feature sets rather than the indicators. See below. However, this creates a number as an output and I need it to create a FeatureSet that an indicator can use. Please help!

 

var portal = Portal('portalnamehere')

    
//pressurized mains

var pm = Filter(
    FeatureSetByPortalItem(
        portal,
        'item id here',
        11,
        ['Owner_Entity','LifeCycleStatus','Shape__Length'],
        false
    ),
    "(Owner_Entity = 'Oklahoma City') AND (LIFECYCLESTATUS = 'ACTIVE')"
    
);    
    
var sumPM = sum(pm,"Shape__Length")

//service lines

var sl = Filter(
    FeatureSetByPortalItem(
        portal,
        'item id here',
        9,
        ['Owner_Entity','LifeCycleStatus','Shape__Length'],
        false
    ),
    "(Owner_Entity = 'Oklahoma City') AND (LIFECYCLESTATUS = 'ACTIVE')"
    
);   

var sumSL = sum(sl,"Shape__Length")

//gravity mains

var gm = Filter(
    FeatureSetByPortalItem(
        portal,
        'item id here',
        10,
        ['Owner_Entity','LifeCycleStatus','Shape__Length'],
        false
    ),
    "(Owner_Entity = 'Oklahoma City') AND (LIFECYCLESTATUS = 'ACTIVE')"
    
);   

var sumgm = sum(gm,"Shape__Length")

//atoka

var at = FeatureSetByPortalItem(
        portal,
        'item id here',
        4,
        ['Owner_Entity','LifeCycleStatus','Shape__Length'],
        false
    )
   

var sumat = sum(at,"Shape__Length")

var totalsum = sumpm + sumSL + sumgm + sumat

return totalsum/5280

 

 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Hm. Well, AGOL lets you create a FeatureSet directly from a dict, but if you're in Enterprise you'll need to wrap it in Text().

Try "return FeatureSet(Text(fs_dict))" instead?

- Josh Carlson
Kendall County GIS

View solution in original post

6 Replies
jcarlson
MVP Esteemed Contributor

Easy enough! Just follow the JSON spec of a FeatureSet. Throw this in at the end of your expression.

var fs_dict = {
  fields: [{name: 'total_sum', type: 'esriFieldTypeDouble'}],
  geometryType: '',
  features: [{attributes: {total_sum: totalsum/5280}}]
}

return FeatureSet(fs_dict)

 

- Josh Carlson
Kendall County GIS
0 Kudos
HaydenHarrison1
Emerging Contributor

Hi Josh, 

 

Thank you for the quick reply! A follow up question for you: 

When I add the above code to mine, the output is the number of miles (which is correct); however, when I exit the data expression editor, it says "unable to execute Arcade script". I wondered if it was because the test was returning the "return totalsum/5280" rather than the "return FeatureSet(fs_dict)".

When I remove the "return totalsum/5280", I get the following error: Execution Error:Invalid Parameter

Attached is the code that returns the number rather than feature set. Thoughts? 

Thank you again!!

 

var portal = Portal('portal name')

    
//pressurized mains

var pm = Filter(
    FeatureSetByPortalItem(
        portal,
        'item name',
        11,
        ['Owner_Entity','LifeCycleStatus','Shape__Length'],
        false
    ),
    "(Owner_Entity = 'Oklahoma City') AND (LIFECYCLESTATUS = 'ACTIVE')"
    
);    
    
var sumPM = sum(pm,"Shape__Length")

//service lines

var sl = Filter(
    FeatureSetByPortalItem(
        portal,
        'item name',
        9,
        ['Owner_Entity','LifeCycleStatus','Shape__Length'],
        false
    ),
    "(Owner_Entity = 'Oklahoma City') AND (LIFECYCLESTATUS = 'ACTIVE')"
    
);   

var sumSL = sum(sl,"Shape__Length")

//gravity mains

var gm = Filter(
    FeatureSetByPortalItem(
        portal,
        'item name',
        10,
        ['Owner_Entity','LifeCycleStatus','Shape__Length'],
        false
    ),
    "(Owner_Entity = 'Oklahoma City') AND (LIFECYCLESTATUS = 'ACTIVE')"
    
);   

var sumgm = sum(gm,"Shape__Length")

//atoka

var at = FeatureSetByPortalItem(
        portal,
        'item name',
        4,
        ['Owner_Entity','LifeCycleStatus','Shape__Length'],
        false
    )
   

var sumat = sum(at,"Shape__Length")

var totalsum = (sumpm + sumSL + sumgm + sumat)

return totalsum/5280

var fs_dict = {
  fields: [{name: 'total_sum', type: 'esriFieldTypeDouble'}],
  geometryType: '',
  features: [{attributes: {total_sum: totalsum/5280}}]
}

return FeatureSet(fs_dict)

 

0 Kudos
jcarlson
MVP Esteemed Contributor

Sorry, I should have mentioned, remove the existing "return totalsum/5280" line, then run it.

- Josh Carlson
Kendall County GIS
0 Kudos
HaydenHarrison1
Emerging Contributor

Unfortunately, I get the "Execution Error:Invalid Parameter" when I remove the existing "return totalsum/5280".

I am new to arcade so I'm unsure what exactly it means by "Invalid Parameter". Any insight is appreciated. 

 

Hayden

0 Kudos
jcarlson
MVP Esteemed Contributor

Hm. Well, AGOL lets you create a FeatureSet directly from a dict, but if you're in Enterprise you'll need to wrap it in Text().

Try "return FeatureSet(Text(fs_dict))" instead?

- Josh Carlson
Kendall County GIS
HaydenHarrison1
Emerging Contributor

It worked! Thank you!!

0 Kudos