Select to view content in your preferred language

Arcade Intersect Returns Null Field Values

2704
8
Jump to solution
05-17-2022 09:39 AM
MulfordnSons
Emerging Contributor

I have two layers: A layer of all tax parcels, and a layer of a subset of all the tax parcels. 

I am trying to use Intersect in arcade to return a featureSet that I can then use to inject a field from the subset layer in the pop-up of the layer with all the tax parcels. However, it is returning Null field values, even though there are geometries that clearly overlap (as they are identical). Please see below:

var parcel = Intersects(FeatureSetByName($map,"Name of layer with subset of all tax parcels"), $feature);

for (var f in parcel){
return f.NameOfField
}

 

returns empty result (shown in attached photo).

 

Any obvious reason someone can see this is happening?

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

When you test your Arcade expression, it only checks one feature (I think it's the first). So if that feature doesn't intersect a feature of your filtered layer, you will get an empty intersect feature set. Your loop will run 0 times and then the expression will return null. If you call First() on an empty feature set, the result is null, which is why you get the ExecutionError when you try to return null.Field

Something like this should do the trick:

var filtered_parcels = Intersects(FeatureSetByName($map,"Name of layer with subset of all tax parcels"), $feature);

var parcel = First(filtered_parcels) // get the first feature

// if filtered_parcels is empty, parcel is null
// in that case, return a default value
if(parcel == null) {
    return "No intersecting subset parcel found."
}
// else return the field value
return parcel.NameOfField

 

When you test that expression, it should show the default result. When you actually open a popup, it should show either the default result or the field of the subset layer, depending on whether there is a subset parcel intersecting the queried feature.


Have a great day!
Johannes

View solution in original post

0 Kudos
8 Replies
RhettZufelt
MVP Notable Contributor

Since they are identical,  there should only one parcel overlapping at a time, so grab the first one.

var parcel = First(Intersects(FeatureSetByName($map,"Name of layer with subset of all tax parcels"), $feature))
return parcel.NameOfField

 

R_

 

0 Kudos
MulfordnSons
Emerging Contributor

Hello, thanks for your reply. Please see below the new error that is thrown from this:

 

Execution Error:Runtime Error: Cannot call member method on null. Name of Field

 

0 Kudos
KenBuja
MVP Esteemed Contributor

Did you make sure the FeatureSet you're retrieving contains any features?

var test = FeatureSetByName($map,"Name of layer with subset of all tax parcels");
console(Count(test));

 

0 Kudos
RhettZufelt
MVP Notable Contributor

You can always test for Null/Empty values and proceeded accordingly:

var parcel = First(Intersects(FeatureSetByName($map,"Name of layer with subset of all tax parcels"), $feature))

if (IsEmpty(parcel.NameOfField)){
    return Null
}  
else {
    return parcel.NameOfField
}

 

But, if you know there is overlap, something is not right as it should be returning something.  As suggested by @KenBuja above, can help to get count, etc. using the Console() option that will output to the Messages window in the Arcade editor.

R_

0 Kudos
JohannesLindner
MVP Frequent Contributor

When you test your Arcade expression, it only checks one feature (I think it's the first). So if that feature doesn't intersect a feature of your filtered layer, you will get an empty intersect feature set. Your loop will run 0 times and then the expression will return null. If you call First() on an empty feature set, the result is null, which is why you get the ExecutionError when you try to return null.Field

Something like this should do the trick:

var filtered_parcels = Intersects(FeatureSetByName($map,"Name of layer with subset of all tax parcels"), $feature);

var parcel = First(filtered_parcels) // get the first feature

// if filtered_parcels is empty, parcel is null
// in that case, return a default value
if(parcel == null) {
    return "No intersecting subset parcel found."
}
// else return the field value
return parcel.NameOfField

 

When you test that expression, it should show the default result. When you actually open a popup, it should show either the default result or the field of the subset layer, depending on whether there is a subset parcel intersecting the queried feature.


Have a great day!
Johannes
0 Kudos
skunkpup
Emerging Contributor

It worked. Thank you.

krunker

0 Kudos
DominicRoberge2
Frequent Contributor

@JohannesLindner I am using your code in a similar fashion, , it's working great if I click inside my Zone (blue area) but if I click outside I get the following warning message. Technically, since I don't have a Zone to intersect I should be getting a "NULL" value correct?

What am I missing?

Thanks!

 

 

DominicRoberge2_0-1687548057336.png

 

 

// Get other layer from datastore 
var other_layer = FeatureSetByName($map, "Tree Inventory Areas")
// Intersect layer and feature, use `First` to take the top feature
var intersectFeat = Intersects($feature, other_layer)
var xs_feat = First(intersectFeat)
var Zone =xs_feat["zone"]
var noZone = "999"

if(xs_feat == null) {
    return noZone
}
//else 
return Zone

 

0 Kudos
DominicRoberge2
Frequent Contributor

Sorry, I solved my problem:

 

 

// Get other layer from datastore
var other_layer = FeatureSetByName($map, "Tree Inventory Areas")
// Intersect layer and feature, use `First` to take the top feature
var intersectFeat = Intersects($feature, other_layer)

//check for intersects
var intersect_count = Count(Intersects(other_layer, $feature))
var noZone = "999"
if(intersect_count ==0) {
    return noZone
}

var xs_feat = First(intersectFeat)
var Zone =xs_feat["zone"]

//else
return Zone

 

0 Kudos