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

1876
8
11-09-2021 01:01 PM
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
8 Replies
ABishop
MVP Regular Contributor

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
MVP Regular Contributor

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 Frequent 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?

JJ_Reyes
Occasional Contributor

Hi @MatthewDavis1984 - what strategy did you end up using for filtering the map? What I've come to is using the "Custom Parameters" option in the underlying Map Viewer to query the live data set. It seems clunky as I have to paste in all the coordinates of the polygons with the "ring" syntax used in the ArcGIS Rest API....

0 Kudos
MatthewDavis1984
New Contributor II

Hello @JJ_Reyes 

I wish I could say that that would work, but my AOI has 59,028 vertices and trying to use custom parameters to filter it out would take forever. Though maybe a generalized AOI with fewer vertices would do the trick?

I ended up doing a 'manual' method. I did a spatial select to get the ~515 gauge locations in my AOI, building a list with them, then manually filtering out only those ~515 gauges in the map filter option on the layer itself. This had additional issues in that building the filters in Chrome tended to stop accepting new filters after every ~20 filters or so. I eventually learned that this issue doesn't happen in Firefox or Edge so performed the rest of the filters there.

MatthewDavis1984_0-1697458142122.png

 

0 Kudos