Calculation Rule- auto populate a point's coordinates into an existing row

1478
9
Jump to solution
07-18-2022 11:17 AM
V1212
by
New Contributor II

Hi, 

I was wondering if it's possible to auto populate the coordinates of a created point feature into an existing row rather than a new row. 

 

Thanks!

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Something like this could do what you want:

  • create a point feature class, add GlobalID
  • create a field in that fc that will work as a foreign key to the table you wish to edit
  • edit and add this attribute rule
// Calculation Attribute Rule on your point FC
// Field: empty
// Triggers: Insert
// Exclude from application evaluation

// get the rows that will be updated
var key = $feature.KeyField
var table = FeatureSetByName($datastore, "Database.Dataowner.TableYouWantToEdit", ["GlobalID", "KeyField"], false)
var rows = Filter(table, "KeyField = @key")

// create and fill the update array
var lat_long_attributes = {"LAT": Geometry($feature).y, "LONG": Geometry($feature).x}
var updates = []
for(var row in rows) {
    Push(updates, {"globalID": row.GlobalID, "attributes": lat_long_attributes}
}

// tell ArcGIS to edit the table
return {
    "edit" [{
        "className": "Database.Dataowner.TableYouWantToEdit",
        "updates": updates
    }]
}

 

The workflow for this would be

  • copy the key of the feature you want to edit
  • create point feature --> paste key into the feature template, create the point in the correct location
  • the attribute rule will trigger and write the coordinates of the  new point into the lat/long fields of the row(s) you specified with the key

Have a great day!
Johannes

View solution in original post

0 Kudos
9 Replies
JohannesLindner
MVP Frequent Contributor

So you want to do something like this?

  • Click on Create Features, choose the point template
  • Click into the map
  • but instead of creating a new feature, the coordinates of an existing point are updated

 

This could be kinda possible (you'd end up with a feature without geometry, so you wouldn't see it on the map). But, questions:

  • What's your use case?
  • Why not use the edit tools to edit the existing point?
  • How would you decide which existing point to edit?
  • Coordinates as in numeric fields in the table or as in the actual point geometry?

Have a great day!
Johannes
0 Kudos
V1212
by
New Contributor II

Thanks for your reply, 

So you want to do something like this?

  • Click on Create Features, choose the point template
  • Click into the map
  • but instead of creating a new feature, the coordinates of an existing point are updated

I want to add a new point feature that populates the coordinates into empty lat/long fields in an existing row in my table.

I want an editor to add coordinates to places that have wrong attribute info so the data can be fixed downstream using the updated coordinates. I want as little manual editing done as possible so I thought this could be a good solution (no copy/pasting correct coordinates into lat/long fields). We don’t edit existing data, just update new corresponding fields. 

 

Hope I answered all your questions!

0 Kudos
JohannesLindner
MVP Frequent Contributor

Something like this could do what you want:

  • create a point feature class, add GlobalID
  • create a field in that fc that will work as a foreign key to the table you wish to edit
  • edit and add this attribute rule
// Calculation Attribute Rule on your point FC
// Field: empty
// Triggers: Insert
// Exclude from application evaluation

// get the rows that will be updated
var key = $feature.KeyField
var table = FeatureSetByName($datastore, "Database.Dataowner.TableYouWantToEdit", ["GlobalID", "KeyField"], false)
var rows = Filter(table, "KeyField = @key")

// create and fill the update array
var lat_long_attributes = {"LAT": Geometry($feature).y, "LONG": Geometry($feature).x}
var updates = []
for(var row in rows) {
    Push(updates, {"globalID": row.GlobalID, "attributes": lat_long_attributes}
}

// tell ArcGIS to edit the table
return {
    "edit" [{
        "className": "Database.Dataowner.TableYouWantToEdit",
        "updates": updates
    }]
}

 

The workflow for this would be

  • copy the key of the feature you want to edit
  • create point feature --> paste key into the feature template, create the point in the correct location
  • the attribute rule will trigger and write the coordinates of the  new point into the lat/long fields of the row(s) you specified with the key

Have a great day!
Johannes
0 Kudos
V1212
by
New Contributor II

Thanks for your help, I really appreciate it!

0 Kudos
V1212
by
New Contributor II

 

Thanks again!

0 Kudos
JohannesLindner
MVP Frequent Contributor

Are you sure that you're creating it on the right feature class? This behavior sounds like you create the rule on the class you want to update.

 


Have a great day!
Johannes
0 Kudos
V1212
by
New Contributor II

 

 

Thanks again!

0 Kudos
JohannesLindner
MVP Frequent Contributor

Yeah, as I thought.

You're adding the rule to the feature class you want to update. That means that you create a point, and then the rule triggers and edits a point in the same class.

The rule is meant to be created on a different point feature class that you use to edit the "real" feature class.


Have a great day!
Johannes
0 Kudos
HusseinNasser2
Esri Contributor

Here is a filegdb example which a calculation rule updates the X and Y fields with the point's geometry coordinates on insert and update. We assign the field as empty so we can update multiple fields in one shot. The rule is simple

 

var g = Geometry($feature);
var x = g.x;
var y = g.y;
return {
	"result": {
		"attributes": {
			"x": x,
			"y": y
		}
	}
}

the rule