Arcade Expression Popup question

608
8
Jump to solution
01-14-2022 05:22 AM
Labels (1)
DavidAdelsberg
New Contributor III

I would like to use an arcade expression for a popup window and use 2 different layers.  The main layer I'm using is tax parcel layer where I'll show:

Parcel #: {PARCELID}

Owner: {OWNERNME1}

Address: {SITEADDRESS}

 

I have those 3 fields with no issue for the popup.  Issue I have is trying to add a field from a CAUV layer that gives the land-use name using arcade expression.  What would be the expression I would use to add the CAUV land-use name/field from a map layer to my tax parcel pop-up? 

This is the result I would like to have:

Parcel #: {PARCELID}

Owner: {OWNERNME1}

Address: {SITEADDRESS}

 

LandUse:(this coming from a different layer within the map)

 

Any help would be greatly appreciated!  Thank you

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Honored Contributor

I'm assuming your landuse uses coded domains, then? That's an easy fix. To list all three results is actually simpler than the whole centroid thing, too. You may still want to use a negative buffer, just in case of slivers.

 

// Landuse
var lu = FeatureSetByName($map, "LandUse", ["landuse_type"])

// Slightly shring feature
var shp = Buffer($feature, -1)

// Get intersecting features
var xs = Intersects(lu, shp)

// Output string
var out_str = ''

// Populate string with intersected landuse features
for (var x in xs){
    var lu_name = DomainName(x, 'landuse_type')
    out_str += `${lu_name}, ` // you could use anything you want for a delimiter here. |, /n, whatever you like
}

// Trim off last two characters. In my example, you'll end up with a ", " at the end
out_str = Left(out_str, Count(out_str) - 2)

return out_str

 

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
8 Replies
JohannesLindner
MVP Regular Contributor

Assuming you want to get the land use by intersection with the parcel:

// load the land use layer
var fs_land_use = FeatureSetByName($map, "LandUse", ["*"], true)
// intersect the parcel feature with the land use layer
var fs_land_use_intersect = Intersects($feature, fs_land_use)
// get the first intersecting land use feature
var land_use_feature = First(fs_land_use_intersect)

// no land use feature? -> return null
if(land_use_feature == null) { return null }
// else return the land use field
return land_use_feature.LandUseField

Have a great day!
Johannes
0 Kudos
DavidAdelsberg
New Contributor III

Johannes,

I appreciate your time, but that didn't work.  I added that expression to my tax parcel configurable popup.  Attached is a pdf of 4 pages showing what I did and the layer I'm wanting to use to add to the popup window for my tax parcel. Maybe I did it wrong?   Not sure if showing this helps?  Thank you.

 

 

0 Kudos
JohannesLindner
MVP Regular Contributor

I didn't know your data structure, so I had to guess at the layer and field names. You should replace them with your real names.

Line 2: click on FeatureSetByName and replace my function with what you get

JohannesLindner_0-1642171139672.png

Line 11: replace LandUseField with Land_Use


Have a great day!
Johannes
0 Kudos
jcarlson
MVP Honored Contributor

We do this for some of our parcel maps, and we use a similar process to what @JohannesLindner  describes. I'd like to add a couple of points to the topic:

If the landuse and parcel layers do not align perfectly, you will have situations in which:

  1. Multiple landuses exist for a parcel
  2. A tiny sliver of adjacent landuse is included in the intersection, and mistakenly returned by the First function

If landuse and parcels overlay 1:1, that is, each parcel has 1 and only 1 landuse value, then consider modifying the parcel geometry prior to intersecting. You can:

  1. Buffer the feature by a negative distance to back away from the parcel boundaries a bit.
    Caveat: If the negative distance is too large, though, you will collapse to a null geometry and the intersection will return nothing.
  2. Intersect based on the centroid of the feature.
    Caveat: If the parcel has an irregular shape, the centroid may not fall within the feature itself, and your intersection will not be correct.

Of course, we can combine both approaches into one. A centroid-based intersection is simpler to perform, so we can default to that, resorting to the negative buffer if the input parcel shape is irregular.

// Landuse
var lu = FeatureSetByName($map, "LandUse", ["landuse_type"])

// Feature centroid
var c = Centroid($feature)

// Check if feature does not contain its own centroid
var irreg = !Contains($feature, c)

// If irregular shape, use negative buffer method
// Otherwise use centroid
if(irreg){
    var shp = Buffer($feature, -10)
    var xs = Intersects(shp, lu)
} else {
    var xs = Intersects(c, lu)
}

// Check if intersecting features found, return first landuse value
if(Count(xs) > 0){
    return First(xs)['landuse_type']
} else {
    return 'No landuse features found'
}

 

Mind that this expression is only returning a single value. If you want a delimited string of multiple intersected values, let me know, as I have an expression for that as well.

- Josh Carlson
Kendall County GIS
0 Kudos
DavidAdelsberg
New Contributor III

Josh,

Yes, could you give me a delimited string of multiple intersected values.  As I click on the parcel, there are 3 different land_use polygons within the 1 parcel and  only 1 result of the land_use shows. I take what you're saying would show all 3 land_use results in the popup?

Also, What you and Johannes gave me worked, but it's only showing the letter code of the land_use.  Why is it not showing the entire word?  I've attached 2 pictures, 1 showing what adding both of your expressions resulted in and the 2nd just showing the CAUV popup on it's own and what I want it to show--meaning full name of the landuse.  I appreciate your guys help.  This has been driving me nuts, as I'm not an arcade expression expert.

0 Kudos
jcarlson
MVP Honored Contributor

I'm assuming your landuse uses coded domains, then? That's an easy fix. To list all three results is actually simpler than the whole centroid thing, too. You may still want to use a negative buffer, just in case of slivers.

 

// Landuse
var lu = FeatureSetByName($map, "LandUse", ["landuse_type"])

// Slightly shring feature
var shp = Buffer($feature, -1)

// Get intersecting features
var xs = Intersects(lu, shp)

// Output string
var out_str = ''

// Populate string with intersected landuse features
for (var x in xs){
    var lu_name = DomainName(x, 'landuse_type')
    out_str += `${lu_name}, ` // you could use anything you want for a delimiter here. |, /n, whatever you like
}

// Trim off last two characters. In my example, you'll end up with a ", " at the end
out_str = Left(out_str, Count(out_str) - 2)

return out_str

 

- Josh Carlson
Kendall County GIS
0 Kudos
DavidAdelsberg
New Contributor III

Josh,

Thank you.  This worked.  After seeing it though, I'll have to decide whether I'll use it cause it is picking up some of the other adjacent parcels land_use, probably do to the buffering and as you said earlier, the 2 different layers not aligning perfectly.  I'll maybe tweak some of the numbers in your expression to see how the results go.

Overall, I appreciate your time and help! 

0 Kudos
jcarlson
MVP Honored Contributor

Happy to help! I used a negative buffer of -1 as an example, but in some of my maps I make that value as large as I can without collapsing any of my parcels, which is usually in the teens (of feet) somewhere.

- Josh Carlson
Kendall County GIS
0 Kudos