Select to view content in your preferred language

Incompatible spatial references when sketching new polyline

1182
2
Jump to solution
02-20-2018 07:36 AM
RehmSoftware
Regular Contributor

Hi,

I have a feature layer with polylines, let's call it "polyline_layer". And there are already some polylines on this layer. Now I created a map tool that lets the user sketch a new polyline on that specific layer. So far so good, but I need to check whether the newly sketched polyline touches an existing polyline (so I can modify the existing polyline instead of creating a new one).. but when I call "GeometryEngine.Touches" to check whether two polylines touch an exception is thrown ("incompatible spatial references"). How can this happen? The new polyline has been sketched on the same layer that contains the existing polylines. The WKIDs of the spatial references are the same, but IsEqual returns false nonetheless. This seems a bit strange to me?!

If I project the sketched polyline into the spatial reference of the layer everything works fine, but it's stilll a bit weird. Here's some example code:

    internal class CreatePolyline : MapTool {
        public CreatePolyline() {
            IsSketchTool = true;
            UseSnapping = true;
            SketchType = SketchGeometryType.Line;
        }

        /// <summary>
        /// Called when the sketch finishes. This is where we will create the sketch operation and then execute it.
        /// </summary>
        /// <param name="geometry">The geometry created by the sketch.</param>
        /// <returns>A Task returning a Boolean indicating if the sketch complete event was successfully handled.</returns>
        protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry) {
            var sketchedPolyline = (Polyline)geometry;
            if (sketchedPolyline == null)
                return false;

            if (sketchedPolyline.PointCount < 2)
                return false;

            FeatureLayer polylineFeatureLayer = //Get feature layer called "polyline_layer"
            var geoEngine = GeometryEngine.Instance;
            await QueuedTask.Run(() => {
                //Uncomment the following lines to avoid the exception
                //var srLayer = polylineFeatureLayer.GetSpatialReference();
                //sketchedPolyline = (Polyline)geoEngine.Project(sketchedPolyline, srLayer);
                
                var rowCursor = polylineFeatureLayer.Search();
                while (rowCursor.MoveNext()) {
                    var polyline = (Polyline)rowCursor.Current["SHAPE"];
                    if (geoEngine.Touches(sketchedPolyline, polyline)) {
                        //Do something..
                    }
                }
            });

            return true;
        }
    }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I'd be glad if anyone could look into it! Thanks in advance.

Best Regards

Christian

0 Kudos
1 Solution

Accepted Solutions
ThomasEmge
Esri Contributor

You are correct in your observation, the sketch geometry is driven by the map. Even though the behavior seems to be be somewhat counterintuitive in your case, think of the map tool as the base class for any type of screen interaction. The returned geometry can be in screen or in map coordinates. For example, for an interactive selection tool in a scene, you would switch the geometry to be returned as screen coordinates. In the context of editing, you are tying the tool to specific geometry type like points, lines, etc. However, the tool itself is unaware of underlying specifics of the layer or the underlying dataset. This information is provided either by the editing template or through interrogation.

For more information, please take a look at the ProConcept section about MapTools ProConcepts Map Exploration · Esri/arcgis-pro-sdk Wiki · GitHub 

View solution in original post

2 Replies
ThomasEmge
Esri Contributor

You are correct in your observation, the sketch geometry is driven by the map. Even though the behavior seems to be be somewhat counterintuitive in your case, think of the map tool as the base class for any type of screen interaction. The returned geometry can be in screen or in map coordinates. For example, for an interactive selection tool in a scene, you would switch the geometry to be returned as screen coordinates. In the context of editing, you are tying the tool to specific geometry type like points, lines, etc. However, the tool itself is unaware of underlying specifics of the layer or the underlying dataset. This information is provided either by the editing template or through interrogation.

For more information, please take a look at the ProConcept section about MapTools ProConcepts Map Exploration · Esri/arcgis-pro-sdk Wiki · GitHub 

RehmSoftware
Regular Contributor

Thanks for your reply, it does make sense.. somewhat ^^

Anyway, so the only way to avoid the exception is reprojecting the polyline into the layer's spatial reference? Or is there something else I should do?

0 Kudos