Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.69 KB | None | 0 0
  1. function queryLayerViewStats(buffer) {
  2. // this array is used just for counting the total features and populate the table. no statistics are performed on this
  3. // array due to text fields being present
  4.  
  5. // 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
  6. let dataFields = ["Total_Hous", "Less_than_", "i10000_to_", "i15000_to1", "i20000_to_",
  7. "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",
  8. "FamiliesIn", "FamilyPove", "Median_Hou_1", "MedianGros", "No_Diploma", "High_Schoo", "Some_colle", "Associates", "Bachelors_", "Masters_De", "Doctorate_", 'OnePersonH', 'TwoPersonH', 'ThreePerso', 'FourPerson', 'FivePerson', 'SixPersonH', 'SevenOrMor'
  9. ]; // UPDATE WHEN DEPLOYING
  10.  
  11. let updatedData_count = [];
  12. // tabledata is used for tabulator table
  13. let tabledata = [];
  14. // query statistics for features only in buffer polygon
  15. let statsToQuery = ['avg']; // UPDATE WHEN DEPLOYING
  16.  
  17. let statDef = [];
  18. // create stats definition array
  19. for (let i = 0; i < statsToQuery.length; i++) {
  20. let currentStat = statsToQuery[i];
  21. dataFields.forEach(function (fieldName) {
  22. statDef.push({
  23. onStatisticField: fieldName,
  24. outStatisticFieldName: fieldName + "_" + currentStat.toUpperCase(),
  25. statisticType: currentStat
  26. })
  27. })
  28. }
  29. // count variables
  30. let bg1 = 0;
  31. let bg2 = 0;
  32. let bg3 = 0;
  33. let bg4 = 0;
  34. let bg5 = 0;
  35. let bg6 = 0;
  36. try {
  37.  
  38. // query layerview to get total of each well type currently in view
  39.  
  40.  
  41. // // lets for mixmax boxplot charts - start
  42. // let pH_minmax_fieldparams = [];
  43. // let waterlevel_minmax_fieldparams = [];
  44. // let temperature_minmax_fieldparams = [];
  45. // let specificco_minmax_fieldparams = [];
  46. // let dissolvedo_minmax_fieldparams = [];
  47. // let oxidaredpo_minmax_fieldparams = [];
  48. // let Eh_minmax_fieldparams = [];
  49. // let turbidity_minmax_fieldparams = [];
  50.  
  51. // lets for minmax boxplot charts - end
  52. return app.statisticsWidget_layerView.queryFeatures({
  53. // returns count of features and also populates tabulator table
  54. geometry: buffer,
  55. outFields: "*",
  56. returnGeometry: true
  57. }).then(function (response) {
  58. for (let i in response.features) {
  59. let bgname = response.features[i].attributes.NAMELSAD10;
  60. // create array of attribute objects for tabulator table
  61. tabledata.push(response.features[i].attributes);
  62.  
  63. // GETS COUNT OF FEATURES BROKEN OUT BY SPECIFIED ATTRIBUTE NAME FROM DATAFIELDS ARRAY
  64. if (bgname) {
  65. if (bgname === 'Block Group 1') {
  66. bg1++;
  67. } else if (bgname === 'Block Group 2') {
  68. bg2++;
  69. } else if (bgname === 'Block Group 3') {
  70. bg3++;
  71. } else if (bgname === 'Block Group 4') {
  72. bg4++;
  73. } else if (bgname === 'Block Group 5') {
  74. bg5++;
  75. } else if (bgname === 'Block Group 6') {
  76. bg6++;
  77. }
  78. } else {
  79. console.log('No value found')
  80. }
  81.  
  82. // GETS COUNT OF FEATURES BROKEN OUT BY PROGRAM
  83.  
  84.  
  85.  
  86. // // create array of attribute objects for mixmax boxplot chart
  87. // pH_minmax_fieldparams.push(parseFloat(response.features[i].attributes.pH.toPrecision(4)));
  88. // waterlevel_minmax_fieldparams.push(parseFloat(response.features[i].attributes.waterlevel.toPrecision(4)));
  89. // temperature_minmax_fieldparams.push(parseFloat(response.features[i].attributes.temperture.toPrecision(2)));
  90. // specificco_minmax_fieldparams.push(parseFloat(response.features[i].attributes.specificco.toPrecision(4)));
  91. // dissolvedo_minmax_fieldparams.push(parseFloat(response.features[i].attributes.dissolvedo.toPrecision(3)));
  92. // oxidaredpo_minmax_fieldparams.push(parseFloat(response.features[i].attributes.oxidaredpo.toPrecision(3)));
  93. // Eh_minmax_fieldparams.push(parseFloat(response.features[i].attributes.Eh.toPrecision(3)));
  94. // turbidity_minmax_fieldparams.push(parseFloat(response.features[i].attributes.turbidity.toPrecision(3)));
  95. }
  96.  
  97. totalSelected = response.features.length;
  98. updatedData_count = [
  99. bg1,
  100. bg2,
  101. bg3,
  102. bg4,
  103. bg5,
  104. bg6
  105. ];
  106.  
  107. // let updatedData_minmax_fieldparams = [
  108. // pH_minmax_fieldparams,
  109. // waterlevel_minmax_fieldparams,
  110. // temperature_minmax_fieldparams,
  111. // specificco_minmax_fieldparams,
  112. // dissolvedo_minmax_fieldparams,
  113. // oxidaredpo_minmax_fieldparams,
  114. // Eh_minmax_fieldparams,
  115. // turbidity_minmax_fieldparams
  116. // ];
  117.  
  118. try {
  119. let query = app.statisticsWidget_layerView.layer.createQuery();
  120. query.outStatistics = statDef;
  121. query.geometry = buffer;
  122.  
  123. // query features within the view's extent on the client
  124. return app.statisticsWidget_layerView.queryFeatures(query).then(function (response) {
  125.  
  126. let stats = response.features[0].attributes;
  127.  
  128. let householdIncomeInfo = [
  129. stats.Median_Hou_AVG,
  130. stats.Median_Hou_1_AVG,
  131. stats.MedianGros_AVG
  132. ];
  133.  
  134. let familyInfo = [
  135. stats.Total_Hous_AVG,
  136. stats.OnePersonH_AVG,
  137. stats.TwoPersonH_AVG,
  138. stats.ThreePerso_AVG,
  139. stats.FourPerson_AVG,
  140. stats.FivePerson_AVG,
  141. stats.SixPersonH_AVG,
  142. stats.SevenOrMor_AVG,
  143. stats.TotalFamil_AVG,
  144. stats.FamiliesIn_AVG,
  145. stats.FamilyPove_AVG
  146. ];
  147. let householdIncomeStrata = [
  148. stats.Less_than__AVG,
  149. stats.i10000_to__AVG,
  150. stats.i15000_to1_AVG,
  151. stats.i20000_to__AVG,
  152. stats.i25000_to__AVG,
  153. stats.i30000_to__AVG,
  154. stats.i35000_to__AVG,
  155. stats.i40000_to__AVG,
  156. stats.i45000_to__AVG,
  157. stats.i50000_to__AVG,
  158. stats.i60000_to__AVG,
  159. stats.i75000_to__AVG,
  160. stats.i100000_to_AVG,
  161. stats.i125000_to_AVG,
  162. stats.i150000_to_AVG,
  163. stats.i200000_or_AVG,
  164. ];
  165.  
  166. let edAttain = [
  167. stats.No_Diploma_AVG,
  168. stats.High_Schoo_AVG,
  169. stats.Some_colle_AVG,
  170. stats.Associates_AVG,
  171. stats.Bachelors__AVG,
  172. stats.Masters_De_AVG,
  173. stats.Doctorate__AVG
  174. ]
  175.  
  176.  
  177. return {
  178. values_count: updatedData_count,
  179. totalSelected: totalSelected,
  180. tabledata: tabledata,
  181. // values_minmax_fieldparams: updatedData_minmax_fieldparams,
  182. title_count: "Total: " + totalSelected.toString() + " Features",
  183. householdIncomeInfo: householdIncomeInfo,
  184. householdIncomeStrata: householdIncomeStrata,
  185. familyInfo: familyInfo,
  186. edAttain: edAttain,
  187. avg_chart_title: "Average Of Data Values"
  188. }
  189. });
  190. } catch (error) {
  191. console.log('Error Message - Mean Chart: ', error.message);
  192. }
  193. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement