Select to view content in your preferred language

Arcade - Intersecting Polygons - return multiple answers if multiple.

1562
11
Jump to solution
12-12-2019 10:47 AM
TrishaSchlake
New Contributor III

Hi Xander Bakker

 

I have a parcel feature layer and a soils feature layer in my webmap. I'm trying to apply the arcade to my parcels layer so that when a parcel is clicked it will give me the corresponding soils to that parcel. The issue is that there could be more than one soil per parcel. The expression I currently have applied to my parcel feature class is this: 

 

 var intersectLayer = Intersects(FeatureSetByName($map,"STATSGO2Soils"), $feature)
for(var f in intersectLayer){
return f.muname
}

 

But it will only return one of my soils into the parcel and will not bring in multiple soils names. Is there a way to do what I'm hoping to do? 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Try this instead.

var intersectLayer = Intersects(FeatureSetByName($map,"STATSGO2Soils"), $feature)
var results = "";
for(var f in intersectLayer){
  if (results == "") {
    results = f.muname;
  } else {
    results += ", " + f.muname;
  }
}
return results;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This would be another way

var intersectLayer = Intersects(FeatureSetByName($map,"STATSGO2Soils"), $feature)
var results = [];
for(var f in intersectLayer){
  results[Count(results)] = f.muname;
}
return Concatenate(results, ", ");‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

11 Replies
KenBuja
MVP Esteemed Contributor

Try this instead.

var intersectLayer = Intersects(FeatureSetByName($map,"STATSGO2Soils"), $feature)
var results = "";
for(var f in intersectLayer){
  if (results == "") {
    results = f.muname;
  } else {
    results += ", " + f.muname;
  }
}
return results;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This would be another way

var intersectLayer = Intersects(FeatureSetByName($map,"STATSGO2Soils"), $feature)
var results = [];
for(var f in intersectLayer){
  results[Count(results)] = f.muname;
}
return Concatenate(results, ", ");‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Amarz
by
Occasional Contributor II

@KenBuja 

This is a very helpful code, but I am wondering is there a way to add a -1ft buffer or something? I am getting all polygons that share a border with the parcel but are not necessarily in the parcel.

Also would it be possible to add an OrderBy ASC to the script?

0 Kudos
KenBuja
MVP Esteemed Contributor

You can use additional chaining to add those extra functions to get the intersect layer

var intersectLayer = OrderBy(
  Intersects(
    Buffer(
      FeatureSetByName(
        $map,
        "STATSGO2Soils"
      ),
      -1, 
      'feet'
    ), 
    $feature
  ),
 'Muname DESC'
);
0 Kudos
Amarz
by
Occasional Contributor II

Thanks for coming back to this Ken!

0 Kudos
Amarz
by
Occasional Contributor II

Hey Ken, sorry to come back, I am attempting to utilize this section in the above script using my own values but am getting the following error: 

 

Invalid Expression. Error on line 19. Identifier expected.
var intersectLayer = OrderBy(
  Intersects(
    Buffer(
      FeatureSetByName(
        $map,
        "STATSGO2Soils"
      ),
      -1, 
      'feet'
    ), 
    $feature
  ),
 'Muname DESC'
);
var results = [];
for(var f in intersectLayer){
  results[Count(results)] = f.muname;
}
return Concatenate(results, ", ");‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

Any advice?

 

0 Kudos
KenBuja
MVP Esteemed Contributor

My apologies...I had the syntax incorrect. Give this a try (using your own layer and field names)

var intersectLayer = OrderBy(
  Intersects(
    FeatureSetByName($map, "other layer"),
    Buffer($feature, -1, "feet")
  ),
  "sortField DESC"
);
var results = [];
for (var f in intersectLayer) {
  results[Count(results)] = f["displayField"];
}
var output = Concatenate(results, ", ");

 

 

 

Amarz
by
Occasional Contributor II

Any idea what is causing the following error? I ran the Check Geometry on both layers participating in this intersect with 0 errors.

ERROR 002717: Invalid Arcade expression, Arcade error: Invalid search geometry, Script line: 9
Failed to execute (CalculateField).

 

0 Kudos
KenBuja
MVP Esteemed Contributor

Could you post your code to see what's on line 9? I'm wondering if there's a null geometry in your data. I tested this on the USA States and USA Major Cities dataset from the Living Atlas and didn't get any errors.

0 Kudos
Amarz
by
Occasional Contributor II

Deleting previous chat cause it wasn't relevant.

@KenBuja Thank you for all your help! I figured it out. The layer I was using had the ever dreaded Slivers in it that were less than 1ft causing the geometry error. 

The code it working as expected when I reduced the negative buffer.

Thank you so much!

0 Kudos