How to use Arcade to filter/limit points within a polygon (or in indicators) on AGOL/Dashboard

565
6
11-09-2021 01:01 PM
Labels (3)
MatthewDavis1984
New Contributor II

There is a hosted feature layer that ESRI produces of Live Stream Gauges (https://www.arcgis.com/home/item.html?id=81c5a9f2a2704d54a49042a44eefa5d3 ) with just under 30,000 gauges from around the world which is updated hourly. I've set up a Dashboard to help show what areas are flooding in my specific Area of Interest (My AOI has 515 gauges). The extent of my AOI is not a regular square/rectangle, so no basic extent filtering. To give you a sense of my AOI it covers several portions of some states but not entire states. I'm not an Admin of that data so cannot create Hosted Feature Views.

I created a local copy of the data that I can match as Layer Actions in my Dashboard for lists of Gauges in my AOI (so folks can select which hydrograph they want to see). Though I can't figure out a way to filter the Live Stream Gauges to only show the 515 gauges my work cares about. Also, without this filtering the Indicators for Major Flooding or Minor Flooding include gauges in the same states as my AOI but outside my AOI itself

I've tried many workarounds and the best one seems to be moving it all to AGOL and using Data Expressions or Arcade to limit either the features shown in the map or in each individual indicator. I'm coming across an issue with my Arcade in an Indicator (I've removed several of the coordinates for brevity) :

var outerGeom = Polygon({
"rings": [ [[-73.95324012956144,40.122201568981296],
[-71.82532762791266,40.98483831123638],
[-71.92829333485861,41.2400142610767],
[-73.61331393113787,40.94986225060882],
[-74.533824004194,40.99513394964706],
[-75.01685781914264,40.66418261919473],
[-74.78762813590278,40.31578492218021],
[-73.95324012956144,40.122201568981296]] ],
"spatialReference": { "wkid": 4617 }
});
Count( Within(outerGeom, $layer));

return {
//textColor:'',
//backgroundColor:'',
//topText: '',
//topTextColor: '',
//topTextOutlineColor: '',
//topTextMaxSize: 'medium',
middleText: $datapoint["count"],
middleTextColor: '',
middleTextOutlineColor: '',
middleTextMaxSize: 'large',
//bottomText: '',
//bottomTextColor: '',
//bottomTextOutlineColor: '',
//bottomTextMaxSize: 'medium',
//iconName:'',
//iconAlign:'left',
//iconColor:'',
//iconOutlineColor:'',
//noValue:false,
//attributes: {
// attribute1: '',
// attribute2: ''
// }
}

I keep getting the error "Parse Error:polygon is not available" when I click on Test. Any ideas?

(Alternately any other ideas on how to filter/clip/mask the gauge points to my AOI in the map itself which would solve this issue.)

 

0 Kudos
6 Replies
ABishop
Regular Contributor III

Hello Matthew,

Does your AOI change?

Amanda Bishop, GISP
0 Kudos
MatthewDavis1984
New Contributor II

Hello Amanda,

No, the AOI is a fixed polygon

0 Kudos
ABishop
Regular Contributor III

I recently attended an Analysis MOOC and they described a way to create features based on overlay analysis.  I think it is only available in the Map Viewer Classic. Could be an option. 

Amanda Bishop, GISP
0 Kudos
MatthewDavis1984
New Contributor II

Thanks for the suggestion! Unfortunately since the data is 'Live' and updated hourly any attempt to create some kind of Join or View or Overlay would result in a static dataset. 

0 Kudos
JohannesLindner
MVP Regular Contributor

The code seems to be OK, no idea why it would throw that error. Maybe try this:

  • create and publish a feature class with that polygon
  • use Intersects:
var aoi = FeatureSetByName($datastore, "AoiPolygonFC", ["*"], true)
var gauges_in_aoi = Intersects(aoi, $layer)
Count(gauges_in_aoi)

 

Personally, I would use a definition query on the layer, so only "your" gauges are shown to begin with. Get the STATION attributes of the gauges in your aoi, construct the SQL as

STATION IN ('US04229500', 'NWSCOSN6', 'US01187300', ...)

and use that to filter your layer. Manually, that would be lots of work (and error prone). If you have access to ArcMap/ArcGIS Pro, it's easy:

Load the gauge layer, select your gauges, edit and run this code in the python window:

cursor = arcpy.da.SearchCursor("Gauge_Layer", ["STATION"])
stations = [row[0] for row in cursor]
print("STATION IN ('{}')".format("', '".join(stations)))

Have a great day!
Johannes
MatthewDavis1984
New Contributor II

Hi Johannes,

Thanks for the input! I'm trying your first suggestion though am getting a "SpatialReference" error which I'll have to dig into. The second two options you put forward I already did to create the Reference layer (it is used to narrow down the two List elements in my Dashboard to only show those in the area we are interested in). Here is a screenshot of the Dashboard:Dashboard_Screenshot.jpg

In the above screenshot the one "Minor Flood" indicator is showing outside of our AOI. I'm hoping to either limit the points in the map itself to our AOI (right now they are only filtered by State), or limit the indicator to the points within our AOI. (Uploading another feature service as a reference layer negates the live updates from the ESRI Live Stream Gauges hosted feature service; I can use it as a reference layer but I need to narrow down the Live layer itself so we can get continuous updates, especially during storm events).  

In the Portal Map that is the basis for this Dashboard I tried manually filtering by stations, but there seemed to be an error where it won't hold more than 125 filters at once (my AOI has 500+ gauges)

Does this help?