Arcade: totaling field values of features contained within a polygon.

8057
12
Jump to solution
10-22-2020 08:54 AM
TravisAnderson
Occasional Contributor

This is related to water consumption and waterloss to add context. I have the following two layers in my map:

   -Zones

   -Meters

I've been trying to make this work in Arcade, but can't exactly figure out how. I have figured out how to Count the meters contained in the "zone" as shown below in the map with the pop-up, but I also want to display the total of the field "Consumption" of all the meters contained in that polygon/zone. So if I had a Zone and there were 5 meters in the zone, and each customer consumed 1,000 gallons, I want to display 5,000 gallons on the pop-up for that Zone. 

var meter = FeatureSetByName($map,"METERS")
var CountMeters = Count(Intersects(meter, $feature))
Return CountMeters

I'm focused on using the "(Intersects(meter, $feature))" with the function of SUM, but I'm not sure that's the right direction. In words, I want to find all the features from the Meter layer that are contained in the polygon Zone, and then total the attribute field "consumption" of those objects. I'm looking for the total water consumption within that Zone. I can only find examples of counting objects using the Intersect function, but not totaling fields using the Intersect function.

Any help would be greatly appreciated.

Attibute table for a Meter:

DMA Zone and Meters:

12 Replies
XanderBakker
Esri Esteemed Contributor

Hi Travis Anderson ,

I am glad that you detected what was going wrong. I think I made a remark earlier about if the information was indeed numeric. When working with GIS and with databases, it is not good to mix different data types (text and numeric data), since things will break in the process. The screenshot you included to show the RollOver if from Excel and Excel is not a database and this often happens. 

About the other question, if the data you shared contains such a specific example, can you indicate how to get to it? Having access to the data and seeing the actual situation would help me a lot to come up with a solution. 

0 Kudos
TravisAnderson
Occasional Contributor

Xander,

I believe I figured everything out. Below is what I basically used to get the 4 items in my popup to work. Although, there's probably a better way to do it. I repeat a lot of the same lines of code in each item that I list in the pop-up. It seems like I'm repeating the same thing 4 times, but I get the correct information and it's fairly quick.

Thanks for your help Xander. Your examples were invaluable. 

Travis

//grab meter information from layer "Service".
var meters = FeatureSetByName($map,"Services");

//determine which are within the zone.
var int = Intersects(meters, $feature);

//Master meters have a "1" in the column/field "meter_definition". All other meters are null.

//Use function Filter to isolate master meters within zone.

var master = Filter(int, 'meter_definition >0');

//If more than 1 master meter exists in a Zone, the largest would be the intlet to that Zone. Other's would be outlets/master meters to other zones fed through this particular zone.
var maximum = max(master, "consumption");

//Use varible master to sum consumption of masters meters within the zone.
var MasterTotal = sum(master, "consumption");

//calculate total volume of consumption for ALL OTHER master meters in the Zone
var MasterOut = MasterTotal - maximum;

//calculate consumption of ALL meters contained in the Zone.
var AllMeters = sum(int, "consumption");

//waterloss calculation = maximum - customer consumption - masterout
custconsumption = AllMeters - maximum - MasterOut;

var waterloss = maximum - custconsumption - MasterOut;

Return waterloss;

XanderBakker
Esri Esteemed Contributor

Hi Travis Anderson ,

Great to see that the pop-up has the information you ware looking for and that you were able to resolve it.

I do wonder a bit about the performance of using multiple Arcade expression to may result in multiple requests to the server for the same information. It is possible to do this with a single expression. However, the resulting pop-up would look different since all information will be returned in a single text. 

0 Kudos