Select to view content in your preferred language

Attribute Rule to Intersect only visable polygons?

825
7
06-10-2024 04:58 PM
Labels (1)
Amarz
by
Frequent Contributor

Hello,

I am attempting to run an Attribute rule that runs an Intersect on a polygon layer with stacked polygons. Think of this as Floor levels of a building.

I am attempting to create an attribute rule that will intersect only the visible features on a map and return the existing value.

My code (arcade) is:

var fs = FeatureSetByName($datastore, "DBO.EAMFacility", ["fullname"])
var fsIntersect = [Intersects(fs, $feature)]
var loc = Back(fsIntersect)
if (fullname == null) return {"errorMessage": "Area not found."}

return loc.fullname

Instead of intersecting layers that are turned on (I'm using definition queries to isolate Assets and Facilities based on Floor level), it is returning the first polygon it encounters.

Any help would be appreciated.

0 Kudos
7 Replies
ZachBodenner
MVP Regular Contributor

If you've got definition queries that are working to restrict visibility, I assume you've got good attribute data - that's what I'd rely on in this case. Include a check against an attribute as part of the IF statements. As an example, you might attempt something like:

var fs = FeatureSetByName($datastore, "DBO.EAMFacility", ["fullname"])
var fsIntersect = [Intersects(fs, $feature)]
var loc = Back(fsIntersect)
if (fullname == null) return {"errorMessage": "Area not found."}
else if ($feature.FloorNumber == 1){return "something"}
//etc

return loc.fullname
Happy mapping,
- Zach
0 Kudos
Amarz
by
Frequent Contributor

Thanks for your response, I suppose my only issue with adding an IF statement is that the Asset layer, the one I'm attempting to get Facility info into, currently doesn't have FloorNumber field in it. I was attempting to make it as simple as possible so my Staff doesn't have to think about it.

Ideally, when the paired feature classes are turned on in the Web Application (IE: Facilities of City Hall Floor 1 & Assets of City Hall Floor 1) as a grouped Feature Service. When you add a new Asset, it reads the Facilities Room and adds it to the location field.

You may be correct where I have to preload the Asset with that Floor level to get the Attribute rule to identify its location.

0 Kudos
ZachBodenner
MVP Regular Contributor

If you have the ability to do that I think it would be a good idea but of course it's not always a given that we can control the data schema. 

Happy mapping,
- Zach
0 Kudos
Amarz
by
Frequent Contributor

The only issue I am seeing is on  Line 5 

else if ($feature.FloorNumber == 1){return "something"}

 Where I'd want the $feature.FloorName to read the input of the User, then check for a similar attribute in the DBO.EAMFacility fullname field to return a result. Any ideas on how to make that occur?

0 Kudos
ZachBodenner
MVP Regular Contributor

Could you identify that as a variable as well?

var floor = $feature.FloorNumber
var facilities = featuresetbyportaitem(
  Portal('<portal URL>'),
  '<itemID>',
  <layerIndex>,
var fInter  = Insersects($feature, facilities)
for (var f in fInter){
// ...
if (floor = f.FloorNumber){return "something"}
}

I'm kind of spitballing because I'm not sure how your data is setup, but you could give that a try. Iterate through the facilities and use the if statement within the for loop to check for matching floor numbers? 

Happy mapping,
- Zach
0 Kudos
Amarz
by
Frequent Contributor

Hmm, my attempts have only returned an array of the possible values, and I can't seem to get it to just return the matching value.

FeatureEAMIT AssetsexampleEAMIT Facilityexample
Fieldsfacilityie: City Hall Floor 1facilitynameie: City Hall
 locationie: City Hall Floor 1 IT Officefacilityfloor

ie: Floor 1

   facilityroom

ie: IT Office

   location

ie: City Hall Floor 1 IT Office

I was first attempting a simpler intersect script, but since my polygons are stacking, it would only provide me with the first option.

The second though process was to manually add the EAMITAsset.facility field and have my users select that from a domain list. Then using this feature, have the script compare from a list created by the intersection and input the matching location.

My current script below will give me the result of : ["City Hall Basement","City Hall Floor 1","City Hall Floor 2"]

Any help cleaning it up would be amazing!

 

// identify the intersecting polygon and fields
var fs = FeatureSetByName($datastore, "DBO.EAMFacility", ["fullname","facilityname","facilityfloor","facilityroom"])

// intersect the point (fs) and polygon (fsIntersect)
var fsIntersect = Intersects(fs, $feature)

// create a list of available values
var results = [];
for (var f in fsIntersect){
// return the values in the form of 'City Hall Floor 1' for example
  results[Count(results)] =  Concatenate(f.facilityname, " ", f.facilityfloor,)
// attempt at matching the results to the feature and returning the matching value.
//**I believe this is the messed up portion of the script
  for (var x in f){
    if (results == $feature.Facility) return (x.fullname)
}
}
return results;

The ultimate goal is to get the EAMITFacility.location into the EAMITAsset.location field.

 

0 Kudos
ZachBodenner
MVP Regular Contributor

I don't have a lot of experience dealing with arrays, but I will say that the part your comments say is messed up is actually basically what I would have done (paired with your concatenate, I would think you're on the right track with matching var results to $feature.Facility). I'm not sure I know what's going on, so if there's anyone else who is watching this threat who notices something, I'd defer to them.

Happy mapping,
- Zach
0 Kudos