I am working through a loop of intersecting layers, in which I want to choose the largest value.
I have tried to use create a list of numbers using += . This worked fine when I was using a combo of text and numbers, but because I am now just looking at numbers it sums the values, == replaces the values. I could not see how to make a list which I could then use the MAX function with.
My next attempt was to nest an if statement so that I am only getting the largest number out but I have an illegal return statement.
Below is an example of what I am currently doing.
var intersectLayer = Intersects(FeatureSetByName($map, "layer"), $feature)
var Zones = "";
var Zones1 = "";
for (var f in intersectLayer){
if(Zones == ""){
Zones = f.Shape__Area
} else {
Zones1 = f.Shape__Area
if (Zones < Zones1){
Zones == Zones1
}else{
Zones1 == ""
}
}
}
Xander Bakker Is this something you can help me with? I'm expecting there to be a much easier way then I have thought of yet.
Solved! Go to Solution.
Hi Naomi Begg ,
Great to hear that you are going to do a course on Python and Arcade! Those are really important languages in ArcGIS.
First of all I would make a small change to the script, but this won't resolve your issue:
var roads = FeatureSetByName($map,'TaupoProperty - Road');
var closestRoads = Intersects(roads,Buffer($feature, 100, "meters"));
var minDistance = Infinity;
var closestRoadName = "";
for (var l in closestRoads){
var roadDistance = Distance(l, $feature, 'meters');
if (roadDistance < minDistance) {
minDistance = roadDistance;
closestRoadName = l.name;
}
}
return closestRoadName;
So, when you use the $datastore, the data should be in the same geodatabase or service. If the data resides in two different "locations" the $datastore will not have access to the other layer. You can use layers from two different datastores in the same map and use the FeatureSetBy* function to get access, but unfortunately this does not work in the Field Calculation profile. Is there any way you could copy the other layer into the datastore to do the calculation? You could use Python to perform the calculation and use two different sources (although I would probably prefer a stand alone script for that than using the Python script inside the field calculator).
Hi Xander
I've used this field calculation on almost 25000 records. For some reason 12 records have created results which fall outside of the expected results. The results are turned into a percentage and should be between 1 and 100. Using the very same expression within the popup show the expected results, but some how it is the field calculator that has skewed a few of the results. I cant see any reason why it should have done this! I tried to run the calculator again on it thinking it might have timed out but I still get the same result.
Hi njbegg ,
Can you share the formula that you are using to create the percentage and in case of the 482,431 the values used in the calculation? Another thing to remember is that when you do an intersect even touching polygons will be included in the intersect. I have used a negative buffer in the past to avoid this from happening. See additional explanation here: https://community.esri.com/docs/DOC-12773-using-featuresetby-functions-in-arcade-to-drill-down-to-ot... (just scroll down to the end of the article).
Yes I had already figured the negative buffer in. Can I send you a little bit of my data along with the script to see where it is going wrong?
Hi Naomi Begg ,
Sure. You could also create a group, share the content to that group and invite me to that group using my AGOL account: xbakker@esri.co_utility_esri_co