Select to view content in your preferred language

Calculate a value using an intersect and a related table

736
7
Jump to solution
02-04-2025 01:17 AM
ColinCampbell1
Regular Contributor

Hi everyone,

I was wondering if anyone could tell me if the following was possible in theory?  I'd also love to know how to do it, but I'm happy to try to work out how if I know it can be done.

I have a point layer which allows people to collect species observations and a separate polygon layer of recording areas where people go to record their species.  The recording areas layer has a related table of visits which a user updates each time they visit an area to record species.

When people add a species observation I would like to intersect that point with the recording areas layer and pull information across from the most recent visit record of the intersecting area - with that information being populated into fields on the observation record.

For the workflow I'm using this needs to be done in the Field Maps app as the species observations records are being created, rather than it being something that can be done outside of FM afterwards.

Is this something that's possible?

Many thanks in advance for any help people can offer.

Colin

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ZachBodenner
MVP Regular Contributor

Alright, so here's a rule that worked for me as an attribute rule. In your case given the context, what you might do is instead of using the $datastore of FeatureSetByName, you might choose $map. Otherwise, you could use FeatureSetByPortalItem, which would allow you to access the layer even if it isn't in the map. 

Essentially, in Field Maps form designer, you would add this as a Calculated Expression, making that field uneditable for the user. You might need to tweak this because Arcade profiled are different across applications, but this should get you a good chunk of the way there. Just adjust your layer names, feature names etc as necessary.

// This is the polygon feature
var nrAreas = FeatureSetbyName($datastore,'NR_Management')
// intersect the polygons
var interArea = first(intersects($feature,nrAreas))
// This is the relted table
var matchTable = FeatureSetbyName($datastore,'NR_Management_Form')

// if there's no intersecting area, end the expression
if (interArea == null){return}

// get the global ID of the polygon
var interAreaGlobal = interArea.GlobalID
// Filter polygons based on shared ID. In this case, NRArea_Rel is a GUID type
var filterStatement = 'NRArea_Rel = @interAreaGlobal'

// Filter all the related forms
var relatedForms = Filter(matchTable,filterStatement)
// Get the data from the most recent form, determined by the 'Date' Field
var recentForm = first(OrderBy(relatedForms, 'Date ASC'))

// Identify the maintenance performed
var maint = recentForm.MaintPerformed

// Write the above value into the attribute this rule runs on
return maint
Happy mapping,
- Zach

View solution in original post

7 Replies
ZachBodenner
MVP Regular Contributor

Can you tell us where the data is stored? For example, are all of the layers and tables you mention hosted, or are they referencing an underlying enterprise database? The reason I ask is because if it's the later it opens you up to some other options, like attribute rules on the dataset instead of relying on Field Maps forms.

I believe this should be possible through a combination of filtering and intersecting, something like initialize a variable that will hold the table attribute you want, intersect the polygon based on the point entered, filter the table based on a common ID between the polygon identified and the table, and use the created variable as the return for your attribute. I could definitely run a test too, but I'll wait for your answer to the first question.

Happy mapping,
- Zach
ColinCampbell1
Regular Contributor

Hi Zach,

All the layers/tables are hosted feature layers on ArcGIS Online.

Thanks for replying so quickly (and helpfully)!

Colin

0 Kudos
ZachBodenner
MVP Regular Contributor

Alright, so here's a rule that worked for me as an attribute rule. In your case given the context, what you might do is instead of using the $datastore of FeatureSetByName, you might choose $map. Otherwise, you could use FeatureSetByPortalItem, which would allow you to access the layer even if it isn't in the map. 

Essentially, in Field Maps form designer, you would add this as a Calculated Expression, making that field uneditable for the user. You might need to tweak this because Arcade profiled are different across applications, but this should get you a good chunk of the way there. Just adjust your layer names, feature names etc as necessary.

// This is the polygon feature
var nrAreas = FeatureSetbyName($datastore,'NR_Management')
// intersect the polygons
var interArea = first(intersects($feature,nrAreas))
// This is the relted table
var matchTable = FeatureSetbyName($datastore,'NR_Management_Form')

// if there's no intersecting area, end the expression
if (interArea == null){return}

// get the global ID of the polygon
var interAreaGlobal = interArea.GlobalID
// Filter polygons based on shared ID. In this case, NRArea_Rel is a GUID type
var filterStatement = 'NRArea_Rel = @interAreaGlobal'

// Filter all the related forms
var relatedForms = Filter(matchTable,filterStatement)
// Get the data from the most recent form, determined by the 'Date' Field
var recentForm = first(OrderBy(relatedForms, 'Date ASC'))

// Identify the maintenance performed
var maint = recentForm.MaintPerformed

// Write the above value into the attribute this rule runs on
return maint
Happy mapping,
- Zach
ColinCampbell1
Regular Contributor

That's absolutely fantastic - thanks so much Zach.  I will give it a go and let you know how I get on.

0 Kudos
ColinCampbell1
Regular Contributor

Just to say that this worked a treat - thank you again!

0 Kudos
ZachBodenner
MVP Regular Contributor

No problem, glad to be helpful!

Happy mapping,
- Zach
0 Kudos
altayebhussein
New Contributor

i think its possible,
but i need to know if the attributes table of polygon layer is the same of point layer?

you con use some codes to transfer data from point layer to polygon 

i hope that i can help you 

0 Kudos