Hello,
I have tried to get a point count with a polygon using the following code:
// address count agol
var p = Portal('https://www.arcgis.com')
// Filter portal layer
var features = Filter(FeatureSetByPortalItem(p, 'xyzxyzxyz', xy), "feature.xy = 'xy'")
// get the points inside the current polygon feature
var points_in_polygon = Contains($feature, features)
// count them and return the number
return Count(points_in_polygon)
However I get the following error:
Invalid expression.
Error on line 1.
Failed to query statistics
When I run it as:
var p = Portal('https://www.arcgis.com')
var features = Filter(FeatureSetByPortalItem(p, 'xyzxyzxyz', xy), "feature.xy = 'xy'")
It runs perfectly but that does not do me any good.
Want I want to do is filter a point layer for specific values and return the count of the features that meet the filtered parameters within a polygon. I can return a value without the filter but for some reason I cannot get it to run when filtering.
Any help is appreciated!
Thanks,
What is your actual Filter function? What you have in there is confusing, since you shouldn't include "feature" as part of the sqlExpression. It should look like this:
var value = xy
var result = Filter(FeatureSetByPortalItem(p, 'itemId', layerId), "pointField = @value");
I guess this would be it:
var features = Filter(FeatureSetByPortalItem(p, 'itemid', layerid), "feature.field name= 'field value'").
Here I am trying to filter the incoming portal layer by field name. If it I leave it at that and don't add more lines of syntax, it says the expression is valid.
The error comes when I try to get a count of the filtered data. I am running the expression in a polygon field.
I have also tried
// address count agol
var p = Portal('https://www.arcgis.com')
var features = FeatureSetByPortalItem(p, '9cf1341131214c15b7900f0153557246', 30)
//filter point layer for fiber only
var fiberFeatures = Filter(features, "feature.Coverage = 'Fiber'")
But again it says valid until I try to return a point count. Don't know if the filter function turns it into a string formula of some sort when I need a numerical value.
What exactly are you doing with:
var value = xy
Are you declaring the field value I am filtering for prior to pulling in the portal layer. Apologies I'm not as familiar with Arcade as I'd like to be.
If I am understanding your data correctly, your code would look like this
// address count agol
var p = Portal('https://www.arcgis.com')
var features = FeatureSetByPortalItem(p, '9cf1341131214c15b7900f0153557246', 30)
//filter point layer for fiber only
var fiberFeatures = Filter(features, "Coverage = 'Fiber'")
// get the points inside the current polygon feature
var points_in_polygon = Contains($feature, fiberFeatures)
// count them and return the number
return Count(points_in_polygon)
Setting a variable to be used in the sqlStatement (variable substitution in the Filter function) means you don't have to worry about whether to use quotes.
var value = 'Fiber'
Filter(features, "Coverage = @value")
// or
var value = 99
Filter(features, "numericField = @value")
It's more useful when you have to get a variable from the incoming feature or make some a calculation, since you can't use Arcade profile variables like $feature or Arcade functions in the sqlStatement
var averageValue = Average($layer, 'POPULATION')
var result = Filter($layer, 'POPULATION > @averageValue');