Select to view content in your preferred language

Run spatial query when a new feature has been created in a feature layer

1598
17
Jump to solution
12-08-2022 07:04 AM
AndrewReynoldsDevon
Occasional Contributor

I have a feature layer with 3 values that exist in other layers that contain information that I want stored in the point layer. I need to run a spatial query when a new feature has been created to look up data in these other 2 layers & then record this data in the main point layer. How can you achieve this?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
AndrewReynoldsDevon
Occasional Contributor

I managed to get it working in the end by deleting the fields in the point feature, creating them again to match the polygon features & then using those in the code. I'm now going to publish to the portal to see if the rules persist & it works as it does in the Pro Project 

View solution in original post

0 Kudos
17 Replies
Alaind_Espaignet
New Contributor II

I think you can do that with attribute rules in PRO. 

https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/an-overview-of-attribute-ru...

I have a similar need. Create a point feature in a Parcel, grab some info from the intersecting parcel and populate it in the new feature. 

0 Kudos
JohannesLindner
MVP Frequent Contributor

As @Alaind_Espaignet said, that's a very common use case for Attribute Rules.

 

A very basic Attribute rule for transferring a single value ( @Alaind_Espaignet scenario):

// Calculation Attribute Rule on the point fc
// field: the field you want to fill
// triggers: Insert(, Update)

// load the other featureset
var fs = FeaturesetByName($datastore, "NameOfTheFC")
// get the first feature from fs that intersects the current $feature
var f = First(Intersects(fs, $feature))
// abort if we didn't find something
if(f == null) { return }
// return the intersecting feature's value
return f.Field

 

 

And for multiple fields ( @AndrewReynoldsDevon scenario):

// Calculation Attribute rule on the point fc
// field: empty!
// triggers: Insert(, Update)

// load the other featuresets
var fs1 = FeaturesetByName($datastore, "NameOfTheFirstFC")
var fs2 = FeaturesetByName($datastore, "NameOfTheSecondFC")

// get the first feature from fs1 that intersects the current $feature
var f1 = First(Intersects(fs1, $feature))
// if there is no intersecting feature, use a default value, else use that feature's field value
var value1 = Iif(f1 == null, null, f1.Field)

// do the same for fs2
var f2 = First(Intersects(fs2, $feature))
var value2 = Iif(f2 == null, null, f2.Field)

// return
return {
    result: {attributes: {
        Field1: value1,
        Field2: value2
    }}
}

Have a great day!
Johannes
0 Kudos
AndrewReynoldsDevon
Occasional Contributor

ok thanks - the feature layer will exist as a layer on a webmap. 

@JohannesLindner with the code above do I add that to the feature whilst in Pro then publish to our enterprise server?

Once published with the updated attribute info will the code then be active?

0 Kudos
JohannesLindner
MVP Frequent Contributor

That's the plan, yes.


Have a great day!
Johannes
0 Kudos
AndrewReynoldsDevon
Occasional Contributor

@JohannesLindner  - rather than intersecting I need to use 'contains within'. The source information are names of people which are polygons & we're creating points. Therefore the query will need to be something like  - when a point is created in this particular polygon look up these 2 values - the name of the person who is responsible for the polygon & the polygon area name. These 2 values will the populate the fields in the point class. 

0 Kudos
AndrewReynoldsDevon
Occasional Contributor

Also does all of the required data need to live within the same project/map service or can the code work with other layers that already exist on our enterprise server?

 

0 Kudos
AndrewReynoldsDevon
Occasional Contributor

The arcade code can't find the name of the feature?

snip.JPG

0 Kudos
AndrewReynoldsDevon
Occasional Contributor

I have a field in the point feature class with the same name as the field that I'm looking up in the other layer. I specified this field when creating the expression but do you need to specify it in the code?

snip 2].JPG

0 Kudos
AndrewReynoldsDevon
Occasional Contributor

The name of the field is the same in both the point fc & the polygon. The value is blank in the point fc but I want it grab the value from the polygon class then return that value & save it in the point fc

0 Kudos