<?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: Help with Attribute Rules - Finding Nearest School in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1098351#M216</link>
    <description>&lt;P&gt;If the rule returns an empty string, it means it didn't find a school in teh specified search radius. If it worked before adding the filter, then the problem is probably&amp;nbsp;in the filter.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;make sure that ELEMENTARY_SCHOOL.DISTRICT_1 and PROPERTIES.School_District are of the same data type&lt;/LI&gt;&lt;LI&gt;make sure that School_District is a value that can actually be found in DISTRICT_1&lt;/LI&gt;&lt;LI&gt;include better log messages (at least temporarily)&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="javascript"&gt;var log = ""

var CURRENTSCHOOLS = FeatureSetByName($datastore, "ELEMENTARY_SCHOOL", ["School_Nam", "DISTRICT_1"]);
log += Count(CURRENTSCHOOLS) + " schools loaded; "

var district = $feature.School_District
if(!IsEmpty(district)) {
  log += "filtering schools by '" + district + "'; "
  CURRENTSCHOOLS = Filter(CURRENTSCHOOLS, "DISTRICT_1 = @district")
  log += Count(CURRENTSCHOOLS) + " schools found; "
} else {
  log += "School_District is empty; "
}

VAR SEARCHDISTANCE = 30;
VAR SCHOOLINTERSECT = INTERSECTS(CURRENTSCHOOLS, BUFFER($FEATURE, SEARCHDISTANCE, "MILES"))
log += Count(SCHOOLINTERSECT) + " schools found in the search radius; "

IF(SCHOOLINTERSECT == null || COUNT(SCHOOLINTERSECT) == 0) {
  return log
}

VAR MINDISTANCE = INFINITY
VAR NEARESTSCHOOL = ""
FOR(VAR SCHOOL IN SCHOOLINTERSECT) {
  VAR DIST = DISTANCE(SCHOOL, $FEATURE)
  IF(DIST &amp;lt; MINDISTANCE) {
    MINDISTANCE = DIST
    NEARESTSCHOOL = SCHOOL.SCHOOL_NAM
  }
}
RETURN NEARESTSCHOOL&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Sep 2021 08:38:36 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2021-09-15T08:38:36Z</dc:date>
    <item>
      <title>Help with Attribute Rules - Finding Nearest School</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1090783#M179</link>
      <description>&lt;P&gt;Hello, I am trying to use the attribute rules in my polygon feature to find the nearest school to each polygon. I have the following below, but it seems to be returning a school further away. Can someone please help?&lt;/P&gt;&lt;P&gt;Thanks in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;var CURRENTSCHOOLS = FeatureSetByName($datastore, "ELEMENTARY_SCHOOL", ["School_Nam"]);&lt;BR /&gt;VAR SEARCHDISTANCE = 10;&lt;BR /&gt;VAR SCHOOLINTERSECT = INTERSECTS(CURRENTSCHOOLS, BUFFER($FEATURE, SEARCHDISTANCE, "MILES"))&lt;BR /&gt;VAR MINDISTANCE = INFINITY&lt;BR /&gt;VAR FSCHOOL = FIRST(SCHOOLINTERSECT)&lt;BR /&gt;IF (FSCHOOL == NULL) RETURN ""&lt;BR /&gt;IF(SEARCHDISTANCE &amp;lt; MINDISTANCE)&lt;BR /&gt;RETURN FSCHOOL.SCHOOL_NAM&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 13:40:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1090783#M179</guid>
      <dc:creator>Robswann</dc:creator>
      <dc:date>2021-08-20T13:40:37Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Attribute Rules - Finding Nearest School</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1090788#M180</link>
      <description>&lt;LI-CODE lang="javascript"&gt;var CURRENTSCHOOLS = FeatureSetByName($datastore, "ELEMENTARY_SCHOOL", ["School_Nam"]);
VAR SEARCHDISTANCE = 10;
VAR SCHOOLINTERSECT = INTERSECTS(CURRENTSCHOOLS, BUFFER($FEATURE, SEARCHDISTANCE, "MILES"))
IF(SCHOOLINTERSECT == null || COUNT(SCHOOLINTERSECT) == 0) {
  RETURN ""
}
VAR MINDISTANCE = INFINITY
VAR NEARESTSCHOOL = ""
FOR(VAR SCHOOL IN SCHOOLINTERSECT) {
  VAR DIST = DISTANCE(SCHOOL, $FEATURE)
  IF(DIST &amp;lt; MINDISTANCE) {
    MINDIST = DIST
    NEARESTSCHOOL = SCHOOL.SCHOOL_NAM
  }
}
RETURN NEARESTSCHOOL&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 20 Aug 2021 13:53:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1090788#M180</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-08-20T13:53:25Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Attribute Rules - Finding Nearest School</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1090790#M181</link>
      <description>&lt;P&gt;Thanks so much Johannes! I had an error but made the change from MINDIST TO MINDISTANCE line 12 and i worked..&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hate to ask, but would there be a way to add a rule that returns the distance from the polygon to the nearest school?&amp;nbsp; Thanks again&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 14:04:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1090790#M181</guid>
      <dc:creator>Robswann</dc:creator>
      <dc:date>2021-08-20T14:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Attribute Rules - Finding Nearest School</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1090792#M182</link>
      <description>&lt;P&gt;Sure. Same as this rule, but return MINDISTANCE instead of NEARESTSCHOOL.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 14:09:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1090792#M182</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-08-20T14:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Attribute Rules - Finding Nearest School</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1090793#M183</link>
      <description>&lt;P&gt;Thanks again!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 14:14:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1090793#M183</guid>
      <dc:creator>Robswann</dc:creator>
      <dc:date>2021-08-20T14:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Attribute Rules - Finding Nearest School</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1097249#M213</link>
      <description>&lt;P&gt;Would it be possible to find the nearest schools within a certain school district only. The School District that would be referenced would be a entered field within the feature, Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2021 15:53:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1097249#M213</guid>
      <dc:creator>Robswann</dc:creator>
      <dc:date>2021-09-10T15:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Attribute Rules - Finding Nearest School</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1097528#M214</link>
      <description>&lt;LI-CODE lang="javascript"&gt;// change: load your school district field
var CURRENTSCHOOLS = FeatureSetByName($datastore, "ELEMENTARY_SCHOOL", ["School_Nam", "School_District"]);
// change: filter schools by district
var district = $feature.School_District
if(district != null) {
  CURRENTSCHOOLS = Filter(CURRENTSCHOOLS, "School_District = @district")
}
// rest stays the same
VAR SEARCHDISTANCE = 10;
VAR SCHOOLINTERSECT = INTERSECTS(CURRENTSCHOOLS, BUFFER($FEATURE, SEARCHDISTANCE, "MILES"))
IF(SCHOOLINTERSECT == null || COUNT(SCHOOLINTERSECT) == 0) {
  RETURN ""
}
VAR MINDISTANCE = INFINITY
VAR NEARESTSCHOOL = ""
FOR(VAR SCHOOL IN SCHOOLINTERSECT) {
  VAR DIST = DISTANCE(SCHOOL, $FEATURE)
  IF(DIST &amp;lt; MINDISTANCE) {
    MINDISTANCE = DIST
    NEARESTSCHOOL = SCHOOL.SCHOOL_NAM
  }
}
RETURN NEARESTSCHOOL&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 13 Sep 2021 06:04:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1097528#M214</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-09-13T06:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Attribute Rules - Finding Nearest School</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1098113#M215</link>
      <description>&lt;P&gt;Thank you for your response, i have been working on getting what you suggested to work, but still no luck. I Probably didnt provide enough info:&lt;/P&gt;&lt;P&gt;//Note: ELEMENTARY_SCHOOL is the feature that has all the schools&lt;/P&gt;&lt;P&gt;// Note: DISTRICT_1 is the field located in ELEMENTARY_SCHOOL that lists the School District the school is located in,&amp;nbsp;&lt;/P&gt;&lt;P&gt;//Note:&amp;nbsp;var district = $feature.School_District - Is the field that contains the School District to search within and is the feature class named PROPERTIES (The layer with the Attribute Rule)&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below returns a null value everytime, not sure what I am doing wrong. Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;// change: load your school district field&amp;nbsp;&lt;BR /&gt;var CURRENTSCHOOLS = FeatureSetByName($datastore, "ELEMENTARY_SCHOOL", ["School_Nam", "DISTRICT_1"]);&lt;BR /&gt;// change: filter schools by district&lt;BR /&gt;var district = $feature.School_District&lt;BR /&gt;if(district != null) {&lt;BR /&gt;CURRENTSCHOOLS = Filter(CURRENTSCHOOLS, "DISTRICT_1 = @district")&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;BR /&gt;// rest stays the same&lt;BR /&gt;VAR SEARCHDISTANCE = 30;&lt;BR /&gt;VAR SCHOOLINTERSECT = INTERSECTS(CURRENTSCHOOLS, BUFFER($FEATURE, SEARCHDISTANCE, "MILES"))&lt;BR /&gt;IF(SCHOOLINTERSECT == null || COUNT(SCHOOLINTERSECT) == 0) {&lt;BR /&gt;RETURN ""&lt;BR /&gt;}&lt;BR /&gt;VAR MINDISTANCE = INFINITY&lt;BR /&gt;VAR NEARESTSCHOOL = ""&lt;BR /&gt;FOR(VAR SCHOOL IN SCHOOLINTERSECT) {&lt;BR /&gt;VAR DIST = DISTANCE(SCHOOL, $FEATURE)&lt;BR /&gt;IF(DIST &amp;lt; MINDISTANCE) {&lt;BR /&gt;MINDISTANCE = DIST&lt;BR /&gt;NEARESTSCHOOL = SCHOOL.SCHOOL_NAM&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;RETURN NEARESTSCHOOL&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 15:56:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1098113#M215</guid>
      <dc:creator>Robswann</dc:creator>
      <dc:date>2021-09-14T15:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Attribute Rules - Finding Nearest School</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1098351#M216</link>
      <description>&lt;P&gt;If the rule returns an empty string, it means it didn't find a school in teh specified search radius. If it worked before adding the filter, then the problem is probably&amp;nbsp;in the filter.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;make sure that ELEMENTARY_SCHOOL.DISTRICT_1 and PROPERTIES.School_District are of the same data type&lt;/LI&gt;&lt;LI&gt;make sure that School_District is a value that can actually be found in DISTRICT_1&lt;/LI&gt;&lt;LI&gt;include better log messages (at least temporarily)&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="javascript"&gt;var log = ""

var CURRENTSCHOOLS = FeatureSetByName($datastore, "ELEMENTARY_SCHOOL", ["School_Nam", "DISTRICT_1"]);
log += Count(CURRENTSCHOOLS) + " schools loaded; "

var district = $feature.School_District
if(!IsEmpty(district)) {
  log += "filtering schools by '" + district + "'; "
  CURRENTSCHOOLS = Filter(CURRENTSCHOOLS, "DISTRICT_1 = @district")
  log += Count(CURRENTSCHOOLS) + " schools found; "
} else {
  log += "School_District is empty; "
}

VAR SEARCHDISTANCE = 30;
VAR SCHOOLINTERSECT = INTERSECTS(CURRENTSCHOOLS, BUFFER($FEATURE, SEARCHDISTANCE, "MILES"))
log += Count(SCHOOLINTERSECT) + " schools found in the search radius; "

IF(SCHOOLINTERSECT == null || COUNT(SCHOOLINTERSECT) == 0) {
  return log
}

VAR MINDISTANCE = INFINITY
VAR NEARESTSCHOOL = ""
FOR(VAR SCHOOL IN SCHOOLINTERSECT) {
  VAR DIST = DISTANCE(SCHOOL, $FEATURE)
  IF(DIST &amp;lt; MINDISTANCE) {
    MINDISTANCE = DIST
    NEARESTSCHOOL = SCHOOL.SCHOOL_NAM
  }
}
RETURN NEARESTSCHOOL&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Sep 2021 08:38:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/help-with-attribute-rules-finding-nearest-school/m-p/1098351#M216</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-09-15T08:38:36Z</dc:date>
    </item>
  </channel>
</rss>

