<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Pull Attribute from multiple layers into one layer using Arcade in ArcGIS Field Maps Questions</title>
    <link>https://community.esri.com/t5/arcgis-field-maps-questions/pull-attribute-from-multiple-layers-into-one-layer/m-p/1250735#M5197</link>
    <description>&lt;P&gt;Hi Johannes,&lt;/P&gt;&lt;P&gt;I need the id of the closest feature, no matter whether it's a point or a line.&lt;/P&gt;&lt;P&gt;Regarding 'm', this is accepted as meters. Have been using for some time with no issues. The same is also true for the null check, all works as expected.&lt;/P&gt;</description>
    <pubDate>Tue, 24 Jan 2023 12:29:13 GMT</pubDate>
    <dc:creator>RonParis</dc:creator>
    <dc:date>2023-01-24T12:29:13Z</dc:date>
    <item>
      <title>Pull Attribute from multiple layers into one layer using Arcade</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/pull-attribute-from-multiple-layers-into-one-layer/m-p/1250695#M5195</link>
      <description>&lt;P&gt;Bare with me on this...&lt;/P&gt;&lt;P&gt;The scenario I have is that I have users plot points on a map. These plotted points need a column populated with a unique value from other nearby points and lines ('id'). The issue I have is that these nearby points and lines are in different layers.&lt;/P&gt;&lt;P&gt;I am able to achieve when the nearby points are in one layer, however I am struggling to achieve this when there are multiple layers. Below is a snippet of the Arcade...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// FeatureClass2
var FeatureClass2 = FeatureSetById($map, /* Layer */ "***")


// Buffer FeatureClass1
var inspBuffer = Buffer($feature,1,'m')

// Undertake an intersection between FeatureClass2
// and FeatureClass1. 
// These 2 should intersect when used correctly
var inspIntersection = Intersects(FeatureClass2, inspBuffer)

// Calculate the distance between the parcel and the current location
// Store the feature and distance as a dictionary and push it into an array
var featuresWithDistances = []
for (var f in inspIntersection) {
    Push(featuresWithDistances, 
        {
            'distance': Distance($feature, f, 'm'),
            'feature': f
        }
    )
}


function sortByDistance(a, b) {
    return a['distance'] - b['distance']
}

var sorted = Sort(featuresWithDistances, sortByDistance)

var closestFeatureWithDistance = First(sorted)


// If there is no id, return null
if (IsEmpty(closestFeatureWithDistance)) { 
    return `${closestFeatureWithDistance['feature']['id']}`
}
else {
    return null
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TIA&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 10:28:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/pull-attribute-from-multiple-layers-into-one-layer/m-p/1250695#M5195</guid>
      <dc:creator>RonParis</dc:creator>
      <dc:date>2023-01-24T10:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: Pull Attribute from multiple layers into one layer using Arcade</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/pull-attribute-from-multiple-layers-into-one-layer/m-p/1250699#M5196</link>
      <description>&lt;P&gt;How should the extraced value look? Do you want the id of the closest feature, no matter if it's a point or line? Or do you want something like "closestpoint.id, closestline.id"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Things I noticed at a first glance:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;GYinspIntersection&lt;/STRONG&gt; and &lt;STRONG&gt;GYfeaturesWithDistances&lt;/STRONG&gt; are not defined&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Buffer&lt;/STRONG&gt; and &lt;STRONG&gt;Distance&lt;/STRONG&gt; have a unit attribute that takes the following values:&amp;nbsp;feet | kilometers | miles | nautical-miles | meters | yards. You supply "m". I haven't tested if that works as replacement for "meters", but it's best to avoid undocumented features.&lt;/LI&gt;&lt;LI&gt;Your null check is the wrong way around. Either check for &lt;STRONG&gt;!IsEmpty(...)&amp;nbsp;&lt;/STRONG&gt;(is not empty) or swap lines 37 and 40.&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Tue, 24 Jan 2023 10:23:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/pull-attribute-from-multiple-layers-into-one-layer/m-p/1250699#M5196</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-01-24T10:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Pull Attribute from multiple layers into one layer using Arcade</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/pull-attribute-from-multiple-layers-into-one-layer/m-p/1250735#M5197</link>
      <description>&lt;P&gt;Hi Johannes,&lt;/P&gt;&lt;P&gt;I need the id of the closest feature, no matter whether it's a point or a line.&lt;/P&gt;&lt;P&gt;Regarding 'm', this is accepted as meters. Have been using for some time with no issues. The same is also true for the null check, all works as expected.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 12:29:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/pull-attribute-from-multiple-layers-into-one-layer/m-p/1250735#M5197</guid>
      <dc:creator>RonParis</dc:creator>
      <dc:date>2023-01-24T12:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: Pull Attribute from multiple layers into one layer using Arcade</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/pull-attribute-from-multiple-layers-into-one-layer/m-p/1250798#M5198</link>
      <description>&lt;P&gt;OK for the "m", but the null check really should not work. Curious...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, here is one way to solve your problem:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// load the two (or more) feature classes
var featuresets = [
    FeaturesetByName($datastore, "TestLines"),
    FeaturesetByName($datastore, "TestPolygons"),
    ]
// get the id of the closest feature in a 1 meter radius
var f_buffer = Buffer($feature, 1, "meters")
var smallest_distance = 1000
var id = null
for(var i in featuresets) {
    var i_fs = Intersects(featuresets[i], f_buffer)
    for(var f in i_fs) {
        var d = Distance(f, $feature, "meters")
        if(d &amp;gt;= smallest_distance) { continue }
        smallest_distance = d
        id = f.id
    }
}
return id&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, this adds another for loop around your lines 11-23 to take care of different featuresets.&lt;/P&gt;&lt;P&gt;Personally, I like to write out custom Sort()s in a for loop (that is what happens under the hood in your code anyway) because then I can see what's happening all in one place. Plus, because I set the output variable to default to null (line 9), I can eliminate the null check at the end.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 14:38:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/pull-attribute-from-multiple-layers-into-one-layer/m-p/1250798#M5198</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-01-24T14:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: Pull Attribute from multiple layers into one layer using Arcade</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/pull-attribute-from-multiple-layers-into-one-layer/m-p/1250820#M5199</link>
      <description>&lt;P&gt;That's done the job. Thank you&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 15:34:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/pull-attribute-from-multiple-layers-into-one-layer/m-p/1250820#M5199</guid>
      <dc:creator>RonParis</dc:creator>
      <dc:date>2023-01-24T15:34:51Z</dc:date>
    </item>
  </channel>
</rss>

