From 693dafcf95fef4ec333e0d1b1a3cebe3f4aa7a3d Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 23 Aug 2019 23:49:23 -0400 Subject: [PATCH] tested and improved examples --- .gitignore | 7 ++ .../UpdateAssociatedFeatures.md | 44 +++++++----- .../UpdateContainerViaAssociations.md | 71 +++++++++++++++++++ 3 files changed, 106 insertions(+), 16 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f66d21d --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +/.idea/$PRODUCT_WORKSPACE_FILE$ +/.idea/.gitignore +/.idea/arcade-expressions.iml +/.idea/inspectionProfiles/profiles_settings.xml +/.idea/misc.xml +/.idea/modules.xml +/.idea/vcs.xml diff --git a/attribute_rules_calculation/UpdateAssociatedFeatures.md b/attribute_rules_calculation/UpdateAssociatedFeatures.md index b31c8a1..0f18b79 100644 --- a/attribute_rules_calculation/UpdateAssociatedFeatures.md +++ b/attribute_rules_calculation/UpdateAssociatedFeatures.md @@ -43,7 +43,7 @@ for (var row in content) { // Return the count of features and in the edit parameter the class of features to update and the list of updates return { -'result': Count(contained_features), +'result': $feature.InstallDate, 'edit': [ {'className': 'WaterDevice', 'updates': contained_features @@ -53,33 +53,45 @@ return { ``` -```js -// This rule will update an attribute in all the features it contains, requires ArcGIS Pro 2.5 -// Query the associations table to find all features that are content of feature. -var globalID = $feature.globalID + + + +```js +// This rule will update an attribute in all the features it contains, requires ArcGIS Pro 2.5 +// Return in date is null +if (IsEmpty($feature.InstallDate)) { + return $feature.InstallDate; +} // Query to get all the content associations var associations = FeatureSetByAssociation($feature, 'content', null, null, ['*'], false); -var contained_features = [] -var i = 0 +if (count(associations) == 0) { + return $feature.InstallDate; +} + +var edits = {}; // Loop through each contained feature, create a dict of the Global ID and the new install date for (var row in associations) { - contained_features[i++] = { + if (HasKey(edits, row.className) == False) { + edits[row.className] = [] + } + edits[row.className][count(edits[row.className])] = { 'globalid': row.globalId, 'attributes': {"InstallDate": $feature.InstallDate} } } - +var contained_features = []; +for (var k in edits) { + contained_features[count(contained_features)] = { + 'className': k, + 'updates': edits[k] + } +} // Return the count of features and in the edit parameter the class of features to update and the list of updates return { - 'result': Count(contained_features), - 'edit': [ - { - 'className': row.className, - 'updates': contained_features - } - ] + 'result': $feature.InstallDate, + 'edit': contained_features } ``` \ No newline at end of file diff --git a/attribute_rules_calculation/UpdateContainerViaAssociations.md b/attribute_rules_calculation/UpdateContainerViaAssociations.md index a5a3eb8..5ebd5ed 100644 --- a/attribute_rules_calculation/UpdateContainerViaAssociations.md +++ b/attribute_rules_calculation/UpdateContainerViaAssociations.md @@ -111,3 +111,74 @@ return { ] }; ``` + + +```js +// This rule will update an attribute in the the container of the feature + +// Function to check if a bit is in an int value +function has_bit(num, test_value) { + // num = number to test if it contains a bit + // test_value = the bit value to test for + // determines if num has the test_value bit set + // Equivalent to num AND test_value == test_value + + // first we need to determine the bit position of test_value + var bit_pos = -1; + for (var i=0; i < 64; i++) { + // equivalent to test_value >> 1 + var test_value = Floor(test_value / 2); + bit_pos++ + if (test_value == 0) + break; + } + // now that we know the bit position, we shift the bits of + // num until we get to the bit we care about + for (var i=1; i <= bit_pos; i++) { + var num = Floor(num / 2); + } + + if (num % 2 == 0) { + return false + } + else { + return true + } + +} + +if (IsEmpty($feature.DETAILS)) { + return $feature.DETAILS; +} +var association_status = $feature.ASSOCIATIONSTATUS; +// Only features with an association status of content(bit 4) or visible content(bit 16) +// need to be evaluated +if (IsEmpty(association_status) || + (has_bit(association_status,4) || has_bit(association_status,16)) == false) { + return $feature.DETAILS; +} + +// Query to get all the content associations +var associations = FeatureSetByAssociation($feature, 'container', null, null, ['*'], false); +if (count(associations) == 0) +{ + return $feature.DETAILS; +} +// Get the first container +var assoc_record = First(associations); +var container_feature = { + 'globalid': assoc_record.GlobalID, + 'attributes': {"LABELTEXT": $feature.DETAILS} +}; + +// Return the value of the field this is assigned on and the edit info for the container +return { + 'result': $feature.DETAILS, + 'edit': [ + { + 'className': assoc_record.className, + 'updates': [container_feature] + } + ] +}; +```