In need of help with Arcade expressions

568
3
11-15-2019 05:41 AM
AdamMajzoub
New Contributor

I have two features in my map. A polygon feature and a point feature. I would like to join the polygon feature to the point feature using a common field. All the points are contained within the polygons. I have about 2000 points and 100's of polygons. I have tried using the Arcade expression below to calculate the join field in my point features to populate it with the unique identifier of the polygon:

var intersectLayer =Within(FeatureSetByName($datastore, "Polygon"),Geometry($feature))

 

var address = ""

 

var cnt = 0

 

for (var f in intersectLayer){

    if (cnt == 0){

    address = f.oaddr2

}

    else {address = "No Address Found"}

}

return address

 

I am still very inexperienced with coding, so I apologize if my question is not entirely clear. 

Tags (2)
0 Kudos
3 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Adam,

Are you trying to add attributes to a pop-up based on an intersection?  If you are, have you seen the following document:

https://community.esri.com/community/gis/web-gis/arcgisonline/blog/2018/12/10/overlapping-features-i... 

AdamMajzoub
New Contributor

Thank you for this. This is useful!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Adam Majzoub ,

There are a couple of things wrong with the expression. First of all you cannot provide a FeatureSet to the Within function. It requires geometries. If you only want to have a single address, you don't need to loop through the results. See the example below:

var intersectLayer = Intersects($feature, FeatureSetByName($datastore, "Polygon"));
var address = ""
var cnt = Count(intersectLayer);
if (cnt == 0) {
    address = "No Address Found";
} else {
    address = First(intersectLayer).oaddr2;
}

return address;‍‍‍‍‍‍‍‍‍‍