Select to view content in your preferred language

Using Arcade to pull a value from an Intersect list that is similar to already defined field?

855
2
Jump to solution
06-18-2024 07:09 AM
Amarz
by
Frequent Contributor

Hello,

I am attempting to do an Intersect from a point to a stacked polygon layer.  So far my arcade expression returns a list of values, I want to be able to isolate a single value in that list based off a predefined value when creating the point.

Data looks like:

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

For instance my list will return: ["City Hall Floor 2 Finance Office (261)","City Hall Basement Maintenance Shop (21)","City Hall Floor 1 Open Office (157)"]

What I want is for the arcade script to read my EAMIT Asset is assigned to City Hall Floor 1, and only return the polygon that has a similar name, so here it would reaturn City Hall Floor 1 Open Off (157) into the EAMIT Asset location field.

Here is my script.

//Here is the stacked polygon being intersected
var fs = FeatureSetByName($datastore, "DBO.EAMFacility", ["fullname","facilityname","facilityfloor","facilityroom"])
var fsIntersect = Intersects(fs, $feature)
var results = [];
for (var f in fsIntersect){
//returns all results available
  results[Count(results)] =  (f.fullname)
//what I would like here is to compare it to the established floor the Asset it on and pick the more similar EAMFacility location.
}
return results

I appreciate any assistance!

1 Solution

Accepted Solutions
Amarz
by
Frequent Contributor

I found a solution that works for my organization, but please use it knowing it came from working with the above script, and prompting ChatGPT to get the results.

 

// Get the FeatureSet
var fs = FeatureSetByName($datastore, "dbo.EAMFacility", ["fullname", "facilityname", "facilityfloor", "facilityroom"]);

// Find features that intersect with the current feature
var fsIntersect = Intersects(fs, $feature);

// Initialize an empty string to store the final result
var resultText = "";

// Get the facility from the input feature (assuming it exists in the $feature)
var inputFacility = $feature.facility; 

// Iterate over the intersecting features
for (var f in fsIntersect) {
    // Concatenate the facilityname and facilityfloor from fs
    var facilityComparison = Concatenate(f.facilityname + " " + f.facilityfloor);
    
    // Compare the concatenated value with the inputFacility
    if (facilityComparison == inputFacility) {
        // If they are similar, add the fullname to the result string
        if (resultText != "") {
            resultText += ", ";  // Add a separator if it's not the first result
        }
        resultText += f.fullname;  // Concatenate the result
    }
}

// Return the final result (if found) as a plain string
if (resultText == "") {
    return null;  // Return null if no results were found
} else {
    return resultText;  // Return the concatenated string of results
}

To add to this, this workflow is predicated on the Asset Feature facility field including a value that is to be compared to the Facility Feature's fullname field. So when assigning the Asset with a facility of 'City Hall First Floor', it will search the array built by the intersect for the Facility that includes 'City Hall First Floor' returning the Facility.fullname of 'City Hall First Floor IT Office'

 

View solution in original post

0 Kudos
2 Replies
GISFunctionalGroup
Regular Contributor

Hi Amraz,

We are also looking for similar case like need to extract the floor features stacked in the building. we are able to capture only top of the floor from the building not underneath it.
If you find any solution kindly do post here.

0 Kudos
Amarz
by
Frequent Contributor

I found a solution that works for my organization, but please use it knowing it came from working with the above script, and prompting ChatGPT to get the results.

 

// Get the FeatureSet
var fs = FeatureSetByName($datastore, "dbo.EAMFacility", ["fullname", "facilityname", "facilityfloor", "facilityroom"]);

// Find features that intersect with the current feature
var fsIntersect = Intersects(fs, $feature);

// Initialize an empty string to store the final result
var resultText = "";

// Get the facility from the input feature (assuming it exists in the $feature)
var inputFacility = $feature.facility; 

// Iterate over the intersecting features
for (var f in fsIntersect) {
    // Concatenate the facilityname and facilityfloor from fs
    var facilityComparison = Concatenate(f.facilityname + " " + f.facilityfloor);
    
    // Compare the concatenated value with the inputFacility
    if (facilityComparison == inputFacility) {
        // If they are similar, add the fullname to the result string
        if (resultText != "") {
            resultText += ", ";  // Add a separator if it's not the first result
        }
        resultText += f.fullname;  // Concatenate the result
    }
}

// Return the final result (if found) as a plain string
if (resultText == "") {
    return null;  // Return null if no results were found
} else {
    return resultText;  // Return the concatenated string of results
}

To add to this, this workflow is predicated on the Asset Feature facility field including a value that is to be compared to the Facility Feature's fullname field. So when assigning the Asset with a facility of 'City Hall First Floor', it will search the array built by the intersect for the Facility that includes 'City Hall First Floor' returning the Facility.fullname of 'City Hall First Floor IT Office'

 

0 Kudos