Select to view content in your preferred language

Arcade - Search Geometry Cannot Be Null error

73
1
yesterday
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 Reply
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.