Select to view content in your preferred language

Geometry Edits, Spatial Reference Error, Geometric Network

3662
4
06-19-2013 11:34 AM
dmacq
by
Occasional Contributor
I'm working on an editing application that allows users to add new points.  Some of the features participate in a Geometric Network.  When trying to add a point via the web interface, SaveEdits fails with the following error:

Error code '400': 'Unable to complete operation.'
The spatial references do not match


Adding features that do not participate in a GN work fine.  If I delete the GN, those features can be added without issue.  I'm working off an enterprise SDE, and all datasets are versioned.

If I remove all base layer services, I'm able to add features fine.  This leads me to believe there is an issue with the Geometric Network being reprojected.  Our base layer services are in Web Mercator, but our feature layer data (the data being edited) is in State Plane.  Currently we maintain a separate, read-only Web Mercator database that is a mirror of our production data for use in presentation-layer web services. 

Any ideas on a workaround?
0 Kudos
4 Replies
BertrandLAURANCIN
Esri Contributor

Hello,

Bug NIM-088473 : Unable to edit reprojected data that participaties in a geometric network in a feature service ?!!?

Bertrand L.

0 Kudos
JenniferNery
Esri Regular Contributor

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;

            }

        }

0 Kudos
JenniferNery
Esri Regular Contributor

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;

        }

0 Kudos
BertrandLAURANCIN
Esri Contributor

Thank you for your answer , have a nice day!

0 Kudos