<?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 The nearest school district calculation in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/the-nearest-school-district-calculation/m-p/1091699#M188</link>
    <description>&lt;P&gt;Hello I am working on a calculation rule that inputs the nearest school district from a polygon feature. The problem I am having is that the rule is bringing back the school district that the polygon is within. I would like it to calculate the nearest (if any) school district within 1 mile. Is this possible. I have the following below.... Thanks in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var SCHOOL_DIST = FeatureSetByName($datastore, "SCHOOL_DIST", ["NAME"]);&lt;BR /&gt;VAR SEARCHDISTANCE = 1;&lt;BR /&gt;VAR SCHOOLINTERSECT = INTERSECTS(SCHOOL_DIST, BUFFER($FEATURE, SEARCHDISTANCE, "MILE"))&lt;BR /&gt;VAR FSCHOOL = FIRST(SCHOOLINTERSECT)&lt;BR /&gt;IF (FSCHOOL == NULL) RETURN ""&lt;BR /&gt;RETURN FSCHOOL.NAME&lt;/P&gt;</description>
    <pubDate>Tue, 24 Aug 2021 13:51:43 GMT</pubDate>
    <dc:creator>Robswann</dc:creator>
    <dc:date>2021-08-24T13:51:43Z</dc:date>
    <item>
      <title>The nearest school district calculation</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/the-nearest-school-district-calculation/m-p/1091699#M188</link>
      <description>&lt;P&gt;Hello I am working on a calculation rule that inputs the nearest school district from a polygon feature. The problem I am having is that the rule is bringing back the school district that the polygon is within. I would like it to calculate the nearest (if any) school district within 1 mile. Is this possible. I have the following below.... Thanks in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var SCHOOL_DIST = FeatureSetByName($datastore, "SCHOOL_DIST", ["NAME"]);&lt;BR /&gt;VAR SEARCHDISTANCE = 1;&lt;BR /&gt;VAR SCHOOLINTERSECT = INTERSECTS(SCHOOL_DIST, BUFFER($FEATURE, SEARCHDISTANCE, "MILE"))&lt;BR /&gt;VAR FSCHOOL = FIRST(SCHOOLINTERSECT)&lt;BR /&gt;IF (FSCHOOL == NULL) RETURN ""&lt;BR /&gt;RETURN FSCHOOL.NAME&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 13:51:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/the-nearest-school-district-calculation/m-p/1091699#M188</guid>
      <dc:creator>Robswann</dc:creator>
      <dc:date>2021-08-24T13:51:43Z</dc:date>
    </item>
    <item>
      <title>Re: The nearest school district calculation</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/the-nearest-school-district-calculation/m-p/1091715#M189</link>
      <description>&lt;P&gt;So you create a feature inside a school district (polygon) and want to return the name of the next district within 1 mile that is not the district the feature is in. Did I get that right?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var school_districts = FeatureSetByName($datastore, "SCHOOL_DIST", ["NAME"], true);
var search_radius = Buffer($feature, 1, "Mile")
var districts_within_search_radius = Intersects(school_districts, search_radius)

// no districts around the feature
if(Count(districts_within_search_radius ) == 0) {
  return "feature has no school district within search radius"
}

// this is basically the code from your previous question
var min_distance = Infinity
var nearest_district = ""
for(var district in districts_within_search_radius) {
  var dist = Distance($feature, district)
  // dist &amp;gt; 0: exclude the district that contains the feature
  if(dist &amp;gt; 0 &amp;amp;&amp;amp; dist &amp;lt; min_distance) {
    min_distance = dist
    nearest_district = district.NAME
  }
}
// no districts that don't intersect the feature
if(nearest_district == "") {
  return "there are " + Count(districts_within_search_radius) + " districts within the search radius, but they all intersect the feature"
}
return nearest_district&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 24 Aug 2021 14:43:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/the-nearest-school-district-calculation/m-p/1091715#M189</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-08-24T14:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: The nearest school district calculation</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/the-nearest-school-district-calculation/m-p/1091718#M190</link>
      <description>&lt;P&gt;Yes you got it right. thanks again!&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 14:48:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/the-nearest-school-district-calculation/m-p/1091718#M190</guid>
      <dc:creator>Robswann</dc:creator>
      <dc:date>2021-08-24T14:48:31Z</dc:date>
    </item>
  </channel>
</rss>

