FeatureSetByPortalItem and arcade script for living Atlas

150
1
Jump to solution
12-03-2021 08:28 AM
ARM
by
New Contributor III

Hello
I have this code to get all Race from living atlas but this arcade give me error. I am trying to use it on pop up.

I don't want to bring layers to webmap and I just want to use FeatureSetByPortalItem 

 Error 

 

Execution Error:Runtime Error: Cannot call member property on object of this type. B03002_003E
//intersect to determine population density in the tract
var portal = Portal("https://www.arcgis.com")
var popu = FeatureSetByPortalItem(Portal,
"23ab8028f1784de4b0810104cd5d1c8f",2,
['B03002_003E','B03002_004E','B03002_005E','B03002_006E'
,'B03002_007E','B03002_008E','B03002_009E','B03002_012E']
, true);

var fields = [
  { value: $feature["B03002_003E"], alias: "White Alone, not Hispanic" },
  { value: $feature["B03002_004E"], alias: "Black or African American Alone, not Hispanic" },
  { value: $feature["B03002_005E"], alias: "American Indian and Alaska Native Alone, not Hispanic" },
  { value: $feature["B03002_006E"], alias: "Asian Alone, not Hispanic" },
  { value: $feature["B03002_007E"], alias: "Native Hawaiian and Other Pacific Islander Alone, not Hispanic" },
  { value: $feature["B03002_008E"], alias: "Some Other Race Alone, not Hispanic" },
  { value: $feature["B03002_009E"], alias: "Two or More Races, not Hispanic" },
  { value: $feature["B03002_012E"], alias: "Hispanic or Latino" }
];

// Returns the predominant category as the alias
// defined in the fields array. If there is a tie,
// then both names are concatenated and used to
// indicate the tie

function getPredominantCategory(fieldsArray){
  var maxValue = -Infinity;
  var maxCategory = "";
  for(var k in fieldsArray){
    if(fieldsArray[k].value > maxValue){
      maxValue = fieldsArray[k].value;
      maxCategory = fieldsArray[k].alias;
    } else if (fieldsArray[k].value == maxValue){
      maxCategory = maxCategory + "/" + fieldsArray[k].alias;
    }
  }
  return IIF(maxValue <= 0, null, maxCategory);
}

getPredominantCategory(fields);

 

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
Regular Contributor

You're actually never using the feature set. You use $feature["B03..."] instead. Do your features have these fields?

 

It seems as if you're trying to do something like this:

// load feature set from Living Atlas
var portal = Portal("https://www.arcgis.com")
var popu_all = FeatureSetByPortalItem(Portal,
"23ab8028f1784de4b0810104cd5d1c8f",2,
['B03002_003E','B03002_004E','B03002_005E','B03002_006E'
,'B03002_007E','B03002_008E','B03002_009E','B03002_012E']
, true);
// intersect with the feature you clicked on
var popu = Intersects(popu_all, $feature)
// get sum of categories of all intersected population polygons
var fields = [
  { value: Sum(popu, "B03002_003E"), alias: "White Alone, not Hispanic" },
  { value: Sum(popu, "B03002_004E"), alias: "Black or African American Alone, not Hispanic" },
  { value: Sum(popu, "B03002_005E"), alias: "American Indian and Alaska Native Alone, not Hispanic" },
  { value: Sum(popu, "B03002_006E"), alias: "Asian Alone, not Hispanic" },
  { value: Sum(popu, "B03002_007E"), alias: "Native Hawaiian and Other Pacific Islander Alone, not Hispanic" },
  { value: Sum(popu, "B03002_008E"), alias: "Some Other Race Alone, not Hispanic" },
  { value: Sum(popu, "B03002_009E"), alias: "Two or More Races, not Hispanic" },
  { value: Sum(popu, "B03002_012E"), alias: "Hispanic or Latino" }
];
// get the predominant category
function getPredominantCategory(fieldsArray){
  var maxValue = -Infinity;
  var maxCategory = "";
  for(var k in fieldsArray){
    if(fieldsArray[k].value > maxValue){
      maxValue = fieldsArray[k].value;
      maxCategory = fieldsArray[k].alias;
    } else if (fieldsArray[k].value == maxValue){
      maxCategory = maxCategory + "/" + fieldsArray[k].alias;
    }
  }
  return IIF(maxValue <= 0, null, maxCategory);
}

getPredominantCategory(fields);

Have a great day!
Johannes

View solution in original post

1 Reply
JohannesLindner
Regular Contributor

You're actually never using the feature set. You use $feature["B03..."] instead. Do your features have these fields?

 

It seems as if you're trying to do something like this:

// load feature set from Living Atlas
var portal = Portal("https://www.arcgis.com")
var popu_all = FeatureSetByPortalItem(Portal,
"23ab8028f1784de4b0810104cd5d1c8f",2,
['B03002_003E','B03002_004E','B03002_005E','B03002_006E'
,'B03002_007E','B03002_008E','B03002_009E','B03002_012E']
, true);
// intersect with the feature you clicked on
var popu = Intersects(popu_all, $feature)
// get sum of categories of all intersected population polygons
var fields = [
  { value: Sum(popu, "B03002_003E"), alias: "White Alone, not Hispanic" },
  { value: Sum(popu, "B03002_004E"), alias: "Black or African American Alone, not Hispanic" },
  { value: Sum(popu, "B03002_005E"), alias: "American Indian and Alaska Native Alone, not Hispanic" },
  { value: Sum(popu, "B03002_006E"), alias: "Asian Alone, not Hispanic" },
  { value: Sum(popu, "B03002_007E"), alias: "Native Hawaiian and Other Pacific Islander Alone, not Hispanic" },
  { value: Sum(popu, "B03002_008E"), alias: "Some Other Race Alone, not Hispanic" },
  { value: Sum(popu, "B03002_009E"), alias: "Two or More Races, not Hispanic" },
  { value: Sum(popu, "B03002_012E"), alias: "Hispanic or Latino" }
];
// get the predominant category
function getPredominantCategory(fieldsArray){
  var maxValue = -Infinity;
  var maxCategory = "";
  for(var k in fieldsArray){
    if(fieldsArray[k].value > maxValue){
      maxValue = fieldsArray[k].value;
      maxCategory = fieldsArray[k].alias;
    } else if (fieldsArray[k].value == maxValue){
      maxCategory = maxCategory + "/" + fieldsArray[k].alias;
    }
  }
  return IIF(maxValue <= 0, null, maxCategory);
}

getPredominantCategory(fields);

Have a great day!
Johannes

View solution in original post