Overlapping Features in Pop-Ups Quick Introduction to Using FeatureSets with Arcade

61963
163
12-10-2018 11:08 AM
KellyGerrow
Esri Frequent Contributor
35 163 62K

With the December update of ArcGIS Online, the ability to reference other layers using Arcade Expressions in Pop-Ups was introduced. This blog is going to outline a quick example about how to create a simple intersect expression and display the results in a Pop-Up.

In this example I have used 4 layers marked as authoritative in ArcGIS Online by  Miami-Dade County, Florida. I want to display the Elementary, Middle and High School names which intersect with building footprints in a single pop-up. I have three layers of School Attendance Boundaries which identifies a specific school boundary which overlaps with many building footprints. The building footprint layer contains geometry information but no information about the infrastructure or zones that intersect with the building.

This Web Map shows examples of the information available in these layers in 4 separate layers.

Unedited Pop-ups

Using the new Arcade FeatureSet functionality, I was able to include the Elementary, Middle and High School names in the building footprint pop up in this web map

feature set

Here are the steps to set up this simple intersecting Arcade Expressions to include in a pop-up.

  1. Add all the desired layers with information that you would like to see to a web map.

  2. Select the layer that should display the pop-up information (Building Footprint)

  3. Inspect the School Attendance Boundary layers to identify the fields that you would like to display in the Building Footprint layer Name)

  4. Select Configure Pop up and navigate to the Add Attribute Expressions

  5. Create the expression for each layer.

    1. Create a variable that returns the FeatureSet of intersecting feature attributes.

      var intersectLayer =Intersects(FeatureSetByName($map,"Elementary School Attendance Boundary"), $feature)

      Expression Values Explained:

      var intersectLayer – specifies the intersecting features variable name

      Intersects – specifies the geometry function one feature intersects the geometry of the other specified layer.

      FeatureSetByName  Creates a FeatureSet from a Feature Layer based on its name within a map or feature service

      $map,"Elementary School Attendance Boundary"– identifies that the feature set is a layer named Elementary School Attendance Boundary, within the web map.

      $featureis the feature that is being selected in the Building Footprint layer that provides the initial spatial information.

         b.   Loop through the feature set created and return a specific field from the feature set:

           

for (var f in intersectLayer){

    return f.NAME

}

6. Once all expressions are created, add them to the pop up configuration.

7. Disable the pop ups and potentially the visibility from the School Attendance Boundary Layers (Not required, but I think it cleans up the display,

8.Check out your pop up with information from intersecting layers.

There will be more documentation, blogs and examples coming out in the next week, but try out this quick sample with simple intersecting layers and let us know if you have questions.

Entire expression for a single high school name:

var intersectLayer =Intersects(FeatureSetByName($map,"Elementary School Attendance Boundary"), $feature)

for (var f in intersectLayer){
return f.NAME
}

163 Comments
Devon_Hedemark
New Contributor

This is a very helpful blog post, much appreciated!

It does not appear that the Screening widget in Web AppBuilder displays the full pop-up from my web map (beta) when using this arcade expression to pull attributes from other feature layers. Is this correct?

I use the Screening widget to lookup locations by an address and any intersecting features, but it doesn't display the attributes with arcade expressions in the resulting popup.  If I click on the feature, the arcade attributes display in the pop-up just fine?

var intersectLayer = Intersects(FeatureSetByName($map, "Zoning"),Buffer($feature, -10, 'feet'))
var zones = ""
for (var f in intersectLayer){
zones = concatenate(zones,f.Zone_ID," ")
}
return zones

MichaelSeybert
Esri Contributor

Xander Bakker

I am trying to proof a concept of using arcade to output intersecting zip code boundaries in a popup.  I am not very familiar with arcade and I am curious if this might be able to support that use case?  In short, each location is going to have a different buffer size.  .25 miles - 5 miles.  I would then like to have the popup display the intersecting Zip Codes that fall on or within that drive-time boundary.  

Again, I am not very familiar with arcade and I am hoping that you can help!

Thanks. 

XanderBakker
Esri Esteemed Contributor

Hi Michael Seybert , 

If you start from a geometry (it doesn't matter if it is a point, polyline or polygon) you can, in the Arcade expression, create a variable buffer around it (is the size stored in an attribute of how you you determine it?) and than intersect the buffer polygon with a zip code layer and create a list of intersecting zip codes to display in the pop-up. If you have the data in ArcGIS Online, and you are willing to share it with me, you can create a group, share the map and necessary data to that group and invite my user "xbakker.spx" to the group and I can help you create the expression. 

MichaelSeybert
Esri Contributor

Hi Xander,

Unfortunately, I am not able to share the dataset.  However, in reality, it can be any point dataset with the following Schema:

  • Address
  • City
  • State
  • Zip
  • Territory Size (miles) (Note: these are not all the same...1.75mi, 2.5mi, 5mi, 4,75mi etc...)

 

Then I just used an underlying Zip Code layer for the U.S.  to complete the intersect.  Idea is to list the Zip Codes that touch or fall within the boundary in the Popup. 

XanderBakker
Esri Esteemed Contributor

Hi Michael Seybert ,

To give you an idea of the Arcade expression, have a look below:

// TODO: change the layer name and field names

// access the feature and the zip code layer
var f = $feature;
var fszip = FeatureSetByName($map,"Name of the zip code layer in the map");

// create buffer
var size = $feature["TerritorySize"]; 
var bufferpol = Buffer($feature, size, 'miles');

// Intersect with zip codes
var fszipint = Intersects(fszip, bufferpol);

// loop through resulting zip codes and create resulting text
var result = "";
var cnt = Count(fszipint);
if (cnt > 0 ) {
    // we have intersecting zip codes
    result = cnt + " zip code(s) found:"
    for (var zip in fszipint) {
        // add zip code to the resulting text
        var zipcode = zip["ZipCode"]; // change field name
        result += TextFormatting.NewLine + " - " + zipcode;
    }
    
} else {
    // no intersecting zip codes
    result = "No ZIP codes found";
}

return result;
JussiLehtonen
Esri Contributor

With the help of samples in geonet, I have been using the following to find areas that are within distance of the clicked feature. Works great.

var IntersectClose = Intersects(Buffer($feature, 2000, 'meters'), FeatureSetById($map, /* population */ "population"));
var cnt = Count(IntersectClose)

return cnt

What I would like to do is calculate the sum of population from all those neighboring areas. So instead of returning count, I'd like to return sum of population.

The necessary population info is in a "population" -field, so I should summarize that field from areas that are nearby and return it as my result.

Any pointers are welcome. 

XanderBakker
Esri Esteemed Contributor

Hi Jussi Lehtonen ,

According to the help, Intersects requires the FeatureSet to be the first parameter, so your example should not work (if the documentation is correct). It should be:

var IntersectClose = Intersects(FeatureSetById($map, /* population */ "population"), Buffer($feature, 2000, 'meters'));
var cnt = Count(IntersectClose);
return cnt;

To calculate the sum of the population of the returned features in the featureset called "IntersectClose", you can use the Sum function like this (assuming that the population field is called "Population"):

var IntersectClose = Intersects(FeatureSetById($map, /* population */ "population"), Buffer($feature, 2000, 'meters'));
return Sum(IntersectClose, "Population");

To optimize the part where you access the featureset, you may want to include the array with the field name and set the return geometry to false (still assuming that your field name with the population is called "Population"):

var IntersectClose = Intersects(FeatureSetById($map, /* population */ "population",  ["Population"], False), Buffer($feature, 2000, 'meters'));
return Sum(IntersectClose, "Population");
VHolubec
Esri Regular Contributor

Hello, 

is there a way how to use the Arcade against the MapService/Map Image layer if you want to use it over a bigger MapService from stand-alone server (30-50 layers), where you don´t want to add or register feature layers of the whole service one by one - which is quite time-consuming?

Thank you! 

John_Shell
New Contributor III

I did not notice if someone had asked about nested layers in a group and if you code those the same way in Arcade for the Popups to work correctly.

Thanks,

John 

JeffreyMotz
New Contributor

Can Arcade be used to determine (and display in a popup) elevation from a raster service?

aam
by
Occasional Contributor

Can this be done for the Map Image Layers?

aam
by
Occasional Contributor

Does it work with Feature Service only or can a map service layers would work too?

municipiobatalha
New Contributor

Is it possible to exclude from the results of the intersection the ones that only touch boundary?

About the Author
I love interactive maps and apps on the internet! The maps and apps that customers create and share on the web, make my job awesome. I'm a Product Manager with the ArcGIS Online team in Redlands, California. I am a proud graduate from Carleton University and the COGS in Canada, with research focus' in Health Geography. Originally from Bedford, NS, Canada but have spent a lot of time in Haliburton and Ottawa, Ontario. I have a passion for the outdoors and dogs.