Skip to content

Commit 3a2240d

Browse files
authored
Merge pull request #249 from Esri/statistical-query-group-sort
statistical query group and sort sample
2 parents d6cd4e9 + 5378d3c commit 3a2240d

File tree

7 files changed

+590
-0
lines changed

7 files changed

+590
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.esri.samples.featurelayers.statistical_query_group_and_sort;
2+
3+
import javafx.beans.property.SimpleBooleanProperty;
4+
import javafx.beans.property.SimpleStringProperty;
5+
6+
/**
7+
* Convenience bean class for representing a group-by field. The grouping property can be bound to a CheckBoxListCell
8+
* to choose whether the field should be grouped by with a CheckBox.
9+
*/
10+
public class GroupField {
11+
12+
private final SimpleStringProperty fieldName;
13+
private final SimpleBooleanProperty grouping;
14+
15+
GroupField(String fieldName, Boolean grouping) {
16+
this.fieldName = new SimpleStringProperty(fieldName);
17+
this.grouping = new SimpleBooleanProperty(grouping);
18+
}
19+
20+
public String getFieldName() {
21+
return fieldName.get();
22+
}
23+
24+
public SimpleStringProperty fieldNameProperty() {
25+
return fieldName;
26+
}
27+
28+
public void setFieldName(String fieldName) {
29+
this.fieldName.set(fieldName);
30+
}
31+
32+
public boolean isGrouping() {
33+
return grouping.get();
34+
}
35+
36+
public SimpleBooleanProperty groupingProperty() {
37+
return grouping;
38+
}
39+
40+
public void setGrouping(boolean grouping) {
41+
this.grouping.set(grouping);
42+
}
43+
44+
@Override
45+
public String toString() {
46+
return getFieldName();
47+
}
48+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.esri.samples.featurelayers.statistical_query_group_and_sort;
2+
3+
import javafx.beans.binding.Bindings;
4+
import javafx.beans.property.SimpleObjectProperty;
5+
import javafx.beans.property.SimpleStringProperty;
6+
7+
import com.esri.arcgisruntime.data.QueryParameters;
8+
9+
/**
10+
* Convenience bean class for representing OrderBy in a TableView row. The sortOrder property can be bound to a
11+
* ComboBoxTableCell for changing the sortOrder with a ComboBox.
12+
*/
13+
public class OrderByField {
14+
15+
private final SimpleStringProperty fieldName;
16+
private final SimpleObjectProperty<QueryParameters.SortOrder> sortOrder;
17+
private final SimpleObjectProperty<QueryParameters.OrderBy> orderBy;
18+
19+
OrderByField(QueryParameters.OrderBy orderBy) {
20+
this.fieldName = new SimpleStringProperty(orderBy.getFieldName());
21+
this.sortOrder = new SimpleObjectProperty<>(orderBy.getSortOrder());
22+
this.orderBy = new SimpleObjectProperty<>();
23+
this.orderBy.bind(Bindings.createObjectBinding(() -> new QueryParameters.OrderBy(this.fieldName.get(), this
24+
.sortOrder.get()), this.fieldName, this.sortOrder));
25+
}
26+
27+
public String getFieldName() {
28+
return fieldName.get();
29+
}
30+
31+
public SimpleStringProperty fieldNameProperty() {
32+
return fieldName;
33+
}
34+
35+
public void setFieldName(String fieldName) {
36+
this.fieldName.set(fieldName);
37+
}
38+
39+
public QueryParameters.SortOrder getSortOrder() {
40+
return sortOrder.get();
41+
}
42+
43+
public SimpleObjectProperty<QueryParameters.SortOrder> sortOrderProperty() {
44+
return sortOrder;
45+
}
46+
47+
public void setSortOrder(QueryParameters.SortOrder sortOrder) {
48+
this.sortOrder.set(sortOrder);
49+
}
50+
51+
public QueryParameters.OrderBy getOrderBy() {
52+
return orderBy.get();
53+
}
54+
55+
public SimpleObjectProperty<QueryParameters.OrderBy> orderByProperty() {
56+
return orderBy;
57+
}
58+
59+
public void setOrderBy(QueryParameters.OrderBy orderBy) {
60+
this.orderBy.set(orderBy);
61+
}
62+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<h1>Statistical Query Group And Sort</h1>
2+
3+
<p>Demonstrates how to query a feature table for statistics grouping and sorting by different fields.</p>
4+
5+
<p><img src="StatisticalQueryGroupAndSort.png"></p>
6+
7+
<h2>How to use the sample</h2>
8+
9+
<p>The sample will start with some default options selected. You can immediately click the "Get Statistics" button to
10+
see the results for these options.</p>
11+
12+
<p>To change the statistic definitions, you can add statistic definitions to the top-left table using the combo boxes
13+
and "Add button". Select a table row and click "Remove" to remove the statistic definition.</p>
14+
15+
<p>To change the group-by fields, check the box by the field you want to group by in the bottom-left list view.</p>
16+
17+
<p>To change the order-by fields, select a group by field (it must be checked) and click the ">>" button to add it to
18+
the Order By table. To remove a field from the Order by table, select it and click the "<<" button. To change the
19+
sort order of the order-by field, click on a cell in the Sort Order column to edit it using a ComboBox.</p>
20+
21+
<h2>How it works</h2>
22+
23+
<p>To query statistics from a feature table:</p>
24+
25+
<ol>
26+
<li>Create and load a <code>ServiceFeatureTable</code>.</li>
27+
<li>Get the feature tables field names list with <code>featureTable.getFields()</code>.</li>
28+
<li>Create <code>StatisticDefinition</code>s specifying the field to compute statistics on and the
29+
<code>StatisticType</code> to compute.</li>
30+
<li>Create <code>StatisticsQueryParameters</code> passing in the list of statistic definitions.</li>
31+
<li>To have the results grouped by fields, add the field names to the query parameters'
32+
<code>groupByFieldNames</code> collection.</li>
33+
<li>To have the results ordered by fields, create <code>OrderBy</code>s, specifying the field name and
34+
<code>SortOrder</code>. Pass these <code>OrderBy</code>s to the parameters' <code>orderByFields</code>
35+
collection.</li>
36+
<li>To execute the query, call <code>featureTable.queryStatisticsAsync(queryParameters)</code></li>
37+
<li>Get the <code>StatisticQueryResult</code>. From this, you can get an iterator of
38+
<code>StatisticRecord</code>s to loop through and display.</li>
39+
</ol>
40+
41+
<h2>Features</h2>
42+
43+
<ul>
44+
<li>Field</li>
45+
<li>QueryParameters</li>
46+
<li>ServiceFeatureTable</li>
47+
<li>StatisticDefinition</li>
48+
<li>StatisticRecord</li>
49+
<li>StatisticType</li>
50+
<li>StatisticsQueryParameters</li>
51+
<li>StatisticsQueryResult</li>
52+
</ul>
94.9 KB
Loading

0 commit comments

Comments
 (0)