/// <summary> /// Computes the result. /// </summary> protected override void ComputeResult() { if (Source.ReferenceSystem != null && _targetReferenceSystem != null && !Source.ReferenceSystem.Equals(_targetReferenceSystem)) { // strategy pattern _transformation = TransformationStrategyFactory.CreateStrategy(Source.ReferenceSystem as ReferenceSystem, _targetReferenceSystem as ReferenceSystem); } if (_factory == null) { _factory = (IGeometryFactory)FactoryRegistry.GetFactory(FactoryRegistry.GetContract(Source.Factory), _targetReferenceSystem); } _intermediateResult = Compute(Source); }
/// <summary> /// Initializes a new instance of the <see cref="CompoundTransformationStrategy" /> class. /// </summary> /// <param name="conversionToGeographic">The conversion to geographic coordinate.</param> /// <param name="geographicTransformation">The geographic transformation.</param> /// <param name="conversionFromGeographic">The conversion from geographic coordinate.</param> public CompoundTransformationStrategy(ITransformationStrategy <Coordinate, GeoCoordinate> conversionToGeographic, ITransformationStrategy <GeoCoordinate, GeoCoordinate> geographicTransformation, ITransformationStrategy <GeoCoordinate, Coordinate> conversionFromGeographic) { _conversionFromGeographic = conversionFromGeographic; _geographicTransformation = geographicTransformation; _conversionToGeographic = conversionToGeographic; }
/// <summary> /// Creates a transformation strategy between reference systems. /// </summary> /// <param name="source">The source.</param> /// <param name="target">The target.</param> /// <returns>The produced transformation strategy.</returns> /// <exception cref="System.NotSupportedException">Conversion is not supported between the specified coordinate reference systems.</exception> public static ITransformationStrategy CreateStrategy(ReferenceSystem source, ReferenceSystem target) { ITransformationStrategy <Coordinate, GeoCoordinate> conversionToGeographic = null; ITransformationStrategy <GeoCoordinate, GeoCoordinate> transformation = null; ITransformationStrategy <GeoCoordinate, Coordinate> conversionFromGeographic = null; switch (source.Type) { case ReferenceSystemType.Projected: conversionToGeographic = new ReverseProjectionStrategy(source as ProjectedCoordinateReferenceSystem); break; case ReferenceSystemType.Geographic2D: case ReferenceSystemType.Geographic3D: conversionToGeographic = CreateReverseConversion(source as CoordinateReferenceSystem); break; } switch (target.Type) { case ReferenceSystemType.Projected: conversionFromGeographic = new ForwardProjectionStrategy(target as ProjectedCoordinateReferenceSystem); break; case ReferenceSystemType.Geographic2D: case ReferenceSystemType.Geographic3D: conversionFromGeographic = CreateForwardConversion(target as CoordinateReferenceSystem); break; } // if no transformation is needed if (conversionFromGeographic.TargetReferenceSystem.Equals(conversionToGeographic.SourceReferenceSystem)) { return(new ConversionStrategy(conversionToGeographic, conversionFromGeographic)); } // load matching forward transformation IList <GeographicTransformation> transformations = GeographicTransformations.FromReferenceSystems(conversionToGeographic.TargetReferenceSystem as GeographicCoordinateReferenceSystem, conversionFromGeographic.SourceReferenceSystem as GeographicCoordinateReferenceSystem); if (transformations.Count > 0) { transformation = new ForwardGeographicStrategy(conversionToGeographic.TargetReferenceSystem as GeographicCoordinateReferenceSystem, conversionFromGeographic.SourceReferenceSystem as GeographicCoordinateReferenceSystem, transformations[0]); return(new CompoundTransformationStrategy(conversionToGeographic, transformation, conversionFromGeographic)); } // if none found, load matching reverse transformation transformations = GeographicTransformations.FromReferenceSystems(conversionFromGeographic.SourceReferenceSystem as GeographicCoordinateReferenceSystem, conversionToGeographic.TargetReferenceSystem as GeographicCoordinateReferenceSystem); if (transformations.Count > 0) { transformation = new ReverseGeographicStrategy(conversionToGeographic.TargetReferenceSystem as GeographicCoordinateReferenceSystem, conversionFromGeographic.SourceReferenceSystem as GeographicCoordinateReferenceSystem, transformations[0]); return(new CompoundTransformationStrategy(conversionToGeographic, transformation, conversionFromGeographic)); } throw new NotSupportedException("Conversion is not supported between the specified coordinate reference systems."); }