private static double?GetEpsgAccuracy(ICoordinateOperationCrsPathInfo path) { double sum = 0; bool hasSumValue = false; foreach (var op in path.CoordinateOperations) { EpsgCoordinateOperationInfoBase epsgOp; var epsgInverse = op as EpsgCoordinateOperationInverse; if (epsgInverse != null) { epsgOp = epsgInverse.Core; } else { epsgOp = op as EpsgCoordinateOperationInfoBase; if (epsgOp == null) { continue; } } var tx = epsgOp as EpsgCoordinateTransformInfo; if (tx != null) { var accuracy = tx.Accuracy; if (accuracy.HasValue && !Double.IsNaN(accuracy.GetValueOrDefault())) { hasSumValue = true; sum += accuracy.GetValueOrDefault(); } } } return(hasSumValue ? sum : (double?)null); }
private static double? GetEpsgAccuracy(ICoordinateOperationCrsPathInfo path) { double sum = 0; bool hasSumValue = false; foreach (var op in path.CoordinateOperations) { EpsgCoordinateOperationInfoBase epsgOp; var epsgInverse = op as EpsgCoordinateOperationInverse; if (epsgInverse != null) { epsgOp = epsgInverse.Core; } else { epsgOp = op as EpsgCoordinateOperationInfoBase; if (epsgOp == null) continue; } var tx = epsgOp as EpsgCoordinateTransformInfo; if (tx != null) { var accuracy = tx.Accuracy; if (accuracy.HasValue && !Double.IsNaN(accuracy.GetValueOrDefault())) { hasSumValue = true; sum += accuracy.GetValueOrDefault(); } } } return hasSumValue ? sum : (double?)null; }
public ITransformation Compile(ICoordinateOperationCrsPathInfo operationPath) { if (operationPath == null) { throw new ArgumentNullException("operationPath"); } Contract.EndContractBlock(); var allOps = operationPath.CoordinateOperations.ToList(); var allCrs = operationPath.CoordinateReferenceSystems.ToList(); if (allCrs.Count <= 1) { return(null); // operationPath must have at least 2 CRSs } Contract.Assume(allOps.Count + 1 == allCrs.Count); var firstCrs = allCrs[0]; var lastCrs = allCrs[allCrs.Count - 1]; var stepResults = new StepCompilationResult[allOps.Count]; var currentUnit = ExtractUnit(firstCrs); if (currentUnit == null) { throw new ArgumentException("Could not extract a unit from the first CRS in the operation path", "operationPath"); } for (int operationIndex = 0; operationIndex < stepResults.Length; operationIndex++) { Contract.Assume(allOps[operationIndex] != null); var stepResult = CompileStep(new StepCompilationParameters( allOps[operationIndex], currentUnit, allCrs[operationIndex], allCrs[operationIndex + 1] )); if (null == stepResult) { return(null); // not supported } stepResults[operationIndex] = stepResult; currentUnit = stepResult.OutputUnit; } // make sure that the output units are correct var lastUnit = ExtractUnit(lastCrs); if (lastUnit == null) { throw new ArgumentException("Could not extract a unit from the last CRS in the operation path", "operationPath"); } var outputUnitConversion = CreateCoordinateUnitConversion(currentUnit, lastUnit); var resultTransformations = stepResults.Select(x => x.Transformation).ToList(); if (null != outputUnitConversion) { resultTransformations.Add(outputUnitConversion); } resultTransformations = Linearize(resultTransformations).ToList(); if (resultTransformations.Count == 0) { return(null); } if (resultTransformations.Count == 1) { return(resultTransformations[0]); } return(new ConcatenatedTransformation(resultTransformations)); }
public ITransformation Compile(ICoordinateOperationCrsPathInfo operationPath) { if (operationPath == null) throw new ArgumentNullException("operationPath"); Contract.EndContractBlock(); var allOps = operationPath.CoordinateOperations.ToList(); var allCrs = operationPath.CoordinateReferenceSystems.ToList(); if (allCrs.Count <= 1) return null; // operationPath must have at least 2 CRSs Contract.Assume(allOps.Count + 1 == allCrs.Count); var firstCrs = allCrs[0]; var lastCrs = allCrs[allCrs.Count - 1]; var stepResults = new StepCompilationResult[allOps.Count]; var currentUnit = ExtractUnit(firstCrs); if(currentUnit == null) throw new ArgumentException("Could not extract a unit from the first CRS in the operation path", "operationPath"); for (int operationIndex = 0; operationIndex < stepResults.Length; operationIndex++) { Contract.Assume(allOps[operationIndex] != null); var stepResult = CompileStep(new StepCompilationParameters( allOps[operationIndex], currentUnit, allCrs[operationIndex], allCrs[operationIndex + 1] )); if (null == stepResult) return null; // not supported stepResults[operationIndex] = stepResult; currentUnit = stepResult.OutputUnit; } // make sure that the output units are correct var lastUnit = ExtractUnit(lastCrs); if (lastUnit == null) throw new ArgumentException("Could not extract a unit from the last CRS in the operation path", "operationPath"); var outputUnitConversion = CreateCoordinateUnitConversion(currentUnit, lastUnit); var resultTransformations = stepResults.Select(x => x.Transformation).ToList(); if (null != outputUnitConversion) resultTransformations.Add(outputUnitConversion); resultTransformations = Linearize(resultTransformations).ToList(); if (resultTransformations.Count == 0) return null; if (resultTransformations.Count == 1) return resultTransformations[0]; return new ConcatenatedTransformation(resultTransformations); }
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); }