Skip to content

Commit 8937c36

Browse files
Rachael-ERachael Ellenjenmerritt
authored
Editing samples: update to use service geodatabase (#683)
* update add features sample * update delete features sample * update the update attributes and geometries sample * update metadata * Update editing/delete-features/src/main/java/com/esri/samples/delete_features/DeleteFeaturesSample.java Co-authored-by: Jen Merritt <[email protected]> * Update editing/delete-features/src/main/java/com/esri/samples/delete_features/DeleteFeaturesSample.java Co-authored-by: Jen Merritt <[email protected]> * Update editing/update-attributes/src/main/java/com/esri/samples/update_attributes/UpdateAttributesSample.java Co-authored-by: Jen Merritt <[email protected]> * Update editing/update-attributes/src/main/java/com/esri/samples/update_attributes/UpdateAttributesSample.java Co-authored-by: Jen Merritt <[email protected]> * Update editing/update-attributes/src/main/java/com/esri/samples/update_attributes/UpdateAttributesSample.java Co-authored-by: Jen Merritt <[email protected]> * Update editing/update-geometries/src/main/java/com/esri/samples/update_geometries/UpdateGeometriesSample.java Co-authored-by: Jen Merritt <[email protected]> * Update editing/update-geometries/src/main/java/com/esri/samples/update_geometries/UpdateGeometriesSample.java Co-authored-by: Jen Merritt <[email protected]> Co-authored-by: Rachael Ellen <[email protected]> Co-authored-by: Jen Merritt <[email protected]>
1 parent 85501bb commit 8937c36

File tree

12 files changed

+170
-92
lines changed

12 files changed

+170
-92
lines changed

editing/add-features/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@ Click on a location on the map to add a feature at that location.
1414

1515
## How it works
1616

17-
1. Create a `ServiceFeatureTable` from a URL.
18-
2. Create a `FeatureLayer` derived from the `ServiceFeatureTable` instance.
19-
3. Create a `Feature` with attributes and a location using the `ServiceFeatureTable`.
20-
4. Add the `Feature` to the `ServiceFeatureTable`.
21-
5. *Apply edits* to the `ServiceFeatureTable` which will upload the new feature to the online service.
17+
1. Create and load a `ServiceGeodatabase` with a feature service URL.
18+
2. Get the `ServiceFeatureTable` from the service geodatabase.
19+
3. Create a `FeatureLayer` from the service feature table.
20+
4. Create a `Feature` with attributes and a location using the `ServiceFeatureTable`.
21+
5. Add the `Feature` to the `ServiceFeatureTable`.
22+
6. Apply edits to the `ServiceGeodatabase` by calling `applyEditsAsync`, which will upload the new feature to the online service.
2223

2324
## Relevant API
2425

2526
* Feature
2627
* FeatureEditResult
2728
* FeatureLayer
2829
* ServiceFeatureTable
30+
* ServiceGeodatabase
2931

3032
## Tags
3133

editing/add-features/README.metadata.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"Feature",
1313
"FeatureEditResult",
1414
"FeatureLayer",
15-
"ServiceFeatureTable"
15+
"ServiceFeatureTable",
16+
"ServiceGeodatabase"
1617
],
1718
"redirect_from": [
1819
"/java/latest/sample-code/add-features.htm"
@@ -21,7 +22,8 @@
2122
"Feature",
2223
"FeatureEditResult",
2324
"FeatureLayer",
24-
"ServiceFeatureTable"
25+
"ServiceFeatureTable",
26+
"ServiceGeodatabase"
2527
],
2628
"snippets": [
2729
"src/main/java/com/esri/samples/add_features/AddFeaturesSample.java"

editing/add-features/src/main/java/com/esri/samples/add_features/AddFeaturesSample.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
3535
import com.esri.arcgisruntime.concurrent.ListenableFuture;
3636
import com.esri.arcgisruntime.data.Feature;
37-
import com.esri.arcgisruntime.data.FeatureEditResult;
37+
import com.esri.arcgisruntime.data.FeatureTableEditResult;
3838
import com.esri.arcgisruntime.data.ServiceFeatureTable;
39+
import com.esri.arcgisruntime.data.ServiceGeodatabase;
3940
import com.esri.arcgisruntime.geometry.GeometryEngine;
4041
import com.esri.arcgisruntime.geometry.Point;
4142
import com.esri.arcgisruntime.layers.FeatureLayer;
@@ -51,7 +52,7 @@ public class AddFeaturesSample extends Application {
5152
private ServiceFeatureTable featureTable;
5253

5354
private static final String SERVICE_LAYER_URL =
54-
"https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0";
55+
"https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer";
5556

5657
@Override
5758
public void start(Stage stage) {
@@ -82,15 +83,21 @@ public void start(Stage stage) {
8283
// set a viewpoint on the map view
8384
mapView.setViewpoint(new Viewpoint(40, -95, 36978595));
8485

85-
// create service feature table from URL
86-
featureTable = new ServiceFeatureTable(SERVICE_LAYER_URL);
86+
// create a service geodatabase from the service layer url and load it
87+
var serviceGeodatabase = new ServiceGeodatabase(SERVICE_LAYER_URL);
88+
serviceGeodatabase.addDoneLoadingListener(() -> {
8789

88-
// create a feature layer from table
89-
FeatureLayer featureLayer = new FeatureLayer(featureTable);
90-
91-
// add the layer to the ArcGISMap
92-
map.getOperationalLayers().add(featureLayer);
90+
// create service feature table from the service geodatabase's table first layer
91+
featureTable = serviceGeodatabase.getTable(0);
9392

93+
// create a feature layer from table
94+
var featureLayer = new FeatureLayer(featureTable);
95+
96+
// add the layer to the ArcGISMap
97+
map.getOperationalLayers().add(featureLayer);
98+
});
99+
serviceGeodatabase.loadAsync();
100+
94101
mapView.setOnMouseClicked(event -> {
95102
// check that the primary mouse button was clicked
96103
if (event.isStillSincePress() && event.getButton() == MouseButton.PRIMARY) {
@@ -152,16 +159,17 @@ private void addFeature(Point mapPoint, ServiceFeatureTable featureTable) {
152159
private void applyEdits(ServiceFeatureTable featureTable) {
153160

154161
// apply the changes to the server
155-
ListenableFuture<List<FeatureEditResult>> editResult = featureTable.applyEditsAsync();
162+
ListenableFuture<List<FeatureTableEditResult>> editResult = featureTable.getServiceGeodatabase().applyEditsAsync();
156163
editResult.addDoneListener(() -> {
157164
try {
158-
List<FeatureEditResult> edits = editResult.get();
165+
List<FeatureTableEditResult> edits = editResult.get();
159166
// check if the server edit was successful
160167
if (edits != null && edits.size() > 0) {
161-
if (!edits.get(0).hasCompletedWithErrors()) {
168+
var featureEditResult = edits.get(0).getEditResult().get(0);
169+
if (!featureEditResult.hasCompletedWithErrors()) {
162170
displayMessage(null, "Feature successfully added");
163171
} else {
164-
throw edits.get(0).getError();
172+
throw featureEditResult.getError();
165173
}
166174
}
167175
} catch (InterruptedException | ExecutionException e) {

editing/delete-features/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@ Click on a feature on the Map, then click the 'delete' button to delete.
1414

1515
## How it works
1616

17-
1. Create a `ServiceFeatureTable` object from a URL.
18-
2. Create a `FeatureLayer` object from the `ServiceFeatureTable`.
19-
3. Select features from the `FeatureLayer` via `selectFeatures()`.
20-
4. Remove the selected features from the `ServiceFeatureTable` using `deleteFeaturesAsync()`.
21-
5. Update the table on the server using `applyEditsAsync()`.
17+
1. Create and load a `ServiceGeodatabase` with a feature service URL.
18+
2. Get the `ServiceFeatureTable` from the service geodatabase.
19+
3. Create a `FeatureLayer` from the service feature table.
20+
4. Identify the selected feature by using `identifyLayerAsync`.
21+
5. Remove the selected features from the `ServiceFeatureTable` using `deleteFeaturesAsync`.
22+
6. Update the data on the server using `applyEditsAsync` on the `ServiceGeodatabase`, which will remove the feature from the online service.
2223

2324
## Relevant API
2425

2526
* Feature
2627
* FeatureLayer
2728
* ServiceFeatureTable
29+
* ServiceGeodatabase
2830

2931
## Tags
3032

31-
deletion, feature, online, Service, table
33+
deletion, feature, online, service, table

editing/delete-features/README.metadata.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@
66
"DeleteFeatures.gif"
77
],
88
"keywords": [
9-
"Service",
109
"deletion",
1110
"feature",
1211
"online",
12+
"service",
1313
"table",
1414
"Feature",
1515
"FeatureLayer",
16-
"ServiceFeatureTable"
16+
"ServiceFeatureTable",
17+
"ServiceGeodatabase"
1718
],
1819
"redirect_from": [
1920
"/java/latest/sample-code/delete-features.htm"
2021
],
2122
"relevant_apis": [
2223
"Feature",
2324
"FeatureLayer",
24-
"ServiceFeatureTable"
25+
"ServiceFeatureTable",
26+
"ServiceGeodatabase"
2527
],
2628
"snippets": [
2729
"src/main/java/com/esri/samples/delete_features/DeleteFeaturesSample.java"

editing/delete-features/src/main/java/com/esri/samples/delete_features/DeleteFeaturesSample.java

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@
3636
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
3737
import com.esri.arcgisruntime.concurrent.ListenableFuture;
3838
import com.esri.arcgisruntime.data.Feature;
39-
import com.esri.arcgisruntime.data.FeatureEditResult;
39+
import com.esri.arcgisruntime.data.FeatureTableEditResult;
4040
import com.esri.arcgisruntime.data.FeatureQueryResult;
4141
import com.esri.arcgisruntime.data.ServiceFeatureTable;
42+
import com.esri.arcgisruntime.data.ServiceGeodatabase;
4243
import com.esri.arcgisruntime.layers.FeatureLayer;
4344
import com.esri.arcgisruntime.mapping.ArcGISMap;
4445
import com.esri.arcgisruntime.mapping.BasemapStyle;
@@ -55,7 +56,7 @@ public class DeleteFeaturesSample extends Application {
5556
private ListenableFuture<FeatureQueryResult> selectionResult;
5657

5758
private static final String FEATURE_LAYER_URL =
58-
"https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0";
59+
"https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer";
5960

6061
@Override
6162
public void start(Stage stage) {
@@ -106,32 +107,48 @@ public void start(Stage stage) {
106107
// set a viewpoint on the map view
107108
mapView.setViewpoint(new Viewpoint(40, -95, 36978595));
108109

109-
// create service feature table from URL
110-
featureTable = new ServiceFeatureTable(FEATURE_LAYER_URL);
110+
// create a service geodatabase from the service layer url and load it
111+
var serviceGeodatabase = new ServiceGeodatabase(FEATURE_LAYER_URL);
112+
serviceGeodatabase.addDoneLoadingListener(() -> {
111113

112-
// create a feature layer from table
113-
featureLayer = new FeatureLayer(featureTable);
114+
// create a service feature table from the first layer on the service geodatabase's table
115+
featureTable = serviceGeodatabase.getTable(0);
114116

115-
// add the layer to the ArcGISMap
116-
map.getOperationalLayers().add(featureLayer);
117+
// create a feature layer from the feature table
118+
featureLayer = new FeatureLayer(featureTable);
119+
120+
// add the layer to the ArcGISMap
121+
map.getOperationalLayers().add(featureLayer);
122+
});
123+
serviceGeodatabase.loadAsync();
117124

118125
mapView.setOnMouseClicked(event -> {
119126
// check for primary or secondary mouse click
120127
if (event.isStillSincePress() && event.getButton() == MouseButton.PRIMARY) {
121128
// create a point from where the user clicked
122129
Point2D point = new Point2D(event.getX(), event.getY());
130+
131+
// clear any previous selection
132+
featureLayer.clearSelection();
133+
deleteButton.setDisable(true);
134+
123135
// identify the clicked feature
124136
ListenableFuture<IdentifyLayerResult> results = mapView.identifyLayerAsync(featureLayer, point, 1, false);
125137
results.addDoneListener(() -> {
126138
try {
127139
IdentifyLayerResult layer = results.get();
128-
// search the layers for identified features
129-
List<Feature> features = layer.getElements().stream().filter(g -> g instanceof Feature).map(
130-
g -> (Feature) g).collect(Collectors.toList());
131-
// add the clicked feature to the selection
132-
if (features.size() > 0) {
133-
featureLayer.selectFeatures(features);
134-
deleteButton.setDisable(false);
140+
if (!layer.getElements().isEmpty()) {
141+
// search the layers for identified features
142+
List<Feature> features = layer.getElements()
143+
.stream()
144+
.filter(g -> g instanceof Feature)
145+
.map(g -> (Feature) g)
146+
.collect(Collectors.toList());
147+
// add the clicked feature to the selection
148+
if (features.size() > 0) {
149+
featureLayer.selectFeatures(features);
150+
deleteButton.setDisable(false);
151+
}
135152
}
136153
} catch (InterruptedException | ExecutionException e) {
137154
displayMessage("Exception getting identify result", e.getCause().getMessage());
@@ -169,16 +186,18 @@ private void deleteFeatures(FeatureQueryResult features, ServiceFeatureTable fea
169186
private void applyEdits(ServiceFeatureTable featureTable) {
170187

171188
// apply the changes to the server
172-
ListenableFuture<List<FeatureEditResult>> editResult = featureTable.applyEditsAsync();
189+
ListenableFuture<List<FeatureTableEditResult>> editResult = featureTable.getServiceGeodatabase().applyEditsAsync();
173190
editResult.addDoneListener(() -> {
174191
try {
175-
List<FeatureEditResult> edits = editResult.get();
192+
List<FeatureTableEditResult> edits = editResult.get();
176193
// check if the server edit was successful
177194
if (edits != null && edits.size() > 0) {
178-
if (!edits.get(0).hasCompletedWithErrors()) {
195+
var featureEditResult = edits.get(0).getEditResult().get(0);
196+
if (!featureEditResult.hasCompletedWithErrors()) {
179197
displayMessage(null, "Feature successfully deleted");
198+
deleteButton.setDisable(true);
180199
} else {
181-
throw edits.get(0).getError();
200+
throw featureEditResult.getError();
182201
}
183202
}
184203
} catch (InterruptedException | ExecutionException e) {

editing/update-attributes/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@ To change the feature's damage property, click on the feature to select it, and
1414

1515
## How it works
1616

17-
1. Create a `ServiceFeatureTable` object from a URL.
18-
2. Create a `FeatureLayer` object from the `ServiceFeatureTable`.
19-
3. Select features from the `FeatureLayer`.
20-
4. To update the feature's attribute, first load it, then use `.getAttributes().put(keyValuePair)` to modify the desired attribute.
21-
5. Update the feature table with `.updateFeatureAsync(feature)`.
22-
6. After a change, apply the changes on the service feature table using `.applyEditsAsync()`.
17+
1. Create and load a `ServiceGeodatabase` with a feature service URL.
18+
2. Get the `ServiceFeatureTable` from the service geodatabase.
19+
3. Create a `FeatureLayer` from the service feature table.
20+
4. Select features from the `FeatureLayer`.
21+
5. To update the feature's attribute, first load it, then use `.getAttributes().put(keyValuePair)` to modify the desired attribute.
22+
6. Update the feature table with `.updateFeatureAsync(feature)`.
23+
7. Apply edits to the `ServiceGeodatabase` by calling `applyEditsAsync`, which will update the feature on the online service.
2324

2425
## Relevant API
2526

2627
* ArcGISFeature
2728
* FeatureLayer
2829
* ServiceFeatureTable
30+
* ServiceGeodatabase
2931

3032
## Tags
3133

editing/update-attributes/README.metadata.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@
1616
"value",
1717
"ArcGISFeature",
1818
"FeatureLayer",
19-
"ServiceFeatureTable"
19+
"ServiceFeatureTable",
20+
"ServiceGeodatabase"
2021
],
2122
"redirect_from": [
2223
"/java/latest/sample-code/update-attributes.htm"
2324
],
2425
"relevant_apis": [
2526
"ArcGISFeature",
2627
"FeatureLayer",
27-
"ServiceFeatureTable"
28+
"ServiceFeatureTable",
29+
"ServiceGeodatabase"
2830
],
2931
"snippets": [
3032
"src/main/java/com/esri/samples/update_attributes/UpdateAttributesSample.java"

0 commit comments

Comments
 (0)