Select to view content in your preferred language

Using multiple arrays to populate new features

665
1
Jump to solution
07-21-2022 05:06 PM
PeterMilenkovic
Frequent Contributor

Hi All

Trying to create an arcade expression to populate a field, i am wanting to construct features using two arrays, is it possible to loop through multiple arrays in parallel (they are the same length), i know i can do this in python by using "for x,y in zip(x_list, y_list):"

 

DormArray = [FP1Dorm,FP2Dorm,FP3Dorm,ConDorm,MedDorm,BlisDorm]

DormWeightArray = [FP1DormWeight,FP2DormWeight,FP3DormWeight,ConDormWeight,MedDormWeight,BlisDormWeight]

var summarydict = {

    fields:[
        {'name':'Dormancy','type':'esriFieldTypeString'},
        {'name':'DormancyWeight','type':'esriFieldTypeDouble'}],
        'geometryType': '',
        'features':[]
        }
    
for (var d in DormArray and var w in DormWeightArray){
    var new_f = {'attributes': {'Dormancy': d,
                                'DormancyWeight':w
                               }}
    Push(summarydict.features, new_f)
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
PeterMilenkovic
Frequent Contributor

Well i found this thread which helped me figure it out.

https://community.esri.com/t5/developers-questions/arcade-multiple-values-in-an-array-arrays-in-an/m...

Rather than having two arrays i created a nested one and used an index to access the sub array values.

var DormArray = [[FP1Dorm,FP1DormWeight],[FP2Dorm,FP2DormWeight],[FP3Dorm,FP3DormWeight],[ConDorm,ConDormWeight],[MedDorm,MedDormWeight],[BlisDorm,BlisDormWeight]]

var summarydict = {

    fields:[
        {'name':'Dormancy','type':'esriFieldTypeString'},
        {'name':'DormancyWeight','type':'esriFieldTypeInteger'}],
        'geometryType': '',
        'features':[]
        }
   
for (var d in DormArray){
    
    var new_f = {'attributes': {'Dormancy': DormArray[d][0],
								'DormancyWeight':DormArray[d][1]
                               }}
    Push(summarydict.features, new_f)
}

var predomDorm = first(groupby(featureset(text(summarydict)),'Dormancy',[{name:'DormSum',expression:'DormancyWeight',statistic:'SUM'}]))['Dormancy']

return  predomDorm

 

View solution in original post

0 Kudos
1 Reply
PeterMilenkovic
Frequent Contributor

Well i found this thread which helped me figure it out.

https://community.esri.com/t5/developers-questions/arcade-multiple-values-in-an-array-arrays-in-an/m...

Rather than having two arrays i created a nested one and used an index to access the sub array values.

var DormArray = [[FP1Dorm,FP1DormWeight],[FP2Dorm,FP2DormWeight],[FP3Dorm,FP3DormWeight],[ConDorm,ConDormWeight],[MedDorm,MedDormWeight],[BlisDorm,BlisDormWeight]]

var summarydict = {

    fields:[
        {'name':'Dormancy','type':'esriFieldTypeString'},
        {'name':'DormancyWeight','type':'esriFieldTypeInteger'}],
        'geometryType': '',
        'features':[]
        }
   
for (var d in DormArray){
    
    var new_f = {'attributes': {'Dormancy': DormArray[d][0],
								'DormancyWeight':DormArray[d][1]
                               }}
    Push(summarydict.features, new_f)
}

var predomDorm = first(groupby(featureset(text(summarydict)),'Dormancy',[{name:'DormSum',expression:'DormancyWeight',statistic:'SUM'}]))['Dormancy']

return  predomDorm

 

0 Kudos