ArcGIS Runtime SDK for Qt

Statistical query



#include "StatisticalQuery.h"

#include "Map.h"
#include "MapQuickView.h"
#include "ArcGISVectorTiledLayer.h"
#include "FeatureLayer.h"
#include "ServiceFeatureTable.h"
#include "StatisticalQuery.h"
#include "StatisticsQueryParameters.h"
#include "StatisticDefinition.h"
#include "StatisticRecord.h"
#include "StatisticRecordIterator.h"
#include "Viewpoint.h"

#include <QUrl>

using namespace Esri::ArcGISRuntime;

StatisticalQuery::StatisticalQuery(QQuickItem* parent /* = nullptr */):

void StatisticalQuery::init()
  // Register the map view for QML
  qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView");
  qmlRegisterType<StatisticalQuery>("Esri.Samples", 1, 0, "StatisticalQuerySample");

void StatisticalQuery::componentComplete()

  // find QML MapView component
  m_mapView = findChild<MapQuickView*>("mapView");

  // Create a new Map with the world streets vector basemap
  m_map = new Map(Basemap::streetsVector(this), this);

  // Create feature table using the world cities URL
  m_featureTable = new ServiceFeatureTable(QUrl(""), this);

  // Create a new feature layer to display features in the world cities table
  FeatureLayer* featureLayer = new FeatureLayer(m_featureTable, this);

  // Set map to map view

  // connect to queryStatisticsCompleted
  connect(m_featureTable, &ServiceFeatureTable::queryStatisticsCompleted, this, [this](QUuid, StatisticsQueryResult* result)
    // Iterate through the results
    QObject parent;
    QString resultText;
    StatisticRecordIterator iter = result->iterator();
    while (iter.hasNext())
      StatisticRecord* record =;
      for (auto key : record->statistics().keys())
        resultText += QString("%1: %2\n").arg(key, record->statistics().value(key).toString());

    // Display the Results
    emit showStatistics(resultText);

void StatisticalQuery::queryStatistics(bool extentOnly, bool bigCitiesOnly)
  // create the parameters
  StatisticsQueryParameters queryParameters;

  // Add the Statistic Definitions
  QList<StatisticDefinition> definitions
    StatisticDefinition("POP", StatisticType::Average, ""),
    StatisticDefinition("POP", StatisticType::Minimum, ""),
    StatisticDefinition("POP", StatisticType::Maximum, ""),
    StatisticDefinition("POP", StatisticType::Sum, ""),
    StatisticDefinition("POP", StatisticType::StandardDeviation, ""),
    StatisticDefinition("POP", StatisticType::Variance, ""),
    StatisticDefinition("POP", StatisticType::Count, "CityCount")

  // If only using features in the current extent, set up the spatial filter for the statistics query parameters
  if (extentOnly)
    // Set the statistics query parameters geometry with the envelope

    // Set the spatial relationship to Intersects (which is the default)

  // If only evaluating the largest cities (over 5 million in population), set up an attribute filter
  if (bigCitiesOnly)
    queryParameters.setWhereClause("POP_RANK = 1");

  // Execute the statistical query with these parameters

In this topic
  1. Code