What would cause an 'Incompatible spatial references' error when creating a multipoint.

996
1
12-22-2017 07:13 AM
ufshall
New Contributor II

I currently dealing with an 'Incompatible spatial references' exception when I try to create a Multipoint from an enumeration of MapPoints.The points are kept in an object that stores the user's mouse clicks on the map or entering a lat/lon through text boxes on a Dockpanel. The MapPoints created all have the same spatial reference.

The points entered through the text boxes are projected from the GCS to the spatial reference of the MapView since we work in state plane systems. Those points will show correctly on the map but when trying to use them they fail to comply. The error occurs in this function:

        protected internal async void UpdateMapViewOverlay()
        {
            var UserBoundsVm = UfsProTools.UserBoundsVm;
            var mapView = MapView.Active;
            List<MapPoint> points = new List<MapPoint>();

            List<UserPlotObject> userPlots = UserBoundsVm._UserPlotObject.OrderBy(o => o.UserNumber).ToList();

            await QueuedTask.Run(() =>
            {
                foreach (UserPlotObject plot in userPlots)
                {
                    points.Add(plot.UserEntryPoint);
                }
                using (MultipointBuilder pointBuilder = new MultipointBuilder(points))
                {
                    Multipoint multiPoint = pointBuilder.ToGeometry();

                    var markerSymbol = SymbolFactory.Instance.ConstructMarker(ColorFactory.Instance.RedRGB, 12.0, SimpleMarkerStyle.Diamond);
                    var pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(markerSymbol);
                    var disposable = mapView.AddOverlay(multiPoint, pointSymbol.MakeSymbolReference());

                    if (points.Count > 1)
                    {
                        using (PolylineBuilder lineBuilder = new PolylineBuilder(multiPoint))
                        {
                            Polyline polyline = lineBuilder.ToGeometry();
                            var lineStyle = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlueRGB, 2.0,
                                SimpleLineStyle.Solid);

                            mapView.UpdateOverlay(disposable, polyline, lineStyle.MakeSymbolReference());
                        }
                    }
                }
            });
        }

The error occurs when the MultipointBuilder tries to create the pointBuilder from the points enumeration. What would cause this to happen?

Thank you in advance for any help!

Scott

0 Kudos
1 Reply
CharlesMacleod
Esri Regular Contributor

Internally the builder is calling SpatialReference.IsEqual on each spatial reference. At some point, one of your spatial references is failing the equality check against the spatialreference that preceeds it. To find which one you should be able to construct your own loop on the point collection and check each spatial reference with the spatial reference that preceeds it.

Note - a comparison of a spatial reference that is null with any other spatial reference is always false.   

http://pro.arcgis.com/en/pro-app/sdk/api-reference/#topic8776.html (IsEqual method)