Select to view content in your preferred language

Arcade To Count Features In A NearMe And Report Out By Criteria

372
1
07-29-2024 12:39 PM
Labels (1)
GregReinecke
Frequent Contributor

Hello All,

I have created some code to count how many features result from their inclusion when the NearMe widget is run in ExB.  When the arcade loads it see all features  so case 1) There is more than 0 features. When I run the NearMe widget case 2) determines if there is more than 0 and fails.  all good. 

My problem is trying to get it to report case 3) when there are 0 features in the NearMe polygon so I can report out "0 features are in the area".  What seems to happen is that it still sees All the features as nothing is actually selected when 0 are found.  makes sense, I just need to account for that.  Here is my script:

// Arcade expression to count the number of selected features in a NearMe promity selection

// Define the feature layer
var layer = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), '#######################', 0, ['*']);

// Retrieve the selected features
// var selectedFeatures = Filter(layer, "OBJECTID IN @Selection");

// Count the number of selected features
var cntFeats = Count($layer)

if (cntFeats > 0) {
    return "There are existing fetures in the NearMe area (" + cntFeats + ") so FAIL";
  }
    else {
      return "There are no existing fetures in the NearMe area so PASS";
}

  Perhaps someone has an idea.

Thanks,

GRMapper

Tags (1)
0 Kudos
1 Reply
GregReinecke
Frequent Contributor

Perhaps a little more context. I’d like a list box to reflect 1) no NearNe executed yet so the box background would be white, 2) if the NearMe widget results in one feature in the circle that’s a Fail so turn the box red and 3) if no feature is in the box that’s a Pass so turn the box green. 

I am trying to avoid the box being green by default. If there was a way to test if the NearMe widget had fired or not might allow a conditional statement to work with. 

Does the NearMe widget when run create a set or group or something that can be addressed in an If Then?

Thanks.  

GRMapper

0 Kudos