Select to view content in your preferred language

How to auto update field with calculated length geometry

273
9
Jump to solution
a week ago
TD1
by
Frequent Contributor

Have an existing feature service hosted in ArcGIS Online and used in a FieldMaps app. Field staff are collecting new data all the time.

I created a field to hold the calculated length of the lines (Can't use shape length). I have been manually running calculate geometry on this feature service via ArcGIS Pro.

Looking how to automate this process so that every time a new line is capture and record is created in feature service that my length field is updated.

0 Kudos
1 Solution

Accepted Solutions
EmilyGeo
Esri Regular Contributor

Hi @TD1

You can create a form for the layer in Map Viewer. In the form builder, you can write (or paste) the calculated expression that will be used to calculate the value for that field. That way the field will be calculated when features are created (or updated) in Map Viewer, Field maps, Web Editor, or other online apps that support editing. 

If you're not familiar with using arcade expressions in forms, this article is a good place to start. 

View solution in original post

9 Replies
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

Hi @TD1,

If you are looking to immediately capture the line length every time a feature is added but not override the existing value then you could use something like this as part of the calculation for that particular field. Without any additional context this should provide you the simplest means of updating that particular field.

var LineMeasure = $feature.<fieldname>
iif( IsEmpty( LineMeasure )  , Round( $feature.<shapefield> ), LineMeasure )

 

TD1
by
Frequent Contributor

@RPGIS is this the Geodesic line measurement?

but where does this script go? I can run a manual calculate field but how do I automatically do this as new data is captured?

If I just add it in the expression on a popup the data isn't touched and if I run it in AGOL on the data using calculate from the table it just runs on the records that exist at that point in time.

0 Kudos
EmilyGeo
Esri Regular Contributor

Hi @TD1

You can create a form for the layer in Map Viewer. In the form builder, you can write (or paste) the calculated expression that will be used to calculate the value for that field. That way the field will be calculated when features are created (or updated) in Map Viewer, Field maps, Web Editor, or other online apps that support editing. 

If you're not familiar with using arcade expressions in forms, this article is a good place to start. 

RPGIS
by MVP Regular Contributor
MVP Regular Contributor

To add to @EmilyGeo, the form builder is for Field Maps where you can set a calculation for a specified field.

TD1
by
Frequent Contributor

@RPGIS @EmilyGeo  I have tried this in form builder but the length field is not calculating at all

0 Kudos
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

What code specifically are you using? If you could please post a copy of the code then i it'll let us know where things aren't working. For the shape field are tou using the shape length field when calculating.

0 Kudos
TD1
by
Frequent Contributor

Figured it out and now it's working. Thanks  @RPGIS  and  @EmilyGeo  for your help!

For future reference for others the solution was using (note "$feature" is not a placeholder but the actual variable):

var test = LengthGeodetic($feature, 'meters')

return test​

 

0 Kudos
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

You could also simply use the Length($feature, 'meters ) to get the same result.

All functions regarding the Geometry functions use the either $feature or $featureset as arguments not placeholders. 

0 Kudos
TD1
by
Frequent Contributor

I needed to use the Geodesic length due to our policies

0 Kudos