Is it possible to fetch the number of items with a certian property against the propery from a CSVLayer in ArcGIS Javascipt API?

对着背影说爱祢 提交于 2019-12-11 16:56:25

问题


Is it possible to fetch the number of items with a certain property against the property from a CSVLayer in ArcGIS Javascript API?

This is the csv file.

My intent is to

  • Category 0 - 1
  • Category 1 - 0
  • Category 2 - 1
  • Category 3 - 0

if we are showing Legends from the "Category" property and all the documents are in the view.

Also is it possible to filter the items based on the same property?

Also is it possible to show the details in a Pie Chart?


回答1:


You can use client side queries to retrieve information about the visible data. Using the CSVLayer and SceneView in the Codepen, the following code counts the number of features where Category = 0 or Category = 2:

view
  .whenLayerView(csvLayer)
  .then(function(csvLayerView) {

    // Create query
    var query = csvLayerView.createQuery();
    query.outStatistics = [{
      onStatisticField: "CASE WHEN Category = 0 THEN 1 ELSE 0 END",
      outStatisticFieldName: "Category0Sum",
      statisticType: "sum"
    }, {
      onStatisticField: "CASE WHEN Category = 2 THEN 1 ELSE 0 END",
      outStatisticFieldName: "Category2Sum",
      statisticType: "sum"
    }];
    return csvLayerView.queryFeatures(query);
  })
  .then(function(response) {

    // Print query results
    console.log("Query results", response.features[0].attributes);
  }).catch(console.error);

The following Codepen runs this code whenever the view changes and prints a new line of results to the console: https://codepen.io/arnofiva/pen/b835cc7b626965332e802fd3385056e9

To see other query options or how to show the results as pie chart, checkout the following resources:

  • API documentation for Query
  • Query statistics by geometry (uses pie charts)
  • Client-side filtering of displayed features


来源:https://stackoverflow.com/questions/57004153/is-it-possible-to-fetch-the-number-of-items-with-a-certian-property-against-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!