Select to view content in your preferred language

Relationship Classes and maintaining a set quantity equilibrium

601
3
03-19-2019 04:11 PM
GustavoMuro
New Contributor

I am trying to figure out the best way to set up some kind of relationship (Relationship Class?) between multiple features and a limited quantity. The scenario is this: There is a large pile or piles of soil in specific locations with some quantity of soil and soil is planned to be removed from that/those piles of soil to new locations. Is there a way to set up a system where if you take a certain quantity from one pile into another, it will automatically deduct the amount of removed soil from the pile it was removed from? I'm basically envisioning field crew using Collector to remove and add soil from different locations and have it mathematically be in sync in real time using some kind of scripting function (Arcade?) to make it balance the quantities and maintain equilibrium. Hope that makes sense. Thank you.

0 Kudos
3 Replies
XanderBakker
Esri Esteemed Contributor

Hi Gustavo Muro ,

I know that this question is rather old, but I just wanted to share some thought on what you could accomplish with Arcade. Obviously the possibilities depend entirely on the data you have. 

For this example I created a few points:

The attribute data contains information about the initial volume (SoilVolume) at each location and the locationID:

I also have a table with all the volumes that have been moved around containing from and to ID's, date and the amount:

Although this example is using ArcGIS Pro, you can do the same thing using ArcGIS Online or Enterprise.

Let's first calculate the new volume of soil after all the movements have taken place. This can be done with the following Arcade expression (which I configured in the pop-up):

var loc_id = $feature.LocationID;
var tbl = FeatureSetByName($map, "SoilMovement");
var sql_from = "FromID = '" + loc_id + "'";
var sql_to = "ToID = '" + loc_id + "'";
var tbl_out = Filter(tbl, sql_from);
var tbl_in = Filter(tbl, sql_to);

var sum_out = 0;
for (var rec_out in tbl_out) {
    sum_out += rec_out.MoveVolume;
}

var sum_in = 0;
for (var rec_in in tbl_in) {
    sum_in += rec_in.MoveVolume;
}

var volume_new = $feature.SoilVolume - sum_out + sum_in;
return volume_new;

As you can see:

  • On line 1, I read out the location ID of the current point
  • Then on line 2 the table with the movements is accessed
  • There are two SQL expressions, one for the volume that is removed (from) and one for the volume that is received (to)
  • Both SQL expressions are used in two filters to get the relevant records
  • Lines 8 to 11 sum up all the removed volume from the current location
  • Lines 13 to 16 sum up the volume that is received at the current location
  • On lines 18 and 19 the new volume is calculated and returned

We can also go a step further and report all the movements of soil with this expression:

var loc_id = $feature.LocationID;
var tbl = FeatureSetByName($map, "SoilMovement");
var sql_from = "FromID = '" + loc_id + "'";
var sql_to = "ToID = '" + loc_id + "'";
var tbl_out = Filter(tbl, sql_from);
var tbl_in = Filter(tbl, sql_to);

var sum_out = 0;
for (var rec_out in tbl_out) {
    sum_out += rec_out.MoveVolume;
}

var sum_in = 0;
for (var rec_in in tbl_in) {
    sum_in += rec_in.MoveVolume;
}


var hist = "";
if (Count(tbl_out) > 0) { 
    hist += "Outgoing volume (" + sum_out + "):"
    for (var rec_out in tbl_out) {
        hist += TextFormatting.NewLine + " - " + Text(rec_out.MoveDate, 'DD/MM/Y  -> ' )  + rec_out.MoveVolume + " (to " + rec_out.ToID + ")";
    }
}

if (Count(tbl_in) > 0) { 
    hist += TextFormatting.NewLine + TextFormatting.NewLine + "Incoming volume (" + sum_in + "):"
    for (var rec_in in tbl_in) {
                hist += TextFormatting.NewLine + " - " + Text(rec_in.MoveDate, 'DD/MM/Y  -> ' )  +  rec_in.MoveVolume + " (from " + rec_in.FromID + ")";
    }
}

return hist;

The final result will display like this:

GustavoMuro
New Contributor

Thank you Xander for you response. What you coded in Arcade looks excellent for ArcGIS Online! Thank you again.

XanderBakker
Esri Esteemed Contributor

You´re welcome. If you run into problems implementing this in ArcGIS Online, just let me know. It should work, although it depends on the structure of the data that you have.

0 Kudos