Hello,
I am running into an issue in ArcGIS Pro that I have been able to resolve in the past using repair geometry, but not on this particular feature class. The script is used to create a unique id for our utilities feature classes by combining ObjectID, Half Section, and utility type.
I am running this expression in a field calculation, but it will be used as a attribute rule.
Any help is appreciated.
// SAN POINTS QA/QC | UPDATE NETWORK ID
var f = $feature.Feat_Code
var o = $feature.Functn
var oid = $feature.OBJECTID
// HALF-SECTION //
// Get the intersecting "HalfSection" polygon
var hs = FeatureSetByName($datastore, "HalfSection");
// Intersect current feature with HalfSection polygons
var h = First(Intersects(hs, $feature));
// Create a buffer (1000 feet)
var buff = Buffer(Geometry($feature), 1000, 'feet');
// Get candidate HalfSections within buffer
var candidates = Intersects(hs, buff);
// Initialize nearest tracking
var nearestHS = null;
var minDist = 999999999;
// Loop through candidates to find closest HalfSection
for (var feat in candidates) {
var d = Distance(Geometry($feature), Geometry(feat));
if (d < minDist) {
minDist = d;
nearestHS = feat;
}
}
var halfSec;
// If an intersecting polygon is found, use its "HalfSec" value
if (!IsEmpty(h)) {
halfSec = h.HalfSec;
}
// If no direct intersect, but a nearby polygon exists, use closest + "xy"
else if (IsEmpty(h) && !IsEmpty(nearestHS)) {
halfSec = nearestHS.HalfSec + "xy";
}
// If nothing found, set to null
else {
halfSec = null;
}
// Network ID Codes
var n = decode(f,
'XC San Manhole', 'SAMH',
'Sanitary Manhole', 'SAMH',
'Sanitary - TW', 'SATW',
'San Service Stub', 'SASS',
'Pipe End', 'SAPE',
'Nolocate', 'SANL',
'MIA', 'SAMA',
'Metro San MH', 'SAMM',
'Meter Station', 'SAMS',
'Manhole Drop Line', 'SAMH',
'Lift Station', 'SALS',
'Gate Valve', 'SAGV',
'Flushing Connection', 'SAFC',
'Curb Stop', 'SACS',
'Crossover','SAXX',
'CP Test','SACP',
'Cleanout', 'SACO',
'Air Release MH', 'SAAR',
null)
// Final Network ID
var ni = n+"-"+halfSec+"-"+oid
return ni
You’re hitting “Invalid search geometry” because your rule calls Intersects(hs, $feature) / Intersects(hs, buff) when the search geometry is sometimes null/empty/invalid (for example, the edited point has no shape yet, bad geometry, or a null geometry is being passed into Buffer()/Intersects())
Try these changes (key fixes: guard for null geometry, don’t call First() until you know there’s a result, and request only needed fields😞
// SAN POINTS QA/QC | UPDATE NETWORK ID
var f = $feature.Feat_Code
var o = $feature.Functn
var oid = $feature.OBJECTID
// ---- Guard: feature must have valid geometry ----
var g = Geometry($feature)
if (g == null || IsEmpty(g)) {
return null // or return $feature.NetworkID (whatever your target field is)
}
// HALF-SECTION
// Only request the field you need; keep geometry available for distance
var hs = FeatureSetByName($datastore, "HalfSection", ["HalfSec"], true)
// 1) Intersect with the feature geometry (not the feature object)
var interFS = Intersects(hs, g)
// Container checking prevents First() on an empty set
var halfSec = null
if (!IsEmpty(interFS, true)) {
halfSec = First(interFS).HalfSec
} else {
// 2) Fallback: buffer search, but only if buffer succeeds
var buff = Buffer(g, 1000, "feet")
if (buff != null && !IsEmpty(buff)) {
var candidates = Intersects(hs, buff)
var nearestHS = null
var minDist = Infinity
for (var feat in candidates) {
var d = Distance(g, Geometry(feat))
if (d < minDist) {
minDist = d
nearestHS = feat
}
}
if (nearestHS != null) {
halfSec = nearestHS.HalfSec + "xy"
}
}
}
// ...continue with your decode() / network id logic...
return halfSecNotes relevant to your snippet: