Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function queryLayerViewStats(buffer) {
- // this array is used just for counting the total features and populate the table. no statistics are performed on this
- // array due to text fields being present
- // MAKE SURE TO CONVERT ANY DATETIME FIELDS TO UTC TIME ZONE VIA THE ARCMAP TOOL 'CONVERT TIME ZONE' IN THE FIELDS TOOLSET UNDER THE DATA MANAGEMENT TOOLBOX IN ARCTOOLBOX
- let dataFields = ["Total_Hous", "Less_than_", "i10000_to_", "i15000_to1", "i20000_to_",
- "i25000_to_", "i30000_to_", "i35000_to_", "i40000_to_", "i45000_to_", "i50000_to_", "i60000_to_", "i75000_to_", "i100000_to", "i125000_to", "i150000_to", "i200000_or", "Median_Hou", "TotalFamil",
- "FamiliesIn", "FamilyPove", "Median_Hou_1", "MedianGros", "No_Diploma", "High_Schoo", "Some_colle", "Associates", "Bachelors_", "Masters_De", "Doctorate_", 'OnePersonH', 'TwoPersonH', 'ThreePerso', 'FourPerson', 'FivePerson', 'SixPersonH', 'SevenOrMor'
- ]; // UPDATE WHEN DEPLOYING
- let updatedData_count = [];
- // tabledata is used for tabulator table
- let tabledata = [];
- // query statistics for features only in buffer polygon
- let statsToQuery = ['avg']; // UPDATE WHEN DEPLOYING
- let statDef = [];
- // create stats definition array
- for (let i = 0; i < statsToQuery.length; i++) {
- let currentStat = statsToQuery[i];
- dataFields.forEach(function (fieldName) {
- statDef.push({
- onStatisticField: fieldName,
- outStatisticFieldName: fieldName + "_" + currentStat.toUpperCase(),
- statisticType: currentStat
- })
- })
- }
- // count variables
- let bg1 = 0;
- let bg2 = 0;
- let bg3 = 0;
- let bg4 = 0;
- let bg5 = 0;
- let bg6 = 0;
- try {
- // query layerview to get total of each well type currently in view
- // // lets for mixmax boxplot charts - start
- // let pH_minmax_fieldparams = [];
- // let waterlevel_minmax_fieldparams = [];
- // let temperature_minmax_fieldparams = [];
- // let specificco_minmax_fieldparams = [];
- // let dissolvedo_minmax_fieldparams = [];
- // let oxidaredpo_minmax_fieldparams = [];
- // let Eh_minmax_fieldparams = [];
- // let turbidity_minmax_fieldparams = [];
- // lets for minmax boxplot charts - end
- return app.statisticsWidget_layerView.queryFeatures({
- // returns count of features and also populates tabulator table
- geometry: buffer,
- outFields: "*",
- returnGeometry: true
- }).then(function (response) {
- for (let i in response.features) {
- let bgname = response.features[i].attributes.NAMELSAD10;
- // create array of attribute objects for tabulator table
- tabledata.push(response.features[i].attributes);
- // GETS COUNT OF FEATURES BROKEN OUT BY SPECIFIED ATTRIBUTE NAME FROM DATAFIELDS ARRAY
- if (bgname) {
- if (bgname === 'Block Group 1') {
- bg1++;
- } else if (bgname === 'Block Group 2') {
- bg2++;
- } else if (bgname === 'Block Group 3') {
- bg3++;
- } else if (bgname === 'Block Group 4') {
- bg4++;
- } else if (bgname === 'Block Group 5') {
- bg5++;
- } else if (bgname === 'Block Group 6') {
- bg6++;
- }
- } else {
- console.log('No value found')
- }
- // GETS COUNT OF FEATURES BROKEN OUT BY PROGRAM
- // // create array of attribute objects for mixmax boxplot chart
- // pH_minmax_fieldparams.push(parseFloat(response.features[i].attributes.pH.toPrecision(4)));
- // waterlevel_minmax_fieldparams.push(parseFloat(response.features[i].attributes.waterlevel.toPrecision(4)));
- // temperature_minmax_fieldparams.push(parseFloat(response.features[i].attributes.temperture.toPrecision(2)));
- // specificco_minmax_fieldparams.push(parseFloat(response.features[i].attributes.specificco.toPrecision(4)));
- // dissolvedo_minmax_fieldparams.push(parseFloat(response.features[i].attributes.dissolvedo.toPrecision(3)));
- // oxidaredpo_minmax_fieldparams.push(parseFloat(response.features[i].attributes.oxidaredpo.toPrecision(3)));
- // Eh_minmax_fieldparams.push(parseFloat(response.features[i].attributes.Eh.toPrecision(3)));
- // turbidity_minmax_fieldparams.push(parseFloat(response.features[i].attributes.turbidity.toPrecision(3)));
- }
- totalSelected = response.features.length;
- updatedData_count = [
- bg1,
- bg2,
- bg3,
- bg4,
- bg5,
- bg6
- ];
- // let updatedData_minmax_fieldparams = [
- // pH_minmax_fieldparams,
- // waterlevel_minmax_fieldparams,
- // temperature_minmax_fieldparams,
- // specificco_minmax_fieldparams,
- // dissolvedo_minmax_fieldparams,
- // oxidaredpo_minmax_fieldparams,
- // Eh_minmax_fieldparams,
- // turbidity_minmax_fieldparams
- // ];
- try {
- let query = app.statisticsWidget_layerView.layer.createQuery();
- query.outStatistics = statDef;
- query.geometry = buffer;
- // query features within the view's extent on the client
- return app.statisticsWidget_layerView.queryFeatures(query).then(function (response) {
- let stats = response.features[0].attributes;
- let householdIncomeInfo = [
- stats.Median_Hou_AVG,
- stats.Median_Hou_1_AVG,
- stats.MedianGros_AVG
- ];
- let familyInfo = [
- stats.Total_Hous_AVG,
- stats.OnePersonH_AVG,
- stats.TwoPersonH_AVG,
- stats.ThreePerso_AVG,
- stats.FourPerson_AVG,
- stats.FivePerson_AVG,
- stats.SixPersonH_AVG,
- stats.SevenOrMor_AVG,
- stats.TotalFamil_AVG,
- stats.FamiliesIn_AVG,
- stats.FamilyPove_AVG
- ];
- let householdIncomeStrata = [
- stats.Less_than__AVG,
- stats.i10000_to__AVG,
- stats.i15000_to1_AVG,
- stats.i20000_to__AVG,
- stats.i25000_to__AVG,
- stats.i30000_to__AVG,
- stats.i35000_to__AVG,
- stats.i40000_to__AVG,
- stats.i45000_to__AVG,
- stats.i50000_to__AVG,
- stats.i60000_to__AVG,
- stats.i75000_to__AVG,
- stats.i100000_to_AVG,
- stats.i125000_to_AVG,
- stats.i150000_to_AVG,
- stats.i200000_or_AVG,
- ];
- let edAttain = [
- stats.No_Diploma_AVG,
- stats.High_Schoo_AVG,
- stats.Some_colle_AVG,
- stats.Associates_AVG,
- stats.Bachelors__AVG,
- stats.Masters_De_AVG,
- stats.Doctorate__AVG
- ]
- return {
- values_count: updatedData_count,
- totalSelected: totalSelected,
- tabledata: tabledata,
- // values_minmax_fieldparams: updatedData_minmax_fieldparams,
- title_count: "Total: " + totalSelected.toString() + " Features",
- householdIncomeInfo: householdIncomeInfo,
- householdIncomeStrata: householdIncomeStrata,
- familyInfo: familyInfo,
- edAttain: edAttain,
- avg_chart_title: "Average Of Data Values"
- }
- });
- } catch (error) {
- console.log('Error Message - Mean Chart: ', error.message);
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement