Hello,
Bug NIM-088473 : Unable to edit reprojected data that participaties in a geometric network in a feature service ?!!?
Bertrand L.
You can subscribe to FeatureLayer.BeginSaveEdits and update the geometry before they get saved.
For example, see code below (assuming you have Microsoft.Bcl.Async installed from Nuget). When projecting geometries to SpatialReference other than 4326 and 3857, you can use GeometryService.Project.
Otherwise, you can also use event-based example is in the SDK: ArcGIS API for Silverlight - Interactive Samples | ArcGIS for Developers
private async void FeatureLayer_BeginSaveEdits(object sender, ESRI.ArcGIS.Client.Tasks.BeginEditEventArgs e)
{
var layer = (FeatureLayer)sender;
if (e.Adds != null)
{
foreach (var g in e.Adds)
g.Geometry = await ProjectGeometryAsync(g.Geometry, layer.SpatialReference);
}
}
private SpatialReference SR_4326 = new SpatialReference(4326);
private SpatialReference SR_3857 = new SpatialReference(3857);
private async Geometry ProjectGeometryAsync(Geometry inputGeometry, SpatialReference outSR)
{
if (outSR == null || inputGeometry == null || SpatialReference.AreEqual(outSR, inputGeometry.SpatialReference))
return inputGeometry;
else if( SpatialReference.AreEqual(inputGeometry.SpatialReference, SR_3857) && SpatialReference.AreEqual(outSR, SR_4326))
return new WebMercator().ToGeographic(inputGeometry);
else if( SpatialReference.AreEqual(inputGeometry.SpatialReference, SR_4326) && SpatialReference.AreEqual(outSR, SR_3857))
return new WebMercator().FromGeographic(inputGeometry)
else
{
var task = new GeometryService("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer");
var result = await task.ProjectTaskAsync(new Graphic[]{new Graphic(){Geometry = inputGeometry}}, outSR);
if(result != null && result.Results != null && result.Results.Count > 0)
return result.Results[0].Geometry;
}
}
Sorry, I think the ProjectGeometryAsync in my previous post will have compile errors. SpatialReference.AreEqual takes a 3rd parameter for ignoring null and since code below is an async method, it should have return Task<Geometry>.
The idea is before features are saved, you update their geometry into the expected SpatialReference.
private async Task<Geometry> ProjectGeometryAsync(Geometry inputGeometry, SpatialReference outSR)
{
if (outSR == null || inputGeometry == null || SpatialReference.AreEqual(outSR, inputGeometry.SpatialReference, false))
return inputGeometry;
else if (SpatialReference.AreEqual(inputGeometry.SpatialReference, SR_3857, false) && SpatialReference.AreEqual(outSR, SR_4326, false))
return new WebMercator().ToGeographic(inputGeometry);
else if (SpatialReference.AreEqual(inputGeometry.SpatialReference, SR_4326, false) && SpatialReference.AreEqual(outSR, SR_3857, false))
return new WebMercator().FromGeographic(inputGeometry);
else
{
var task = new GeometryService("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer");
var result = await task.ProjectTaskAsync(new Graphic[] { new Graphic() { Geometry = inputGeometry } }, outSR);
if (result != null && result.Results != null && result.Results.Count > 0)
return result.Results[0].Geometry;
}
return inputGeometry;
}
Thank you for your answer , have a nice day!