Is it possible to fetch the number of items with a

2019-08-18 07:40发布

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条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-08-18 07:56

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:

查看更多
登录 后发表回答