View on GitHub Sample viewer app

Update a feature’s location in an online feature service.

Image of update geometries feature service

Use case

Sometimes users may want to edit features in an online feature service by moving them.

How to use the sample

Click a feature to select it. Click again to set the updated location for that feature. An alert will be shown confirming success or failure.

How it works

  1. Create and load a ServiceGeodatabase with a feature service URL.
  2. Get the ServiceFeatureTable from the service geodatabase.
  3. Create a FeatureLayer from the service feature table.
  4. Select and load a feature from the FeatureLayer.
  5. Change the selected feature’s location using Feature.setGeometry(geometry).
  6. Apply edits to the ServiceGeodatabase by calling applyEditsAsync, which will update the feature’s geometry on the online service.

Relevant API

  • Feature
  • FeatureLayer
  • ServiceFeatureTable
  • ServiceGeodatabase

Tags

editing, feature layer, feature table, moving, service, updating

Sample Code

module-info.java module-info.java UpdateGeometriesSample.java
/*
* Copyright 2022 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.
*/
module com.esri.samples.update_geometries {
// require ArcGIS Maps SDK for Java module
requires com.esri.arcgisruntime;
// handle SLF4J http://www.slf4j.org/codes.html#StaticLoggerBinder
requires org.slf4j.nop;
// require JavaFX modules that the application uses
requires javafx.graphics;
requires javafx.controls;
exports com.esri.samples.update_geometries;
}