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.
var SCHOOL_DIST = FeatureSetByName($datastore, "SCHOOL_DIST", ["NAME"]);
VAR SEARCHDISTANCE = 1;
VAR SCHOOLINTERSECT = INTERSECTS(SCHOOL_DIST, BUFFER($FEATURE, SEARCHDISTANCE, "MILE"))
VAR FSCHOOL = FIRST(SCHOOLINTERSECT)
IF (FSCHOOL == NULL) RETURN ""
RETURN FSCHOOL.NAME
Solved! Go to Solution.
Yes you got it right. thanks again!
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?
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 > 0: exclude the district that contains the feature
if(dist > 0 && dist < 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
Yes you got it right. thanks again!