ArcGIS Runtime SDK for Java

Statistical Query Group And Sort

Demonstrates how to query a feature table for statistics grouping and sorting by different fields.

How it works

To query statistics from a feature table:

  1. Create and load a ServiceFeatureTable.
  2. Get the feature tables field names list with featureTable.getFields().
  3. Create StatisticDefinitions specifying the field to compute statistics on and the StatisticType to compute.
  4. Create StatisticType passing in the list of statistic definitions.
  5. To have the results grouped by fields, add the field names to the query parameters' groupByFieldNames collection.
  6. To have the results ordered by fields, create OrderBys, specifying the field name and SortOrder. Pass these OrderBys to the parameters' orderByFields collection.
  7. To execute the query, call featureTable.queryStatisticsAsync(queryParameters).
  8. Get the StatisticQueryResult. From this, you can get an iterator of StatisticRecords to loop through and display.

Code

package com.esri.samples.featurelayers.statistical_query_group_and_sort;

/*
 * Copyright 2018 Esri.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

import java.io.IOException;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class StatisticalQueryGroupAndSortSample extends Application {

  @Override
  public void start(Stage stage) throws IOException {
    // set up the scene
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/statistical_query_group_and_sort.fxml"));
    Parent root = loader.load();
    loader.getController();
    Scene scene = new Scene(root);

    // set up the stage
    stage.setTitle("Statistical Query Group And Sort Sample");
    stage.setWidth(800);
    stage.setHeight(700);
    stage.setScene(scene);
    stage.show();
  }

  /**
   * Opens and runs application.
   *
   * @param args arguments passed to this application
   */
  public static void main(String[] args) {

    Application.launch(args);
  }
}


In this topic
  1. How it works
  2. Code