public override void Stop(SnapResult snapResult)
        {
            var networkLocation = (INetworkLocation)SourceFeature;

            if (null == networkLocation)
            {
                return;
            }

            var branch = snapResult.SnappedFeature as IBranch;

            if (null == branch)
            {
                return;
            }

            var network = Network ?? branch.Network; // network must e known

            if (network == null)
            {
                return;
            }

            if (networkLocation.Branch != branch)
            {
                networkLocation.Branch = branch;
            }
            // todo move update distance to AddBranchFeatureToNearestBranch?
            var distanceInGeometryLength    = GeometryHelper.Distance((ILineString)networkLocation.Branch.Geometry, TargetFeature.Geometry.Coordinates[0]);
            var distanceInCalculationLength = NetworkHelper.CalculationChainage(branch, distanceInGeometryLength);

            networkLocation.Chainage = BranchFeature.SnapChainage(networkLocation.Branch.Length, distanceInCalculationLength);
        }
Esempio n. 2
0
        private static INetworkLocation MapPointToClosestBranch(IPoint point, IEnumerable <IBranch> branches,
                                                                double tolerance)
        {
            IBranch targetBranch  = null;
            var     pointEnvelope = point.EnvelopeInternal;

            pointEnvelope.ExpandBy(tolerance);

            // this is cheaper than multiple calls to Distance(..) below
            var overlappingBranches = branches.Where(b => b.Geometry.EnvelopeInternal.Intersects(pointEnvelope));

            double distance = tolerance;

            foreach (var branch in overlappingBranches)
            {
                var d = branch.Geometry.Distance(point);
                if (!(d < distance))
                {
                    continue;
                }

                targetBranch = branch;
                distance     = d;
            }

            if (targetBranch == null)
            {
                return(null);
            }

            var line = targetBranch.Geometry as ILineString;

            if (line == null)
            {
                return(null);
            }

            var coordinate = GeometryHelper.GetNearestPointAtLine(line, point.Coordinate, tolerance);
            var chainage   = NetworkHelper.CalculationChainage(targetBranch,
                                                               GeometryHelper.Distance(
                                                                   (ILineString)targetBranch.Geometry, coordinate));

            return(new NetworkLocation(targetBranch, chainage));
        }