Returning attributes from a FeatureSet where string values match

318
3
Jump to solution
02-12-2024 09:50 AM
Labels (2)
Ferreira
New Contributor II

Hello,

I've been trying to find a solution for a voting location tool for a local municipality. I understand that ESRI has something in place for a similar set up, but I am a bit confused if I can achieve something a little more elaborate with the data I got. Ideally, I'd like to set up an app where a resident can either:

    (1) Type their address and a voting precinct/voting location gets selected and popup is shown (Not sure if        this is going to work).

    (2) Click or type a precinct and a popup showing the respective voting location to that precinct shows up.

Would an instant app give me the capabilities for it, or would it require an Experience Builder approach?

The data I am working with entails two FeatureSets. One is polygon feature showing voting precincts, and the second is a point feature for the actual voting locations. These voting locations aren't always located inside the voting precinct that they represent - so doing a spatial intersect, or zone lookup wouldn't work. Also, some voting locations are used for more than one precinct.

Both features have a PRECINCTCODE column. The only difference is that the voting precinct has only one value per line, while the location has multiple values separated by a comma, as shown below.

Voting Location:

OBJECTID PRECINCTCODE

1"2011"
2"2022, 2024"
3"2002, 2023, 2026"
4"2012, 2020"
5"2001"
6"2007"
7"2017"
9"2003"
10"2004, 2008"
11"2005, 2025"
12"2018"
13"2010, 2013, 2016"
14"2009, 2019"
15"2021"
16"2015"
17"2014"
18"2006"

 

I did find this post that I believe points me in the right direction (see below). But I'm getting stuck on querying the string data and using perhaps a Split function(?), in order to look at these precinct code values separately.

How do you reference another field from a related ... - Esri Community

This is probably a very simple task, but my limited knowledge of arcade has been setting me back for a while. I apologize if this issue has previously been addressed in a different post already.

 

Thanks in advance,

Caio

0 Kudos
1 Solution

Accepted Solutions
JohnEvans6
Occasional Contributor

It's a bit of a challenge to do without your data, but maybe something like

// Build query that gets takes your polygon precinct id and compares it against the polling place PRECINCTCODE
var ident = Concatenate("'%",$feature.PRECINCTCODE,"%'")

// Build Query polling place where code matches with a wildcard
var sql = Concatenate("PRECINCTCODE LIKE",ident)

// Get your polling place feature based on query. Update with your Polling Place layer name
var features = Filter(FeatureSetByName($map, "Polling Places"), sql)

// DESCRIPTION Should be whatever your polling place name is or whatever other fields you want to build as your output. Really this will just return 1 feature. You should include some error checking here if features are empty.
For (var f in features) {
  var polling_place = f.DESCRIPTION
}

var str_output = Concatenate("My polling place for this precinct is: ",polling_place)

return { 
	type : 'text', 
	text : str_output
}

View solution in original post

3 Replies
JohnEvans6
Occasional Contributor

It's a bit of a challenge to do without your data, but maybe something like

// Build query that gets takes your polygon precinct id and compares it against the polling place PRECINCTCODE
var ident = Concatenate("'%",$feature.PRECINCTCODE,"%'")

// Build Query polling place where code matches with a wildcard
var sql = Concatenate("PRECINCTCODE LIKE",ident)

// Get your polling place feature based on query. Update with your Polling Place layer name
var features = Filter(FeatureSetByName($map, "Polling Places"), sql)

// DESCRIPTION Should be whatever your polling place name is or whatever other fields you want to build as your output. Really this will just return 1 feature. You should include some error checking here if features are empty.
For (var f in features) {
  var polling_place = f.DESCRIPTION
}

var str_output = Concatenate("My polling place for this precinct is: ",polling_place)

return { 
	type : 'text', 
	text : str_output
}
Ferreira
New Contributor II

Thank you so much, John! It worked like a charm! Now I'm able to select the precinct and the pop up will show the voting location.

Ferreira_1-1707855016957.png Ferreira_2-1707855042515.png

 

I'm still trying to figure out how I'd go about having the voting location feature get selected once the user queries a precinct, for example. As it shows in the first screenshot, when I select the precinct, it'll give me the address and location name - which is already great. However, since for that precinct the location is actually not within the precincts boundaries, I have to manually select the voting place.

I'm wondering if there's any tweaking around a quick app to make this happen, or if I'll just have to use Experience Builder to trigger this kind of action. Any suggestions?

Again, thank you so much for your help! 🙂

 

0 Kudos
JohnEvans6
Occasional Contributor

There's not really a lot of options via arcade for that. If you enable search on your polling place you could use the find parameter to add a URL to the summary window, but that basically opens the same map at the same place in a new tab with the polling place selected, which feels redundant. If its a good enough work around, just append

&find=856
 
or whatever the polling place precinct number is.
0 Kudos