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?
Solved! Go to Solution.
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
I think you can do that with attribute rules in PRO.
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.
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
}}
}
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?
That's the plan, yes.
@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.
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?
The arcade code can't find the name of the feature?
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?
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