Select to view content in your preferred language

Arcade - Search Geometry Cannot Be Null error

335
3
Jump to solution
06-11-2025 07:07 AM
JoshSaad1
Frequent Contributor

In my road centerline features I'm trying to calculate the neighborhood names in the left and right sides of each road segment based on the neighborhood.  To indicate which side to check, I'm including an Offset function to calculate the neighborhood name that intersects 1-foot on either side of the line.  I'm also performing this in a file geodatabase.  Here is my script:

var fsNbrhd = FeatureSetByName($datastore, 'Neighborhood', ['Nbrhd_Comm'], true)
var RoadLeft = Offset($feature, -1, 'us-feet', 'square')
var fsNbrhdLeft = Intersects(fsNbrhd, RoadLeft)
var NbrhdLeft = First(fsNbrhdLeft)

if (IsEmpty(Geometry(NbrhdLeft))) return
else if(NbrhdLeft == null) return null
else return NbrhdLeft.Nbrhd_Comm

I keep getting an error on line 4, "Search geometry cannot be null".  However, if I change the variable on line 3 to the line itself instead of the offset:

var fsNbrhdLeft = Intersects(fsNbrhd, $feature) 

I don't get the error, and it just calculates whatever polygon my line intersects.  I think the problem might be with the Offset function.

I also tried adding error messages in the script to help identify the problem:

var fsNbrhd = FeatureSetByName($datastore, 'Neighborhood', ['Nbrhd_Comm'], true)
if (IsEmpty(Geometry(fsNbrhd))) return "error0"

var RoadLeft = Offset($feature, -1, 'us-feet', 'square')
if (IsEmpty(Geometry(RoadLeft))) return "error1"

var fsNbrhdLeft = Intersects(fsNbrhd, RoadLeft)
if (IsEmpty(Geometry(fsNbrhdLeft))) return "error2"

var NbrhdLeft = First(fsNbrhdLeft)
if (IsEmpty(Geometry(NbrhdLeft))) return "error3"

if(NbrhdLeft == null) return null
return NbrhdLeft.Nbrhd_Comm

When running this, all of the features returned "error0", indicating null geometry in my Neighborhood layer, but it seems to be drawing on the map with no problem, and it calculates fine if I ignore the offset and just calculate whatever intersects the line.

Has anyone else experienced this, or can help identify the problem?

Thanks,

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
JoshSaad1
Frequent Contributor

I found that the version of ArcGIS Pro that I use in our AWS Cloud environment, which is a few versions behind, may have been throwing the error because of a bug.  When I tested on the latest version on my PC, I didn't receive it, but I was getting bad results.  It was matching neighborhoods to road centerlines that were several miles away.  I contacted Esri support and they were able to modify the script to make it work: 

var fsNbrhd = FeatureSetByName($datastore, "Neighborhood", ['Nbrhd_Comm'], true)
var fsNbrhdRight = Intersects(fsNbrhd, $feature)
if (Count(fsNbrhdRight) > 0) {
var NbrhdRight = First(fsNbrhdRight)
return NbrhdRight.Nbrhd_Comm
}
else {
var buffLine = Offset($feature, 200, 'us-feet')
var NewInterSect = Intersects(fsNbrhd, buffLine)
if(Count(NewInterSect) > 0) {
return First(NewInterSect).Nbrhd_Comm
}
else return null

}

View solution in original post

0 Kudos
3 Replies
KenBuja
MVP Esteemed Contributor

What do you get when you return RoadLeft? Your code seems to work in the Playground, returning the value for the IsEmpty check. That is expected, since I doubt the testing FeatureSet and $feature intersect at all

Snag_8068ae.png

The reason you're getting "error0" is that the Geometry function expects a Feature, not a FeatureSet.  You'd have to loop through the FeatureSet to test each Feature.

var fsNbrhd =  FeatureSetByName($datastore, 'Neighborhood', ['Nbrhd_Comm'], true);
for (var f in fsNbrhd) {
  if (IsEmpty(Geometry(f))) return `Record ${f.OJBECTID) is empty";
}
return "No empty records";

 What's curious is that putting the FeatureSet in the Geometry function works in ArcGIS Pro but not in the Playground.

Snag_9a4dc5.png

**Update

I did test your code using my data in ArcGIS Pro and it did run correctly.

JoshSaad1
Frequent Contributor

I'm still testing out some things.  I tried the script you suggested, looping through all of the features, but got "No Empty Records" for all of my features.

I put in a support ticket with Esri to see if they can help out.  I'll post an answer if I get it working.

0 Kudos
JoshSaad1
Frequent Contributor

I found that the version of ArcGIS Pro that I use in our AWS Cloud environment, which is a few versions behind, may have been throwing the error because of a bug.  When I tested on the latest version on my PC, I didn't receive it, but I was getting bad results.  It was matching neighborhoods to road centerlines that were several miles away.  I contacted Esri support and they were able to modify the script to make it work: 

var fsNbrhd = FeatureSetByName($datastore, "Neighborhood", ['Nbrhd_Comm'], true)
var fsNbrhdRight = Intersects(fsNbrhd, $feature)
if (Count(fsNbrhdRight) > 0) {
var NbrhdRight = First(fsNbrhdRight)
return NbrhdRight.Nbrhd_Comm
}
else {
var buffLine = Offset($feature, 200, 'us-feet')
var NewInterSect = Intersects(fsNbrhd, buffLine)
if(Count(NewInterSect) > 0) {
return First(NewInterSect).Nbrhd_Comm
}
else return null

}
0 Kudos