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

61974
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
XanderBakker
Esri Esteemed Contributor

Hi Kelly Gerrow , 

Thanks for sharing this blog! Any idea when the online help of ArcGIS Arcade | ArcGIS for Developers will reflect the new features in version 1.5 ? At this moment it is still showing version 1.4 (July):

KellyGerrow
Esri Frequent Contributor

Hi,

It was just updated. You can find feature set doc here:

Data Functions | ArcGIS for Developers 

-Kelly

XanderBakker
Esri Esteemed Contributor

Great, thank you Kelly! 

JohnLucotch2
Occasional Contributor

I'm assuming this isn't available in Portal yet?

RobertScheitlin__GISP
MVP Emeritus

John,

  That would be No. See this release info link:

About release versions—Portal for ArcGIS | ArcGIS Enterprise 

XanderBakker
Esri Esteemed Contributor

I suspect that this will be included in the March release of ArcGIS 10.7.

JohnLucotch2
Occasional Contributor

Thanks.  Just determining a route to proceed with. 

KellyGerrow
Esri Frequent Contributor

Yes, This is planned to be included with the next ArcGIS Enterprise release. (10.7)

KellyGerrow
Esri Frequent Contributor

Check out this blog by Paul Barker about Feature Sets:

What’s new with Arcade: Taking a stroll through FeatureSets (Part 1) 

XanderBakker
Esri Esteemed Contributor
by Anonymous User
Not applicable

Is it also possible to use the position off the mouseclick instead off $feature within the Intersects function?

XanderBakker
Esri Esteemed Contributor

I don't think that is possible (at least I haven't seen a functionality exposed in Arcade that does that. Could you explain a little better what you would like to achieve?

HeatherWidlund
Occasional Contributor

Thank you, Xander. I was able to use the negative buffer example you provided in your blog - very helpful! Also, I created an if... else to determine if more than one polygon was intersected and return different expressions.

var buff = Buffer($feature,-10,'feet')
var intersectsLayer = Intersects(FeatureSetByName($map,"Zoning"),buff)
var intcount = Count(intersectsLayer)
var expr = ''
if(intcount>1) {
    expr = 'Multiple regulations apply. Contact appropriate Planning Department.'
}
else {
   for(var f in intersectsLayer){
      var zone = f.ZONING
      expr = Proper(zone)
   }
}
return expr

You could also return multiple values by iterating and adding to the expression before returning it, but the lack of a new line capability in AGOL makes this unworkable for me.

XanderBakker
Esri Esteemed Contributor

Hi Heather Widlund , 

Great to hear that you successfully made use of the new Arcade functions! Please post a screenshot of the result.

Actually the "TextFormatting.NewLine" works in the pop-up and you can create a new line for each entry as show below:

The document you referenced Using FeatureSetBy functions in Arcade to drill-down to other layers and tables shows how you can do this.

HeatherWidlund
Occasional Contributor

I was led astray by old documentation, I guess - not the first time. Thanks for the tip! I decided not to do the multiple results for other reasons, but here are my two pop-ups, consisting of two expressions drilling down from one polygon layer to another.

pop up window pop up window

BrianFausel
Occasional Contributor III

Is it safe to say that this functionality does not work if the web map contains ArcGIS Enterprise "Map Image Layers" (formerly known as ArcGIS Server Dynamic Map Services)? I tried setting it up with those in the web map and I was not able to access the Global "$map" entity. As a result the Arcade Expression does not work. But when I add hosted feature layers from ArcGIS Online to the web map it does work. I also assume this would work with an ArcGIS Enterprise feature layer, but I'll have to wait to test that in the future when we have the on-site Portal set up.

HeatherWidlund
Occasional Contributor

I tried the same thing. It doesn't work with Map Image Layers. I haven't tried it with hosted Enterprise feature layers.

deleted-user-hIRaiUqzOdC_
New Contributor II

When I attempt to create an expression, similar to the example, I receive this error... Any ideas as to why? AGOL, not portal.

HeatherWidlund
Occasional Contributor

That's the error I got when I tried to use a source that was not a hosted feature layer (it was a map image layer published from ArcGIS Server). It doesn't have an object $map because it's not the right kind of source.

BrianFausel
Occasional Contributor III

That is also the same error I encountered when I used a map image layer from ArcGIS Server. Error did not happen when using a hosted feature layer from AGOL.

NedCake1
Occasional Contributor

The expression will work for AGS layers if you register the individual layers in your AGS map service as feature layers in AGOL (by their map index number).  Then add the registered feature layers to your web map. The globals for $map, $feature, $layer, and $datastore will appear in the expression builder.

Hope that helps

Ned

KenMorefield
Occasional Contributor

Hi all,

This is exciting stuff!  I'm still fairly new to Arcade.  Can anyone tell me if these Arcade Expressions with FeatureSets will work in Collector?  If they will work in Collector, will they work in an offline Collector application that has syncing enabled?

I have some end users that could really use some of this functionality to quickly determine some summary info while "disconnected" in the field.

Thanks!

Ken 

XanderBakker
Esri Esteemed Contributor

I just did a small test on Collector (Aurora, iPad) and it seems that there is still not full support for Arcade. I do expect that the new functions will be supported in the future. 

BrianFausel
Occasional Contributor III

I tried this and it did not seem to work for me. Perhaps it is a version issue? I am using a really old AGS stack at the moment (AGS 10.3.1, Enterprise GDB in SQL Server 2008 R2). Out of curiosity what version are you running, Ned?

KyleWikstrom
Occasional Contributor II

This is just SUPER! This ability is very much appreciated!

It does not appear that the Near Me widget in Web AppBuilder supports this capability yet. Is this in fact the case? We like to use the Near Me widget to lookup locations and any intersecting features, but it doesn't seem like the Arcade expressions want to print results in the Near Me resulting popup configuration.

NedCake1
Occasional Contributor

Kyle,

My tests confirm your findings. My group uses the Near Me widget in a similar fashion so this is a significant limitation for us too.

Any thoughts or potential work around ideas from ESRI Staff?

Thanks

XanderBakker
Esri Esteemed Contributor

Due to performance issues I guess this functionality has been limited. You can however do a field calculation and use the Arcade functions to create a new field and that one will be available in all the widgets. The donwside is that the values in the new field will not update when a feature changes or new features are created.

AllisonMuise1
Occasional Contributor III

Kyle WikstromNed Cake‌ This is a known issue with Near Me right now. We're planing to include a fix in the next release of WebAppbuilder/ArcGIS Online.

-Allison

NedCake1
Occasional Contributor

Sounds Great Allison!

Thanks for the quick response.  Will the fix find its way into the WAB Developer Edition also?

Thanks

Ned

AllisonMuise1
Occasional Contributor III

Yes, it will.

NedCake1
Occasional Contributor

Hi Brian,

We are at AGS 10.4.1 with multiple load balanced servers in pairs. The services consume layer content from a local FGDB on each ArcGIS Server (updated daily).

Are you unable to register the individual service layers by index number?

KyleWikstrom
Occasional Contributor II

I've been using this capability already and it is just awesome! Very useful!

Not being an expression language person, I want to ask if Arcade expressions can support displaying related table (1:M) popup configurations within the feature popup as well. The scenario is that there are multiple layers each representing an elected official district (State Senate, State Legislature, etc.) and there is a single table with representative information. Each layer has a 1:M relationship with the representative table. Users desire to select a single location on the map, view one popup with the concatenated feature popup information, as this blog goes through, but with the ADDITIONAL capability to view the related table records in the same popup. What would an expression like this look like? Guidance?

Thanks much!

Kyle

XanderBakker
Esri Esteemed Contributor

Arcade allows you to access related features (although I think you will have to use the Filter function and construct the SQL query to get to the related records of multiple layer. They will however no appear as links in the pop-up. 

When you implement an Arcade expression in teh pop-up of a layer, and the user click on a polygon, you will only have the polygon geometry of the layer the user clicked on and not the point location. You can use spatial or attribute relationships to navigate to any related data (as long as it is in the map or published in the same datastore) and analyze the data and include the result in the pop-up. Can you show an example of how the State Senate and State Legislature districts spatialy relate?

KyleWikstrom
Occasional Contributor II

I'll share the web map URL. https://pwa.maps.arcgis.com/home/webmap/viewer.html?webmap=1ce2978ffec44e15a4fce1a58484fdb2  

Each of the district layers has a relationship class (1:M) with a Representatives table that contains all representative information. A single location on the map has 4 intersecting features, and each feature is from a separate layer (State Legislature Districts, State Senate Districts, US Congressional Districts, and US Senate Districts). Each feature has a District Name attribute that is used as the key in the relationship class, and the Representatives table also has a District Name attribute which is that table's key. The features are related to records in the table via a single attribute.

XanderBakker
Esri Esteemed Contributor

As an example what can be done (probably not what you want, but just to help explain the concept):

In this case I configured the expression on the Voting District layer and added the expression to the custom HTML pop-up you have.

In this case it does a spatial intersect with the layer Minnesota Legisature and reads out the "DISTRICTNAME". It also reads the attribute "MNLEGDIST" of the voting districts and filters the representatives table to get the related names.

Below the code I used (it is slow since it contains multiple requests to the server):

// var USS = Intersects(FeatureSetByName($map,"US Senate"), $feature);
// var USC = Intersects(FeatureSetByName($map,"US Congress"), $feature);
// var MNS = Intersects(FeatureSetByName($map,"Minnesota Senate"), $feature);
var mnls = Intersects(FeatureSetByName($map,"Minnesota Legislature"), $feature);
var mnl_info = "";
for (var mns in mnls) {
    if (mnl_info == "") {
        mnl_info = " - " + mns.DISTRICTNAME;
    } else {
        mnl_info += TextFormatting.NewLine + " - " + mns.DISTRICTNAME;
    }
}

var mnleg_distr = $feature.MNLEGDIST;
var tbl_REP = FeatureSetByName($map,"Representatives");
var sql = "DistrictID = '" + mnleg_distr + "'";
var REP_distr = Filter(tbl_REP, sql);

var reps = "";
for (var rep in REP_distr) {
    if (reps == "") {
        reps = " - " + rep.RepresentativeName;
    } else {
        reps += TextFormatting.NewLine + " - " + rep.RepresentativeName;
    }
}

var info = "Located in Minnesota Legislature:";
info += TextFormatting.NewLine + mnl_info;
info += TextFormatting.NewLine + "Representatives:"
info += TextFormatting.NewLine + reps;
return info;
HeatherStudley1
New Contributor III

I'm not sure if this is what Chris is looking for, but in my case it would be clicking on a property outline and having the Intersect use that feature (to, say, find out what your building zones are or if you're in a flood zone).

KenMorefield
Occasional Contributor

Hi Xander,

I don't mean to hijack this thread, but I thought maybe you could help me with an Arcade example that I'm working on.  I have a linear stream layer that represents all streams within the state of California.  This layer does not change at all.  I also have a point layer representing pollution.  These points are collected on iPads in the field and are constantly changing.  I'm trying to set up an Arcade FeatureSet to buffer the selected feature by 150 feet, and then if that buffer intersects one or more of the streams, to return the stream name(s).  I have this working just fine using this Arcade code:

var bufferPt = Buffer($feature, 150, 'feet');
var intersectStream = Intersects(bufferPt, FeatureSetByName($map, "California Streams"));
    for (var f in intersectStream){

        return f.DFGWATERID

    }

There are a couple of issues.  This seems to work when only one stream is within 150 feet.  But if there are two or more, it returns blank.  The more concerning issue is that it takes right at 60 seconds to calculate and then populate the popup.  I'm sure this has to do with the fact that there are 740,662 streams in the stream layer.  So I think the calculation might be running through all streams, checking to see if they intersect the 150 foot buffer of the pollution point.  Do you have any guidance on how to first filter the streams layer so that it doesn't take 60 seconds to run?  Or any other suggestions for speeding up the Arcade calculation? 

Thanks,

Ken

XanderBakker
Esri Esteemed Contributor

Hi Heather Studley , in your case the click will select the property and the property would have the expression in the pop-up window and drill down to the building zone and/or flood zone. In case of beaart  he would like to use the point where the user clicked to do some analysis. Since the arcade expression lives in the pop-up of a feature you would start off with a feature and that might be a big feature resulting in too many or inprecise results. 

XanderBakker
Esri Esteemed Contributor

Hi Ken Morefield ,

60 seconds to intersect a buffered point with almost 750K streams is not very long. However, 60 seconds for a user to wait that a pop-up is returned is eternal. 

In this blog What’s new with Arcade: Taking a stroll through FeatureSets Part 2  by Paul Barker‌ he mentions at the end a couple of keys things to remember:

  • Define the minimum needed FeatureSets required to do the job
  • Always reduce your FeatureSets when you can
  • Filtering by attributes will always be faster than filtering by geometry
  • Chain functions together when possible to reduce queries
  • Use stats and sorting to avoid unnecessary loops
  • Review Part 1 of this blog series

Reviewing your process I don't think you will be able to bring the processing time down to an acceptable level. What you could do is rather than putting this logic dynamically in the pop-up is to add a field a use the Arcade Expression in a Field Calculation. The downside of this, is that the result will be static and new point collected in the field will not have a value. So you could try and script it to run the field calculation every night. Ideally, a field calculation would have a setting to make it repeat the process with a defined interval (like every night), but this functionality is not available, so for now you would probably have to use the ArcGIS Python API to do this for you. In  the future I'm sure that Attribute Rules will come to ArcGIS Online and this can be accomplished with a Calculation Attribute Rule.

XanderBakker
Esri Esteemed Contributor

BTW, I would probably change the expression to this to handle multiple intersects:

var intersectStream = Intersects(Buffer($feature, 150, 'feet'), FeatureSetByName($map, "California Streams"));
var streams = "";
for (var f in intersectStream) {
    if (streams == "") {
        streams = "Intersecting stream(s):" + TextFormatting.NewLine + " - " + f.DFGWATERID;
    } else {
        streams += TextFormatting.NewLine + " - " + f.DFGWATERID;            
    }
}
return streams;
‍‍‍‍‍‍‍‍‍‍
KellyGerrow
Esri Frequent Contributor

Hi Brian,

This should work as Ned described. I'd suggest getting in touch with tech support to dig into the specific issue if you are still running into issues.

-Kelly

TimothyKing3
Occasional Contributor

Can the data that is added to the popup be sent to Survey123 from Collector?  It would be great to have additional data from other feature services that could be ported over to 123. 

XanderBakker
Esri Esteemed Contributor

Yes you can do this. You can create a URL that includes parameters to pre-fill the survey: https://community.esri.com/groups/survey123/blog/2016/07/30/understanding-survey123s-custom-url-sche... Any information you have access to using the FeatureSetBy* functions can be included in the URL to pre-fill the Survey

TimothyKing3
Occasional Contributor

Thanks Xander,

I went through the tutorials and am very excited about these tools.  I was able to get the popups to show the additional Attribute Expressions but they did not show up in either Collector Classic or Explorer.  Is there something I am missing?

Thanks,

LTK

XanderBakker
Esri Esteemed Contributor

No, you are not missing something. In Collector Classic there is no support for Arcade. There is Collector (Aurora). Not so sure about Explorer, but perhaps not yet (also depending on the OS, since iOS is normally a bit ahead of Android development).

deleted-user-hIRaiUqzOdC_
New Contributor II

Is this not supported for the Arc Explorer app yet? Will there be an update soon to fix that?

TimothyKing3
Occasional Contributor

Thanks Xander,

I loaded up the new Collector on my iPad and although the newly created attribute fields displayed, they were empty.  I was looking at it live and had not downloaded the map for offline use.  Does arcade work using Collector directly or do the maps have to be downloaded. 

Thanks,

LTK

XanderBakker
Esri Esteemed Contributor

As far as I know, parts of Arcade work in the new Collector. For existing features in the pop-up you can see the result, however, they wont work on symbology. You mentioned that when creating new features, the on Arcade based attributes do not show. In case the field was calculated in the Field Calculator of ArcGIS Online this makes sense. In case you are referring to the pop-up, then I guess this part of Arcade in Collector is not implemented yet.

TimothyKing3
Occasional Contributor

Thanks Xander,

So that would mean that that Arcade calculated data using FeatureSets  i.e. topo name, number of tests within an area, can't be sent to Survey123 via the URL Scheme

XanderBakker
Esri Esteemed Contributor

In case the URL is constructed inside Collector that might be true (for the moment). In case you construct the URL to pre-populate the Survey inside the pop-up of a web map, that is working, since the URL is constructed with strings that are the result of the Arcade expression and those will persist. 

Are you starting Survey using Collector? What information are you trying to send to Survey?

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.