I have a layer of points (call it points of interest), I would like to click on one, and obtain in a popup all the addresses (from address points) that fall within the parcel that the original point is within. I thought the approach below would work, but the the line 8 below fails, telling me there is an invalid parameter. There will be other steps after this that actually return the list of addresses for use in the popup, but can't implement that until i actually have a set to work with. This seems straightforward in my head (click on poi, get a parcel, get the address points that fall inside the parcel) but I'm obviously missing something. Thoughts?
// gets addresses that belong to a single parcel
var fs_parcels = FeatureSetByName($map, "parcel layer"['UPC','OWNER','OWNADD','SITUSADD'])
var targ_parcel = Intersects(fs_parcels, $feature) //target parcel from clicking on point of interest
console("returns " + Count(targ_parcel)+ " parcels")//gives me a count of 1, as expected
var fs_addr_pts = FeatureSetByName($map, "addr_points",['GeoAddress'])//creates feature set of address points in map
console("returns " + Count(fs_addr_pts))//returns 207,000 records found in featureset
//the next setp fails and doesn't return any features
var parcel_addrs = Intersects(fs_addr_pts, targ_parcel)
Console("returns " + count(parcel_addrs) + " addresses")
Solved! Go to Solution.
The Intersects function takes a FeatureSet and a Feature. Even though targ_parcel contains only one Feature, it's still considered a FeatureSet. What you have to do is get the First item of that FeatureSet (line 3) to use in the Intersects function.
// gets addresses that belong to a single parcel
var fs_parcels = FeatureSetByName($map, "parcel layer", ['UPC','OWNER','OWNADD','SITUSADD'])
var targ_parcel = First(Intersects(fs_parcels, $feature)) //target parcel from clicking on point of interest
//console("returns " + Count(targ_parcel)+ " parcels")//gives me a count of 1, as expected
var fs_addr_pts = FeatureSetByName($map, "addr_points",['GeoAddress'])//creates feature set of address points in map
console("returns " + Count(fs_addr_pts))//returns 207,000 records found in featureset
//the next setp fails and doesn't return any features
var parcel_addrs = Intersects(fs_addr_pts, targ_parcel)
Console("returns " + count(parcel_addrs) + " addresses")
The Intersects function takes a FeatureSet and a Feature. Even though targ_parcel contains only one Feature, it's still considered a FeatureSet. What you have to do is get the First item of that FeatureSet (line 3) to use in the Intersects function.
// gets addresses that belong to a single parcel
var fs_parcels = FeatureSetByName($map, "parcel layer", ['UPC','OWNER','OWNADD','SITUSADD'])
var targ_parcel = First(Intersects(fs_parcels, $feature)) //target parcel from clicking on point of interest
//console("returns " + Count(targ_parcel)+ " parcels")//gives me a count of 1, as expected
var fs_addr_pts = FeatureSetByName($map, "addr_points",['GeoAddress'])//creates feature set of address points in map
console("returns " + Count(fs_addr_pts))//returns 207,000 records found in featureset
//the next setp fails and doesn't return any features
var parcel_addrs = Intersects(fs_addr_pts, targ_parcel)
Console("returns " + count(parcel_addrs) + " addresses")
@KenBuja I'm not sure who marked this as solved, but this doesn't seem to be working - that line fails to return anything and gives the same 'invalid parameter'. At first i thought it was because there are two 'First' functions, one that handles an array, and another that takes features and returns a feature, but since there is no way to specify which function I'm assuming Arcade figures out what the input and desired result is. Regardless, if you have other thoughts I'd appreciate it.
Arcade will figure out which function you're using from the input parameters.
I just tested this with my data and got the expected return value (this is using an Arcade element).
var fs_parcels = FeatureSetByName($map, "Enterprise Zone", ['*'])
var targ_parcel = First(Intersects(fs_parcels, $feature))
var fs_addr_pts = FeatureSetByName($map, "Sub-Neighborhoods",['*'])
var parcel_addrs = Intersects(fs_addr_pts, targ_parcel)
var output = "returns " + count(parcel_addrs) + " addresses"
return {
type : 'text',
text : output
}
completely bizarre - here's the screen shot from running this using the First function and then one removing that function. I feel like I'm missing something really silly here.
You can't use a Feature in the Count function. You can use Arrays, FeatureSets, or Text strings.
well see? something ridiculously silly. @KenBuja thanks for the assist!
code works, i have a little to do to clean it up and add some finesse stuff but the main functionality is there.