Arcade attribute calculation : how to wait for the end of a geometry

195
2
03-21-2024 02:33 AM
DISIG
by
New Contributor III

hello everybody i am migrating to fieldmaps an arcade calculation that work perfectly in the map viewer and pro.

the subject of this calculation is  : spatially catching the attribute of an other layer BUT based on the majoritary representation in multiple intersections case.

when calculating in fieldmaps seems not wait the end of the complete geometry before calculating.

 

console('STATUT : EN PRODUCTION')
console('TITRE : extraire atribut relation spatiale')
console('CLC-ATTR-HERIT-SPA')
console('2024-02-28 Version 1.0 ')
// VARIABLES UTILISATEURS
var t = 50; // tolérance maximale de recherche exprimée en mètres
var G = $feature // G pour géométrie source
var P = buffer($feature,t,'meters'); // P pour entité de type polygone
var L = FeatureSetByName($map, "ROUTES_POUR_PR") // L pour layer dont on veut l'attribut majoritaire
var A = 'ROUTE' // A pour attribut à retourner

// STEP1 : AJUSTEMENT DE LA DISTANCE DE TRAITEMENT
var I = Intersects(L,P) // I pour Intersection
if(isempty(I) || count(I)==0){return '+ de '+t+ 'mètres'}
var adjustedDistance     = Infinity;
  // On cherche le plus proche pour calculer sa distance
  for (var sEnt in I){
    var DynDistance = Distance(sEnt,G, "meters");
    if(DynDistance < adjustedDistance){
      adjustedDistance = DynDistance;
    }
  };
if(adjustedDistance==0){adjustedDistance+=1}

// STEP : 2  ADAPTATION DE LA GÉOMETRIE SOURCE
if(typeof(geometry(G))=='Polyline'|| typeof(geometry(G))=='Point')
    {P = buffer(G,adjustedDistance,'meters')
    console('P est une ligne ou un point')};
if(typeof(geometry(G))=='Polygon')
    {P = G
    console('P est un polygone')};

// STEP 3 : TRAITEMENT DES CAS D'INTERSECTION UNIQUES.
if(isempty(I)||count(I)==0){return '-'};
if(count(I)==1){
var candidat = first(I)[A]
if(right(candidat,2)=='PG'){return replace(candidat,'PG','')}else{return candidat}
};

// STEP 4  : TRAITEMENT DES CAS D'INTERSECTION MULTIPLES.
var features = [];
var feat;
for (var eEnt in I){
  var tmpG = clip(eEnt,extent(P))
  var Geom = Buffer(tmpG,adjustedDistance,'meters')
  var gArea = Area(Intersection(P,Geom),'meters')
  var gAttr = eEnt[A]
  feat = {'attributes': {'inheritedAttr': Text(gAttr),'representation': Number(gArea),}}
    Push(features, feat);

}
var dowDict = { 
  'fields': [{ 'name': 'inheritedAttr', 'type': 'esriFieldTypeString'},
  {'name': 'representation', 'type': 'esriFieldTypeDouble'}], 
  'geometryType': '', 
  'features': features
};
var candidat = first(orderBy(FeatureSet(dowDict),'representation DESC'))['inheritedAttr']
if(right(candidat,2)=='PG'){return replace(candidat,'PG','')}else{return candidat}

 

0 Kudos
2 Replies
JakeBrownMaps
Esri Contributor

Hello @DISIG  - thanks for sharing all the detail.  The Field Maps create new feature edit experience doesn't really have the concept of "end of the complete geometry" as vertices are added to the polyline that will trigger calculated values to update. 

Is the primary issue the calculations execution time as vertices are added/updated?  Perhaps it's a distraction to the field worker using the form? 

Couple suggestions:

  • display the calculated field's value in the popup and hide it in the editing form
  • use a vertex count  or Length($feature, 'meters') > 1; to ensure the line meets a certain criteria before calculating 

Hope that helps-

Jake Brown

Field App Product Engineer

 

0 Kudos
DISIG
by
New Contributor III

Hello Jake, thank you for your answer. 

It was just a simple projection problem. This kind of geometrical calculations seems to work in FieldMaps if the projections of all the layers are the sames. (BUG-000133986)

I reprojected my all layers and everything is working perfectly.

 A good step to ready-to-use data 🙂

 

Thank you!

0 Kudos