Select to view content in your preferred language

Arcade - Spatial reference expected

215
2
07-28-2025 02:49 PM
Labels (1)
aricraimundo
Occasional Contributor

Hi,

I'm working with an Arcade expression in ArcGIS Pro Advanced 3.5.2 on Windows 11, using a File Geodatabase (v10.0).

I'm trying to create an immediate calculation attribute rule triggered on Insert or Update of a polygon feature class. The rule is intended to extract two fields (FIELD1 and FIELD2) from another polygon feature class based on maximum area of intersection.

Both of my polygon feature classes have defined spatial references, so I don't believe it's a projection issue. However, when I attempt to calculate the area of the intersection geometry (line 25), I get this error:

Arcade error: Spatial reference expected.

Here is my expression:

var fc = FeatureSetByName(
  $datastore,
  "MyPolygonFeatureClass",
  ["FIELD1", "FIELD2"],
  true
);

var matches = Intersects(fc, $feature);
var matchesCount = Count(matches);

if (matchesCount == 0) {
  return { errorMessage: "Invalid feature !" };
}

var feat = null;

if (matchesCount == 1) {
  feat = First(matches);
} else {
  var bestMatch = null;
  var maxArea = 0.0;

  for (var f in matches) {
    var commonGeometry = Intersection($feature, f);
    var geometryArea = AreaGeodetic(commonGeometry, "square-meters");

    if (IsEmpty(bestMatch) || geometryArea > maxArea) {
      maxArea = geometryArea;
      bestMatch = f;
    }
  }

  feat = bestMatch;
}

return {
  result: {
    attributes: {
      field1: feat.FIELD1,
      field2: feat.FIELD2,
    },
  },
};


I've reviewed my Arcade expression and can't spot any obvious issue. 

I also came across BUG-000176749, and I'm wondering if this might be related.

Has anyone else encountered this error or have insight into what might be causing it? 

Any help would be appreciated.

Thanks!

0 Kudos
2 Replies
RTPL_AU
Honored Contributor

@aricraimundo 
Does "commonGeometry"  have a coordinate system once it has been created from the intersect?
I don't know Arcade very well and it is full of weird things.
Try assigning a coordsys prior to the area calc.

0 Kudos
aricraimundo
Occasional Contributor

Yes, it does.

And commonGeometry is a Polygon. I’ve used TypeOf to confirm.

I agree with you on “weird things”.

0 Kudos