private StepCompilationResult CompileStep(StepCompilationParameters stepParams) { Contract.Requires(stepParams != null); var operations = ConcatenatedCoordinateOperationInfo.LinearizeOperations(stepParams.CoordinateOperationInfo).ToArray(); if (operations.Length == 0) { return(null); } var currentUnit = stepParams.InputUnit; var partResults = new StepCompilationResult[operations.Length]; for (int operationIndex = 0; operationIndex < operations.Length; operationIndex++) { Contract.Assume(operations[operationIndex] != null); var partResult = CompilePart(new StepCompilationParameters( operations[operationIndex], currentUnit, stepParams.RelatedInputCrs, stepParams.RelatedOutputCrs )); if (null == partResult) { return(null); // not supported } partResults[operationIndex] = partResult; currentUnit = partResult.OutputUnit; } ITransformation transformation = partResults.Length == 1 ? partResults[0].Transformation : new ConcatenatedTransformation(Array.ConvertAll(partResults, x => x.Transformation)); return(new StepCompilationResult( stepParams, currentUnit, transformation)); }
private StepCompilationResult CompileStep(StepCompilationParameters stepParams) { Contract.Requires(stepParams != null); var operations = ConcatenatedCoordinateOperationInfo.LinearizeOperations(stepParams.CoordinateOperationInfo).ToArray(); if (operations.Length == 0) return null; var currentUnit = stepParams.InputUnit; var partResults = new StepCompilationResult[operations.Length]; for (int operationIndex = 0; operationIndex < operations.Length; operationIndex++) { Contract.Assume(operations[operationIndex] != null); var partResult = CompilePart(new StepCompilationParameters( operations[operationIndex], currentUnit, stepParams.RelatedInputCrs, stepParams.RelatedOutputCrs )); if (null == partResult) return null; // not supported partResults[operationIndex] = partResult; currentUnit = partResult.OutputUnit; } ITransformation transformation = partResults.Length == 1 ? partResults[0].Transformation : new ConcatenatedTransformation(Array.ConvertAll(partResults, x => x.Transformation)); return new StepCompilationResult( stepParams, currentUnit, transformation); }
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); }