Skip to content

Commit

Permalink
tested and improved examples
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMillerGIS committed Aug 24, 2019
1 parent 6d17742 commit 693dafc
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
44 changes: 28 additions & 16 deletions attribute_rules_calculation/UpdateAssociatedFeatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
```
71 changes: 71 additions & 0 deletions attribute_rules_calculation/UpdateContainerViaAssociations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
]
};
```

0 comments on commit 693dafc

Please sign in to comment.