Select to view content in your preferred language

Arcade - Spatial reference expected

461
4
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
4 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
AlexisHandelman
Occasional Contributor

Did you find a solution or work around. We recently upgraded our environment and now our previously working attribute rules stopped working with the same error. Ours are almost identical to yours. They return a field from an intersecting polygon feature class and returns the value from the feature of greatest overlap. 

0 Kudos
JoeNunn
Frequent Contributor

I have just been testing using ArcGIS 3.5.4 to ugrade within our team and immediatly stumbled into this issue getting the Arcade error: Spatial reference expected. on an arcade field calculation.  I managed to get it to work on 3.4 but not in 3.5.4 giving the same error.  The line of code it failed on was this:

intersectArea += Area(intersection($feature,block), "square metres");

Would be good to know if this is fixed so we can trust an upgrade?

 

0 Kudos