Exemple #1
0
        /// <summary>
        /// Update snapping
        /// </summary>
        /// <param name="sourceLayer"></param>
        /// The layer of feature.
        /// <param name="feature"></param>
        /// Feature that is snapped. Feature is not always available.
        /// <param name="geometry"></param>
        /// actual geometry of the feature that is snapped.
        /// <param name="worldPosition"></param>
        /// <param name="trackerIndex"></param>
        public ISnapResult ExecuteLayerSnapRules(ILayer sourceLayer, IFeature feature, IGeometry geometry,
                                                 ICoordinate worldPosition, int trackerIndex)
        {
            IList <ISnapRule> snapRules  = MapControl.GetSnapRules(sourceLayer, feature, geometry, trackerIndex);
            ISnapResult       snapResult = null;

            for (int i = 0; i < snapRules.Count; i++)
            {
                ISnapRule rule = snapRules[i];
                snapResult = ExecuteSnapRule(rule, feature, geometry, null, worldPosition, trackerIndex);
                if (null != snapResult)
                {
                    break;
                }
                // If snapping failed for the last rule and snapping is obligatory
                // any position is valid
                // todo add rule with SnapRole.Free?
                if ((!rule.Obligatory) && (i == snapRules.Count - 1))
                {
                    snapResult = new SnapResult(worldPosition, null, null, -1, -1);
                }
            }
            if (0 == snapRules.Count)
            {
                snapResult = new SnapResult(worldPosition, null, null, -1, -1);
            }
            return(snapResult);
        }
Exemple #2
0
        public static void LineStringSnapStartEnd(ref double minDistance, ref ISnapResult snapResult, ILineString lineString, ICoordinate worldPos)
        {
            ICoordinate c1 = lineString.Coordinates[0];
            ICoordinate location;
            int         snapIndexPrevious;
            int         snapIndexNext;
            double      distance = GeometryHelper.Distance(c1.X, c1.Y, worldPos.X, worldPos.Y);

            if (distance < minDistance)
            {
                location          = c1;
                snapIndexPrevious = 0;
                snapIndexNext     = 0;
                minDistance       = distance;
                snapResult        = new SnapResult(location, null, lineString, snapIndexPrevious, snapIndexNext);
            }
            ICoordinate c2 = lineString.Coordinates[lineString.Coordinates.Length - 1];

            distance = GeometryHelper.Distance(c2.X, c2.Y, worldPos.X, worldPos.Y);
            if (distance >= minDistance)
            {
                return;
            }
            location          = c2;
            snapIndexPrevious = lineString.Coordinates.Length - 1;
            snapIndexNext     = lineString.Coordinates.Length - 1;
            snapResult        = new SnapResult(location, null, lineString, snapIndexPrevious, snapIndexNext);
        }
Exemple #3
0
 public static void LineStringSnapAllTrackers(ref double minDistance, ref ISnapResult snapResult, ILineString lineString, ICoordinate worldPos)
 {
     for (int i = 0; i < lineString.Coordinates.Length; i++)
     {
         ICoordinate c1 = lineString.Coordinates[i];
         double distance = GeometryHelper.Distance(c1.X, c1.Y, worldPos.X, worldPos.Y);
         if (distance >= minDistance) 
             continue;
         minDistance = distance;
         snapResult =  new SnapResult(lineString.Coordinates[i], null, lineString, i, i);
     }
 }
Exemple #4
0
        public static void LineStringSnapFreeAtObject(ref double minDistance, ref ISnapResult snapResult, IFeature feature, ILineString lineString, ICoordinate worldPos)
        {
            int vertexIndex;
            var nearestPoint = GeometryHelper.GetNearestPointAtLine(lineString, worldPos, minDistance, out vertexIndex);

            if (nearestPoint == null)
            {
                return;
            }

            minDistance = GeometryHelper.Distance(nearestPoint.X, nearestPoint.Y, worldPos.X, worldPos.Y);
            snapResult  = new SnapResult(nearestPoint, feature, lineString, vertexIndex - 1, vertexIndex);
        }
Exemple #5
0
        public static void LineStringSnapFreeAtObject(ref double minDistance, ref ISnapResult snapResult, IFeature feature, ILineString lineString, ICoordinate worldPos)
        {
            int vertexIndex;
            var nearestPoint = GeometryHelper.GetNearestPointAtLine(lineString, worldPos, minDistance, out vertexIndex);

            if (nearestPoint == null)
            {
                return;
            }

            minDistance = GeometryHelper.Distance(nearestPoint.X, nearestPoint.Y, worldPos.X, worldPos.Y);
            snapResult = new SnapResult(nearestPoint, feature, lineString, vertexIndex - 1, vertexIndex);
        }
Exemple #6
0
 public static void LineStringSnapAllTrackers(ref double minDistance, ref ISnapResult snapResult, ILineString lineString, ICoordinate worldPos)
 {
     for (int i = 0; i < lineString.Coordinates.Length; i++)
     {
         ICoordinate c1       = lineString.Coordinates[i];
         double      distance = GeometryHelper.Distance(c1.X, c1.Y, worldPos.X, worldPos.Y);
         if (distance >= minDistance)
         {
             continue;
         }
         minDistance = distance;
         snapResult  = new SnapResult(lineString.Coordinates[i], null, lineString, i, i);
     }
 }
Exemple #7
0
 public static void LineStringSnapFree(ref double minDistance, ref ISnapResult snapResult, ILineString lineString, ICoordinate worldPos)
 {
     for (int i = 1; i < lineString.Coordinates.Length; i++)
     {
         ICoordinate c1       = lineString.Coordinates[i - 1];
         ICoordinate c2       = lineString.Coordinates[i];
         double      distance = GeometryHelper.LinePointDistance(c1.X, c1.Y, c2.X, c2.Y,
                                                                 worldPos.X, worldPos.Y);
         if (distance >= minDistance)
         {
             continue;
         }
         minDistance = distance;
         snapResult  = new SnapResult(GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y), null, lineString, i - 1, i);
     }
 }
Exemple #8
0
 public static void PolygonSnapFreeAtObject(ref double minDistance, ref ISnapResult snapResult, IPolygon polygon, ICoordinate worldPos)
 {
     for (int i = 1; i < polygon.Coordinates.Length; i++)
     {
         ICoordinate c1       = polygon.Coordinates[i - 1];
         ICoordinate c2       = polygon.Coordinates[i];
         double      distance = GeometryHelper.LinePointDistance(c1.X, c1.Y, c2.X, c2.Y,
                                                                 worldPos.X, worldPos.Y);
         if (distance >= minDistance)
         {
             continue;
         }
         minDistance = distance;
         ICoordinate min_c1 = polygon.Coordinates[i - 1];
         ICoordinate min_c2 = polygon.Coordinates[i];
         snapResult = new SnapResult(GeometryHelper.NearestPointAtSegment(min_c1.X, min_c1.Y,
                                                                          min_c2.X, min_c2.Y, worldPos.X,
                                                                          worldPos.Y), null, polygon, i - 1, i);
     }
 }
Exemple #9
0
 public static void LineStringSnapStartEnd(ref double minDistance, ref ISnapResult snapResult, ILineString lineString, ICoordinate worldPos)
 {
     ICoordinate c1 = lineString.Coordinates[0];
     ICoordinate location;
     int snapIndexPrevious;
     int snapIndexNext;
     double distance = GeometryHelper.Distance(c1.X, c1.Y, worldPos.X, worldPos.Y);
     if (distance < minDistance)
     {
         location = c1;
         snapIndexPrevious = 0;
         snapIndexNext = 0;
         minDistance = distance;
         snapResult = new SnapResult(location, null, lineString, snapIndexPrevious, snapIndexNext);
     }
     ICoordinate c2 = lineString.Coordinates[lineString.Coordinates.Length - 1];
     distance = GeometryHelper.Distance(c2.X, c2.Y, worldPos.X, worldPos.Y);
     if (distance >= minDistance) 
         return;
     location = c2;
     snapIndexPrevious = lineString.Coordinates.Length - 1;
     snapIndexNext = lineString.Coordinates.Length - 1;
     snapResult = new SnapResult(location, null, lineString, snapIndexPrevious, snapIndexNext);
 }
Exemple #10
0
 public static void PolygonSnapFreeAtObject(ref double minDistance, ref ISnapResult snapResult, IPolygon polygon, ICoordinate worldPos)
 {
     for (int i = 1; i < polygon.Coordinates.Length; i++)
     {
         ICoordinate c1 = polygon.Coordinates[i - 1];
         ICoordinate c2 = polygon.Coordinates[i];
         double distance = GeometryHelper.LinePointDistance(c1.X, c1.Y, c2.X, c2.Y,
                                                            worldPos.X, worldPos.Y);
         if (distance >= minDistance) 
             continue;
         minDistance = distance;
         ICoordinate min_c1 = polygon.Coordinates[i - 1];
         ICoordinate min_c2 = polygon.Coordinates[i];
         snapResult = new SnapResult(GeometryHelper.NearestPointAtSegment(min_c1.X, min_c1.Y,
                                                                    min_c2.X, min_c2.Y, worldPos.X,
                                                                    worldPos.Y), null, polygon, i - 1, i);
     }
 }
Exemple #11
0
 public static void LineStringSnapStart(ref ISnapResult snapResult, ILineString lineString)
 {
     snapResult = new SnapResult(lineString.Coordinates[0], null, lineString, 0, 0);
 }
Exemple #12
0
 public static void LineStringSnapEnd(ref ISnapResult snapResult, ILineString lineString)
 {
     snapResult = new SnapResult(lineString.Coordinates[lineString.Coordinates.Length - 1], null, lineString,
                                 lineString.Coordinates.Length - 1, lineString.Coordinates.Length - 1);
 }
Exemple #13
0
 public static void PointSnap(ref ISnapResult snapResult, IGeometry geometry)
 {
     snapResult = new SnapResult(geometry.Coordinates[0], null, geometry, 0, 0);
 }
Exemple #14
0
 public static void LineStringSnapEnd(ref ISnapResult snapResult, ILineString lineString)
 {
     snapResult = new SnapResult(lineString.Coordinates[lineString.Coordinates.Length - 1], null, lineString,
                           lineString.Coordinates.Length - 1, lineString.Coordinates.Length - 1);
 }
Exemple #15
0
 public static void PointSnap(ref ISnapResult snapResult, IGeometry geometry)
 {
     snapResult = new SnapResult(geometry.Coordinates[0], null, geometry, 0, 0);
 }
Exemple #16
0
 public static void LineStringSnapStart(ref ISnapResult snapResult, ILineString lineString)
 {
     snapResult = new SnapResult(lineString.Coordinates[0], null, lineString, 0, 0);
 }
Exemple #17
0
 public static void LineStringSnapFree(ref double minDistance, ref ISnapResult snapResult, ILineString lineString, ICoordinate worldPos)
 {
     for (int i = 1; i < lineString.Coordinates.Length; i++)
     {
         ICoordinate c1 = lineString.Coordinates[i - 1];
         ICoordinate c2 = lineString.Coordinates[i];
         double distance = GeometryHelper.LinePointDistance(c1.X, c1.Y, c2.X, c2.Y,
                                                            worldPos.X, worldPos.Y);
         if (distance >= minDistance) 
             continue;
         minDistance = distance;
         snapResult = new SnapResult(GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y), null, lineString, i - 1, i);
     }
 }
Exemple #18
0
        public override void OnMouseUp(ICoordinate worldPosition, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
                return;
            if (newLineGeometry.Count == 0)
            {
                return;
            }

            ISnapResult snapResult = MapControl.SnapTool.ExecuteLayerSnapRules(Layer, null, adding ? newLineGeometry[0] : null,
                                                            worldPosition,
                                                            adding ? newLineGeometry[0].Coordinates.Length - 1 : -1);
            IGeometry defaultGeometry = null;
            IFeatureEditor featureEditor = MapControl.SelectTool.GetFeatureEditor(Layer, null);
            if (null != featureEditor)
            {
                defaultGeometry = featureEditor.CreateDefaultGeometry(Layer, newLineGeometry[0],
                    (null != snapResult) ? snapResult.NearestTarget : null,
                    (null != snapResult) ? snapResult.Location : null);
                if (null != defaultGeometry)
                {
                    newLineGeometry.Clear();
                    newLineGeometry.Add(defaultGeometry);
                }
            }
            ILineString lineString = (ILineString)newLineGeometry[0];
            if (null == lineString)
            {
                isBusy = false;
                return;
            }
            if (ActualAutoCurve)
            {
                if (null == defaultGeometry)
                {
                    snapResult = Snap(worldPosition);
                    if (null == snapResult)
                    {
                        // hack if obligatory snapping failed mimic result. This is not valid for NewNodeTool
                        // Think of solution within snaprule
                        snapResult = new SnapResult(worldPosition, null, null, -1, -1);
                    }
                    if (TemporalEnd)
                        GeometryHelper.SetCoordinate(lineString, lineString.Coordinates.Length - 1, snapResult.Location);
                    else
                        lineString = AppendCurvePoint(lineString, snapResult.Location);
                    lineString = RemoveDuplicatePoints(lineString);
                }
                adding = false;
                newLineGeometry[0] = lineString;
                //Flush();
                SelectTool selectTool = MapControl.SelectTool;

                if (null != lineString && snapResult != null)
                {
                    // TODO: call editor here instead of feature provider
                    int count = FeatureProvider.GetFeatureCount();

                    try
                    {
                        FeatureProvider.Add(lineString); // will add Cross Section and call ConnectCrossSectionToBranch
                    }
                    catch (Exception exception)
                    {
                        // an exception during add operation can fail; for example when adding a branch feature
                        log.Warn(exception.Message);
                        adding = false;
                        StopDrawing();
                        newLineGeometry.Clear();
                        return;
                    }

                    // was adding succesfull?
                    if ((1 + count) == FeatureProvider.GetFeatureCount())
                    {
                        IFeature feature = FeatureProvider.GetFeature(count);
                        //Layer.RenderRequired = true;
                        MapControl.SelectTool.Select(Layer, feature, 0);
                    }
                }
                else
                {
                    // do not add a linestring with zero length
                    selectTool.Clear();
                }
                adding = false;
                StopDrawing();
                newLineGeometry.Clear();
            }
            Layer.RenderRequired = true;
            MapControl.Refresh();
            isBusy = false;
        }
Exemple #19
0
 /// <summary>
 /// Update snapping 
 /// </summary>
 /// <param name="sourceLayer"></param>
 /// The layer of feature. 
 /// <param name="feature"></param>
 /// Feature that is snapped. Feature is not always available. 
 /// <param name="geometry"></param>
 /// actual geometry of the feature that is snapped. 
 /// <param name="worldPosition"></param>
 /// <param name="trackerIndex"></param>
 public ISnapResult ExecuteLayerSnapRules(ILayer sourceLayer, IFeature feature, IGeometry geometry, 
                                         ICoordinate worldPosition, int trackerIndex)
 {
     IList<ISnapRule> snapRules = MapControl.GetSnapRules(sourceLayer, feature, geometry, trackerIndex);
     ISnapResult snapResult = null;
     for (int i = 0; i < snapRules.Count; i++)
     {
         ISnapRule rule = snapRules[i];
         snapResult = ExecuteSnapRule(rule, feature, geometry, null, worldPosition, trackerIndex);
         if (null != snapResult)
             break;
         // If snapping failed for the last rule and snapping is obligatory 
         // any position is valid
         // todo add rule with SnapRole.Free?
         if ((!rule.Obligatory) && (i == snapRules.Count - 1))
         {
             snapResult = new SnapResult(worldPosition, null, null, -1, -1);
         }
     }
     if (0 == snapRules.Count)
     {
         snapResult = new SnapResult(worldPosition, null, null, -1, -1);
     }
     return snapResult;
 }