How to change the shape of a feature?

561
2
Jump to solution
05-27-2019 12:17 AM
RehmSoftware
New Contributor III

Hi,

I have a simple polyline feature layer and there are some polylines on it that I want to reshape/replace with new polylines and I'm having a little trouble with it. So, this code here works fine:

public async Task SetPolylineShapeAsyncViaCursor(int polylineId, ArcGISGeo.Polyline newPolyline) {
FeatureLayer polylineFeatureLayer = //Get feature layer
if (polylineFeatureLayer == null)
return;

await ArcGISTasks.QueuedTask.Run(() => {
var queryFilter = new ArcGISData.QueryFilter();
queryFilter.WhereClause = String.Format("{0} = {1}", "PID", polylineId);
var cursor = polylineFeatureLayer.Search(queryFilter);
if (cursor.MoveNext()) {
var feature = (ArcGISData.Feature)cursor.Current;
feature.SetShape(newPolyline);
feature.Store();
}
});
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

However, I'd very much prefer to use an EditOperation since this polyline operation is part of a bigger editing process and I eventually want to pass around an EditOperation instance that all methods use and in the end ExecuteAsync is called once. For now I'd like to have it working with a local EditOperation, but it doesn't work when I try to modify the shape via EditOperation.Reshape (it only yields an "EditOperation failed" error):

public async Task SetPolylineShapeAsyncViaReshape(int polylineId, ArcGISGeo.Polyline newPolyline) {
FeatureLayer polylineFeatureLayer = //Get feature layer
if (polylineFeatureLayer == null)
return;

long polylineOID = await this.GetPolylineOIDAsync(polylineId);
if (polylineOID == -1)
return;

var polylineOperation = new EditOperation();
polylineOperation.Reshape(polylineFeatureLayer, polylineOID, newPolyline);
await polylineOperation.ExecuteAsync();
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

It must be a small detail that's missing but I'd be glad if somebody could tell me what I'm doing wrong.

Thanks in adavance

Best Regards

Christian

0 Kudos
1 Solution

Accepted Solutions
SeanJones
Esri Regular Contributor

Hi Christian,

The editoperation reshape method is the equivalent to the reshape tool in the UI.

Since your looking to replace the exiting geometry with a new one you can use one of the many Modify methods instead.

This overload matches the variables you have. The dictionary of attributes is optional.

EditOperation.Modify(ArcGIS.Desktop.Mapping.Layer, long, ArcGIS.Core.Geometry.Geometry, System.Collections.Generic.Dictionary<string, object>)

View solution in original post

0 Kudos
2 Replies
SeanJones
Esri Regular Contributor

Hi Christian,

The editoperation reshape method is the equivalent to the reshape tool in the UI.

Since your looking to replace the exiting geometry with a new one you can use one of the many Modify methods instead.

This overload matches the variables you have. The dictionary of attributes is optional.

EditOperation.Modify(ArcGIS.Desktop.Mapping.Layer, long, ArcGIS.Core.Geometry.Geometry, System.Collections.Generic.Dictionary<string, object>)

View solution in original post

0 Kudos
RehmSoftware
New Contributor III

Hi Sean,

thank you for your reply. I got it working with the Modify-method 🙂

Best Regards

Christian