AnsweredAssumed Answered

Incompatible spatial references when sketching new polyline

Question asked by RehmSoftware on Feb 20, 2018
Latest reply on Feb 20, 2018 by RehmSoftware



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