How to update a feature's geometry (Point)?

951
2
Jump to solution
04-09-2018 11:49 AM
KristofDewilde
New Contributor II

Hi there

I'm having way more trouble than I should have trying to update a feature's geometry (and sync it back to the database). Using Runtime v100, I retrieved the feature from the database like this:

QueryParameters {
    id: queryParams
    objectIds: [ app.user.OBJECTID ]
    returnGeometry: true
}

ServiceFeatureTable {
    url: http://url.to/restservice

    onLoadStatusChanged: if( loadStatus === Enums.LoadStatusLoaded )
            queryFeatures( queryParams );

    onQueryFeaturesStatusChanged: if( queryFeaturesStatus === Enums.TaskStatusCompleted )
            root.userFeature = queryFeaturesResult.iterator.features[0];
}

Next, I want to update root.userFeature's geometry to the user's current location:

root.userFeature.geometry = mapView.locationDisplay.mapLocation;

I was able to write very similar code to update a feature's attachments and everything just synced magically to the database, so I suspect it's a SpatialReference issue, but I've tried projecting mapLocation to the service's spatial reference, WGS84, ... no luck. When I log app.user.geometry.json, it is the same as mapLocation's. I've tried to applyEdits() but nope. What am I missing here?

Also, Runtime v10 had GeodatabaseFeatureServiceTable.feature( objectid ) to get a specific feature by its OBJECTID. Does v100 have something similar? Couldn't find it in the docs, and the whole queryFeatures seems a bit overkill in my case (I know what the OBJECT ID of the feature I want to edit the geometry of, is).

0 Kudos
1 Solution

Accepted Solutions
nakulmanocha
Esri Regular Contributor

Hi there,

Please make sure the new Location SR is same as the feature layer SR. If not project it using GeometryEngine. And then call updateFeature(). On the updatefeature signal call applyedits(). Like below.

selectedFeature.geometry = newLocation;
 // update the feature in the feature table asynchronously
 featureTable.updateFeature(selectedFeature);‍‍‍
FeatureLayer {
             id: featureLayer

              selectionColor: "cyan"
              selectionWidth: 3

              // declare as child of feature layer, as featureTable is the default property
              ServiceFeatureTable {
                  id: featureTable
                  url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0"

                  // make sure edits are successfully applied to the service
                    onApplyEditsStatusChanged: {
                         if (applyEditsStatus === Enums.TaskStatusCompleted) {
                                    console.log("successfully updated feature");
                             }
                        }

                // signal handler for the asynchronous updateFeature method
                onUpdateFeatureStatusChanged: {
                 if (updateFeatureStatus === Enums.TaskStatusCompleted) {
                            // apply the edits to the service
                            featureTable.applyEdits();
                      }
                  }
              }

Thanks,

Nakul

View solution in original post

2 Replies
nakulmanocha
Esri Regular Contributor

Hi there,

Please make sure the new Location SR is same as the feature layer SR. If not project it using GeometryEngine. And then call updateFeature(). On the updatefeature signal call applyedits(). Like below.

selectedFeature.geometry = newLocation;
 // update the feature in the feature table asynchronously
 featureTable.updateFeature(selectedFeature);‍‍‍
FeatureLayer {
             id: featureLayer

              selectionColor: "cyan"
              selectionWidth: 3

              // declare as child of feature layer, as featureTable is the default property
              ServiceFeatureTable {
                  id: featureTable
                  url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0"

                  // make sure edits are successfully applied to the service
                    onApplyEditsStatusChanged: {
                         if (applyEditsStatus === Enums.TaskStatusCompleted) {
                                    console.log("successfully updated feature");
                             }
                        }

                // signal handler for the asynchronous updateFeature method
                onUpdateFeatureStatusChanged: {
                 if (updateFeatureStatus === Enums.TaskStatusCompleted) {
                            // apply the edits to the service
                            featureTable.applyEdits();
                      }
                  }
              }

Thanks,

Nakul

KristofDewilde
New Contributor II

Thanks for such a quick reply, Nakul!

It was the updateFeature() that I was forgetting... Wow. I guess I'll blame that on it being a Monday, because I feel really stupid right now.  

Do you perhaps know of a GeodatabaseFeatureServiceTable.feature( objectid ) equivalent for Runtime v100 too?

0 Kudos