<?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>idea Arcade Nearest Feature Function in Developers Ideas</title>
    <link>https://community.esri.com/t5/developers-ideas/arcade-nearest-feature-function/idi-p/1670770</link>
    <description>&lt;P&gt;I think it would be beneficial to include an Arcade function that finds the nearest feature (or potentially features) from a featureSet to a specific feature/geometry.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a routine task that has been asked about several times before across the various forums:&lt;BR /&gt;&lt;A href="https://community.esri.com/t5/arcgis-online-questions/using-arcade-to-find-the-nearest-address-point/m-p/108741#M5171" target="_blank"&gt;https://community.esri.com/t5/arcgis-online-questions/using-arcade-to-find-the-nearest-address-point/m-p/108741#M5171&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-online-questions/arcade-get-4-nearest-addresses-from-point-feature/m-p/463470#M23381" target="_blank"&gt;https://community.esri.com/t5/arcgis-online-questions/arcade-get-4-nearest-addresses-from-point-feature/m-p/463470#M23381&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-field-maps-questions/nearest-address-calculation-expression-in-field/m-p/1176989#M3585" target="_blank"&gt;https://community.esri.com/t5/arcgis-field-maps-questions/nearest-address-calculation-expression-in-field/m-p/1176989#M3585&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have written my own code to get my desired result here:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var portalItem = FeatureSetByPortalItem(Portal('https://redacted.com/portal'), 'redactedportalitemid', 1, ["featureDescription"], true)
var inputFeature = $feature
var nearestFeature
var relevantFeaturesBuffer = Buffer($feature, 500, "meters")
var relevantFeatures = Intersects(portalItem, relevantFeaturesBuffer)

function compareShortestDistance(a,b){
  return Distance(Geometry(a), Geometry(inputFeature)) - Distance(Geometry(b), Geometry($feature))
}

for (var feature in relevantFeatures){
  if (nearestFeature == null) {
    nearestFeature = feature
  } else if (compareShortestDistance(nearestFeature, feature) &amp;gt; 0){
    nearestFeature = feature
  }
}

return nearestFeature.featureDescription&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This does work and meet my needs, however I feel that it is still inefficient. You may notice that there is a buffer and intersection used to filter "relevant" features that are nearby (hardcoded 500m). This is necessary because if the portalItem contains a large number of features then the distance comparison becomes prohibitively slow. If instead there is a nearest function created by ESRI it should be possible to better optimize the function by taking advantage of backend tools like spatial indexes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm proposing is a function like such:&lt;BR /&gt;Nearest(featureSet, feature/geometry, numberOfReturnedFeatures?) =&amp;gt; feature/featureSet&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Dec 2025 02:45:55 GMT</pubDate>
    <dc:creator>GeoGalvanic</dc:creator>
    <dc:date>2025-12-05T02:45:55Z</dc:date>
    <item>
      <title>Arcade Nearest Feature Function</title>
      <link>https://community.esri.com/t5/developers-ideas/arcade-nearest-feature-function/idi-p/1670770</link>
      <description>&lt;P&gt;I think it would be beneficial to include an Arcade function that finds the nearest feature (or potentially features) from a featureSet to a specific feature/geometry.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a routine task that has been asked about several times before across the various forums:&lt;BR /&gt;&lt;A href="https://community.esri.com/t5/arcgis-online-questions/using-arcade-to-find-the-nearest-address-point/m-p/108741#M5171" target="_blank"&gt;https://community.esri.com/t5/arcgis-online-questions/using-arcade-to-find-the-nearest-address-point/m-p/108741#M5171&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-online-questions/arcade-get-4-nearest-addresses-from-point-feature/m-p/463470#M23381" target="_blank"&gt;https://community.esri.com/t5/arcgis-online-questions/arcade-get-4-nearest-addresses-from-point-feature/m-p/463470#M23381&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-field-maps-questions/nearest-address-calculation-expression-in-field/m-p/1176989#M3585" target="_blank"&gt;https://community.esri.com/t5/arcgis-field-maps-questions/nearest-address-calculation-expression-in-field/m-p/1176989#M3585&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have written my own code to get my desired result here:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var portalItem = FeatureSetByPortalItem(Portal('https://redacted.com/portal'), 'redactedportalitemid', 1, ["featureDescription"], true)
var inputFeature = $feature
var nearestFeature
var relevantFeaturesBuffer = Buffer($feature, 500, "meters")
var relevantFeatures = Intersects(portalItem, relevantFeaturesBuffer)

function compareShortestDistance(a,b){
  return Distance(Geometry(a), Geometry(inputFeature)) - Distance(Geometry(b), Geometry($feature))
}

for (var feature in relevantFeatures){
  if (nearestFeature == null) {
    nearestFeature = feature
  } else if (compareShortestDistance(nearestFeature, feature) &amp;gt; 0){
    nearestFeature = feature
  }
}

return nearestFeature.featureDescription&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This does work and meet my needs, however I feel that it is still inefficient. You may notice that there is a buffer and intersection used to filter "relevant" features that are nearby (hardcoded 500m). This is necessary because if the portalItem contains a large number of features then the distance comparison becomes prohibitively slow. If instead there is a nearest function created by ESRI it should be possible to better optimize the function by taking advantage of backend tools like spatial indexes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm proposing is a function like such:&lt;BR /&gt;Nearest(featureSet, feature/geometry, numberOfReturnedFeatures?) =&amp;gt; feature/featureSet&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Dec 2025 02:45:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-ideas/arcade-nearest-feature-function/idi-p/1670770</guid>
      <dc:creator>GeoGalvanic</dc:creator>
      <dc:date>2025-12-05T02:45:55Z</dc:date>
    </item>
  </channel>
</rss>

