private bool IsCrsAllowed(EpsgCrs crs) {
            Contract.Requires(crs != null);
            if (CrsFilters == null || CrsFilters.Count == 0)
                return true;

            return CrsFilters.All(f => f(crs));
        }
            public static List <CrsOperationRelation> BuildTargetSearchList(EpsgCrs target)
            {
                Contract.Requires(target != null);
                Contract.Ensures(Contract.Result <List <CrsOperationRelation> >() != null);
                Contract.Ensures(Contract.ForAll(Contract.Result <List <CrsOperationRelation> >(), x => x != null));
                var cost    = 0;
                var current = target;
                var path    = new CoordinateOperationCrsPathInfo(target);
                var result  = new List <CrsOperationRelation> {
                    new CrsOperationRelation {
                        Cost = cost, RelatedCrs = current, Path = path
                    }
                };

                while (current is EpsgCrsProjected)
                {
                    var projected  = current as EpsgCrsProjected;
                    var projection = projected.GetBaseOperation();
                    if (null == projection)
                    {
                        break;
                    }

                    cost++;
                    current = projected.BaseCrs;
                    path    = path.Prepend(current, projected.GetBaseOperation());
                    result.Add(new CrsOperationRelation {
                        Cost = cost, RelatedCrs = current, Path = path
                    });
                }
                Contract.Assume(Contract.ForAll(result, x => x != null));
                return(result);
            }
 public PathNode Append(EpsgCrs crs, ICoordinateOperationInfo edgeFromParent) {
     Contract.Requires(edgeFromParent != null);
     Contract.Ensures(Contract.Result<PathNode>() != null);
     var newNode = new PathNode(crs) {
         Parent = this,
         EdgeFromParent = edgeFromParent
     };
     return newNode;
 }
 public override bool IsValid(EpsgCrs crs)
 {
     if (crs == null)
     {
         throw new ArgumentNullException("crs");
     }
     Contract.EndContractBlock();
     return(base.IsValid(crs) && _predicate(crs));
 }
 public bool AreaIntersectionTest(EpsgCrs crs) {
     Contract.Requires(crs != null);
     var area = crs.Area;
     return area == null
         || SourceArea == null
         || SourceArea.Intersects(area)
         || TargetArea == null
         || TargetArea.Intersects(area);
 }
 public bool AreaContainsTest(EpsgCrs crs) {
     Contract.Requires(crs != null);
     var area = crs.Area;
     return area == null
         || SourceArea == null
         || area.Contains(SourceArea)
         || TargetArea == null
         || area.Contains(TargetArea);
 }
示例#7
0
 public EpsgCrsPathSearchNode(EpsgCrs crs, ICoordinateOperationInfo edgeFromParent, EpsgCrsPathSearchNode parent)
 {
     Contract.Requires(crs != null);
     Contract.Requires(edgeFromParent != null);
     Contract.Requires(parent != null);
     Crs            = crs;
     EdgeFromParent = edgeFromParent;
     Parent         = parent;
 }
 public virtual bool IsValid(EpsgCrs crs)
 {
     if (crs == null)
     {
         throw new ArgumentNullException("crs");
     }
     Contract.EndContractBlock();
     return(IsValid(crs.Area));
 }
 public bool AreaIntersectionTest(EpsgCrs crs)
 {
     Contract.Requires(crs != null);
     var area = crs.Area;
     return area == null
         || SourceArea == null
         || SourceArea.Intersects(area)
         || TargetArea == null
         || TargetArea.Intersects(area);
 }
 public bool AreaContainsTest(EpsgCrs crs)
 {
     Contract.Requires(crs != null);
     var area = crs.Area;
     return area == null
         || SourceArea == null
         || area.Contains(SourceArea)
         || TargetArea == null
         || area.Contains(TargetArea);
 }
 public EpsgCrsGraphSearcherOld(EpsgCrs sourceCrs, EpsgCrs targetCrs) {
     if (sourceCrs == null) throw new ArgumentNullException("sourceCrs");
     if (targetCrs == null) throw new ArgumentNullException("targetCrs");
     Contract.EndContractBlock();
     SourceCrs = sourceCrs;
     SourceCrsCode = sourceCrs.Code;
     SourceArea = sourceCrs.Area;
     TargetCrs = targetCrs;
     TargetCrsCode = targetCrs.Code;
     TargetArea = targetCrs.Area;
 }
 public EpsgCrsGraphSearcherOld(EpsgCrs sourceCrs, EpsgCrs targetCrs)
 {
     if (sourceCrs == null) throw new ArgumentNullException("sourceCrs");
     if (targetCrs == null) throw new ArgumentNullException("targetCrs");
     Contract.EndContractBlock();
     SourceCrs = sourceCrs;
     SourceCrsCode = sourceCrs.Code;
     SourceArea = sourceCrs.Area;
     TargetCrs = targetCrs;
     TargetCrsCode = targetCrs.Code;
     TargetArea = targetCrs.Area;
 }
 private PathNode(EpsgCrs crs) {
     Contract.Requires(crs != null);
     Crs = crs;
 }
示例#14
0
 private static bool IsNotDeprecated(EpsgCrs crs)
 {
     return !crs.Deprecated;
 }
 public static PathNode CreateStartNode(EpsgCrs crs)
 {
     Contract.Requires(crs != null);
     Contract.Ensures(Contract.Result<PathNode>() != null);
     return new PathNode(crs);
 }
 private PathNode(EpsgCrs crs)
 {
     Contract.Requires(crs != null);
     Crs = crs;
 }
 public PathNode Append(EpsgCrs crs, ICoordinateOperationInfo edgeFromParent)
 {
     Contract.Requires(edgeFromParent != null);
     Contract.Ensures(Contract.Result<PathNode>() != null);
     var newNode = new PathNode(crs) {
         Parent = this,
         EdgeFromParent = edgeFromParent
     };
     return newNode;
 }
 public static PathNode CreateStartNode(EpsgCrs crs) {
     Contract.Requires(crs != null);
     Contract.Ensures(Contract.Result<PathNode>() != null);
     return new PathNode(crs);
 }
        public ICoordinateOperationCrsPathInfo Generate(EpsgCrs from, EpsgCrs to)
        {
            if (from == null || to == null)
            {
                return(null);
            }
            // see if there is a direct path above the source
            var sourceList = CrsOperationRelation.BuildSourceSearchList(from);

            foreach (var source in sourceList)
            {
                if (source.RelatedCrs == to)
                {
                    return(source.Path);
                }
            }

            // see if there is a direct path above the target
            var targetList = CrsOperationRelation.BuildTargetSearchList(to);

            foreach (var target in targetList)
            {
                if (target.RelatedCrs == from)
                {
                    return(target.Path);
                }
            }

            // try to find the best path from any source to any target
            var graph      = new EpsgTransformGraph(from.Area, to.Area, Options);
            var results    = new List <CrsPathResult>();
            var lowestCost = Int32.MaxValue;

            foreach (var source in sourceList)
            {
                foreach (var target in targetList)
                {
                    var pathCost = source.Cost + target.Cost;
                    if (pathCost >= lowestCost)
                    {
                        continue;
                    }

                    if (source.RelatedCrs == target.RelatedCrs)
                    {
                        results.Add(new CrsPathResult {
                            Cost = pathCost,
                            Path = source.Path.Append(target.Path)
                        });
                        if (pathCost < lowestCost)
                        {
                            lowestCost = pathCost;
                        }

                        continue;
                    }

                    if ((pathCost + 1) >= lowestCost)
                    {
                        continue;
                    }

                    var path = graph.FindPath(source.RelatedCrs, target.RelatedCrs);
                    if (null == path)
                    {
                        continue; // no path found
                    }
                    var pathOperations = source.Path;
                    for (int partIndex = 1; partIndex < path.Count; partIndex++)
                    {
                        var part = path[partIndex];
                        pathCost      += part.Cost;
                        pathOperations = pathOperations.Append(part.Node, part.Edge);
                    }
                    pathOperations = pathOperations.Append(target.Path);

                    results.Add(new CrsPathResult {
                        Cost = pathCost,
                        Path = pathOperations //source.Path.Append(pathOperations).Append(target.Path)
                    });

                    if (pathCost < lowestCost)
                    {
                        lowestCost = pathCost;
                    }
                }
            }

            // find the smallest result;
            ICoordinateOperationCrsPathInfo bestResult = null;

            lowestCost = Int32.MaxValue;
            foreach (var result in results)
            {
                if (result.Cost < lowestCost)
                {
                    lowestCost = result.Cost;
                    bestResult = result.Path;
                }
            }
            return(bestResult);
        }
        private bool IsCrsAllowed(EpsgCrs crs)
        {
            Contract.Requires(crs != null);
            if (CrsFilters == null || CrsFilters.Count == 0)
                return true;

            return CrsFilters.All(f => f(crs));
        }
示例#21
0
 public EpsgCrsPathSearchNode(EpsgCrs crs)
 {
     Contract.Requires(crs != null);
     Crs = crs;
 }