<?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 Data Expression to Clip Features and Calculate Area in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-clip-features-and-calculate/m-p/1360931#M8850</link>
    <description>&lt;P&gt;Hi -&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm hoping for some help with my syntax. The first part of this expression is working well. I can not figure out where I am going wrong starting at line 105 with the Clip function. I've verified everything above this is working thru use of Console, but can't get any further.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am wondering if because I am trying to feed Clip a FeatureSet instead of a $feature (as shown in the documentation) I am getting an error.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do any of the Arcade wizards on here have suggestions?&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1108"&gt;@XanderBakker&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The goal here is to use Dashboards/Arcade to provide non-GIS people with information needed for reporting w/o having to open Pro and do geoprocessing, or without needing a Creator license to use the AGOL Spatial Analysis tools. I was hoping this might be a viable workaround.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// custom memorize function to increase performance of featureset
function Memorize(fs) {
    var temp_dict = {
        fields: Schema(fs)['fields'],
        geometryType: Schema(fs).geometryType,
        features: []
    }

    for (var f in fs) {
        var attrs = {}

        for (var attr in f) {
            attrs[attr] = Iif(TypeOf(f[attr]) == 'Date', Number(f[attr]), f[attr])
        }

        Push(
            temp_dict['features'],
            {attributes: attrs, geometry: Geometry(f)}
        )
    }

    return FeatureSet(Text(temp_dict))
}
// variable to define the portal URL
var portal = Portal("https://mass-eoeea.maps.arcgis.com");

// Quabbin Drainage Basins
var QUAB = FeatureSetByPortalItem(portal, "6b878308af9646af8239d2251a26fe15", 0, ['DISTRICT', 'SUB_BASIN', 'AREA_ACRES'], true);

// Ware River Drainage Basins
var WARE = FeatureSetByPortalItem(portal, "60c237cb9b53472a91c331785c035954", 0, ['DISTRICT', 'SUBDISTRICT_BASIN', 'Acres'], true);

// Wachusett Subbasins
var WACH = FeatureSetByPortalItem(portal, "702f5bf477d7451aa27abc939c9b5b65", 0, ['Big_Wshed', 'Wshed', 'Area_Acres'], true);

// Create a FeatureSet with all Basins from Quabbin, Ware and Wachusett
var int_dict = {
  fields: [
    {name: "DistrictName", type: "esriFieldTypeString"},
    {name: "BasinName", type: "esriFieldTypeString"},
    {name: "Acres", type: "esriFieldTypeDouble"},
  ],
  geometryType: "esriGeometryPolygon",
  "spatialReference": {
    "wkid":102100,
    "latestWkid": 3857
  },
  features: [],
};

// Fill intermediate FeatureSet with Basin Info
var i = 0;
for (var q in QUAB) {
  //Console(q)
  int_dict.features[i] = {
    attributes: {
      'DistrictName': q["DISTRICT"],
      'BasinName': q["SUB_BASIN"],
      'Acres': q["AREA_ACRES"],
    },
    geometry: Geometry(q),
  }
  i++;
};

for (var w in WACH) {
  int_dict.features[i] = {
    attributes: {
      'DistrictName': w["Big_Wshed"],
      'BasinName': w["Wshed"],
      'Acres': w["Area_Acres"],
    },
    geometry: Geometry(w),
  }
  i++;
};

for (var r in WARE) {
  int_dict.features[i] = {
    attributes: {
      'DistrictName': r["DISTRICT"],
      'BasinName': r["SUBDISTRICT_BASIN"],
      'Acres': r["Acres"],
    },
    geometry: Geometry(r),
  }
  i++;
};
//Console(Text(int_dict));
//return FeatureSet(Text(int_dict));
var basinDict = FeatureSet(Text(int_dict));
//Console(Text(basinDict));

// DWSP Fee OpenSpace
var dwspOS = Memorize(Filter(FeatureSetByPortalItem(portal, "807b0f1e96444ec28fd06270fb8d3488", 0, ['GIS_ACRES'], true), "OWNER_ABRV ='DCRW'"))

// create an empty feature array
var features = []

// clip dwspOS by int_dict features to determine number acres dwspOS per basin
for (var b in basinDict) {
  // get the envelope of each basin feature within int_dict
  var envelope = Extent(b)
  // determine acres per envelope (basin)
  // is clip function limited to working with a single feature rather than a collection of features?
  var areaOS = Area(Clip(Geometry(dwspOS), envelope), 'acres')
  Console(areaOS)
  for (var a in areaOS) {
    // do math to determine percent ownership dwspOS acres per basin
    var pctOwn = Round(a/basinDict.Acres*100, 1)
    //add to array
    var new_f = {attributes: {
      DistName: a[basinDict.DistrictName],
      Basin: a[basinDict.BasinName],
      AcresBasin: a[basinDict.Acres],
      AcresDWSP: areaOS,
      PctOwnership: pctOwn,
    }}
    Push(features, new_f)
  }
}
Console(Text(new_f));

// create a FeatureSet with all of these features
var combined_dict = {
  fields: [
    {name: "DistName", type: "esriFieldTypeString"},
    {name: "Basin", type: "esriFieldTypeString"},
    {name: "AcresBasin", type: "esriFieldTypeDouble"},
    {name: "AcresDWSP", type: "esriFieldTypeDouble"},
    {name: "PctOwnership", type: "esriFieldTypeDouble"},
  ],
  geometryType: "esriGeometryPolygon",
  "spatialReference": {
    "wkid":102100,
    "latestWkid": 3857
  },
  features: features,
}

//Console(Text(combined_dict));
//return FeatureSet(Text(combined_dict));
return combined_dict&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Dec 2023 19:24:26 GMT</pubDate>
    <dc:creator>erica_poisson</dc:creator>
    <dc:date>2023-12-19T19:24:26Z</dc:date>
    <item>
      <title>Data Expression to Clip Features and Calculate Area</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-clip-features-and-calculate/m-p/1360931#M8850</link>
      <description>&lt;P&gt;Hi -&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm hoping for some help with my syntax. The first part of this expression is working well. I can not figure out where I am going wrong starting at line 105 with the Clip function. I've verified everything above this is working thru use of Console, but can't get any further.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am wondering if because I am trying to feed Clip a FeatureSet instead of a $feature (as shown in the documentation) I am getting an error.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do any of the Arcade wizards on here have suggestions?&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1108"&gt;@XanderBakker&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The goal here is to use Dashboards/Arcade to provide non-GIS people with information needed for reporting w/o having to open Pro and do geoprocessing, or without needing a Creator license to use the AGOL Spatial Analysis tools. I was hoping this might be a viable workaround.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// custom memorize function to increase performance of featureset
function Memorize(fs) {
    var temp_dict = {
        fields: Schema(fs)['fields'],
        geometryType: Schema(fs).geometryType,
        features: []
    }

    for (var f in fs) {
        var attrs = {}

        for (var attr in f) {
            attrs[attr] = Iif(TypeOf(f[attr]) == 'Date', Number(f[attr]), f[attr])
        }

        Push(
            temp_dict['features'],
            {attributes: attrs, geometry: Geometry(f)}
        )
    }

    return FeatureSet(Text(temp_dict))
}
// variable to define the portal URL
var portal = Portal("https://mass-eoeea.maps.arcgis.com");

// Quabbin Drainage Basins
var QUAB = FeatureSetByPortalItem(portal, "6b878308af9646af8239d2251a26fe15", 0, ['DISTRICT', 'SUB_BASIN', 'AREA_ACRES'], true);

// Ware River Drainage Basins
var WARE = FeatureSetByPortalItem(portal, "60c237cb9b53472a91c331785c035954", 0, ['DISTRICT', 'SUBDISTRICT_BASIN', 'Acres'], true);

// Wachusett Subbasins
var WACH = FeatureSetByPortalItem(portal, "702f5bf477d7451aa27abc939c9b5b65", 0, ['Big_Wshed', 'Wshed', 'Area_Acres'], true);

// Create a FeatureSet with all Basins from Quabbin, Ware and Wachusett
var int_dict = {
  fields: [
    {name: "DistrictName", type: "esriFieldTypeString"},
    {name: "BasinName", type: "esriFieldTypeString"},
    {name: "Acres", type: "esriFieldTypeDouble"},
  ],
  geometryType: "esriGeometryPolygon",
  "spatialReference": {
    "wkid":102100,
    "latestWkid": 3857
  },
  features: [],
};

// Fill intermediate FeatureSet with Basin Info
var i = 0;
for (var q in QUAB) {
  //Console(q)
  int_dict.features[i] = {
    attributes: {
      'DistrictName': q["DISTRICT"],
      'BasinName': q["SUB_BASIN"],
      'Acres': q["AREA_ACRES"],
    },
    geometry: Geometry(q),
  }
  i++;
};

for (var w in WACH) {
  int_dict.features[i] = {
    attributes: {
      'DistrictName': w["Big_Wshed"],
      'BasinName': w["Wshed"],
      'Acres': w["Area_Acres"],
    },
    geometry: Geometry(w),
  }
  i++;
};

for (var r in WARE) {
  int_dict.features[i] = {
    attributes: {
      'DistrictName': r["DISTRICT"],
      'BasinName': r["SUBDISTRICT_BASIN"],
      'Acres': r["Acres"],
    },
    geometry: Geometry(r),
  }
  i++;
};
//Console(Text(int_dict));
//return FeatureSet(Text(int_dict));
var basinDict = FeatureSet(Text(int_dict));
//Console(Text(basinDict));

// DWSP Fee OpenSpace
var dwspOS = Memorize(Filter(FeatureSetByPortalItem(portal, "807b0f1e96444ec28fd06270fb8d3488", 0, ['GIS_ACRES'], true), "OWNER_ABRV ='DCRW'"))

// create an empty feature array
var features = []

// clip dwspOS by int_dict features to determine number acres dwspOS per basin
for (var b in basinDict) {
  // get the envelope of each basin feature within int_dict
  var envelope = Extent(b)
  // determine acres per envelope (basin)
  // is clip function limited to working with a single feature rather than a collection of features?
  var areaOS = Area(Clip(Geometry(dwspOS), envelope), 'acres')
  Console(areaOS)
  for (var a in areaOS) {
    // do math to determine percent ownership dwspOS acres per basin
    var pctOwn = Round(a/basinDict.Acres*100, 1)
    //add to array
    var new_f = {attributes: {
      DistName: a[basinDict.DistrictName],
      Basin: a[basinDict.BasinName],
      AcresBasin: a[basinDict.Acres],
      AcresDWSP: areaOS,
      PctOwnership: pctOwn,
    }}
    Push(features, new_f)
  }
}
Console(Text(new_f));

// create a FeatureSet with all of these features
var combined_dict = {
  fields: [
    {name: "DistName", type: "esriFieldTypeString"},
    {name: "Basin", type: "esriFieldTypeString"},
    {name: "AcresBasin", type: "esriFieldTypeDouble"},
    {name: "AcresDWSP", type: "esriFieldTypeDouble"},
    {name: "PctOwnership", type: "esriFieldTypeDouble"},
  ],
  geometryType: "esriGeometryPolygon",
  "spatialReference": {
    "wkid":102100,
    "latestWkid": 3857
  },
  features: features,
}

//Console(Text(combined_dict));
//return FeatureSet(Text(combined_dict));
return combined_dict&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 19:24:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-clip-features-and-calculate/m-p/1360931#M8850</guid>
      <dc:creator>erica_poisson</dc:creator>
      <dc:date>2023-12-19T19:24:26Z</dc:date>
    </item>
  </channel>
</rss>

