/// <summary> /// Use this method to calculate transformation parameters for giver extent. All points will be transformed using calculated parameters. /// </summary> /// <param name="inputExtent">Extent for which to calculate parameters</param> /// <param name="inputProjection">input projection</param> /// <param name="outputProjection">output projection</param> /// <returns>transformation parameters</returns> public double[] CalculateAffineTransformationParameters(GeoExtent inputExtent, enumProjection inputProjection = enumProjection.BGS_1970_K9, enumProjection outputProjection = enumProjection.BGS_2005_KK) { if (inputProjection == enumProjection.BGS_SOFIA) { inputExtent.NorthEastCorner.X += this.projections[inputProjection].X0; inputExtent.NorthEastCorner.Y += this.projections[inputProjection].Y0; inputExtent.SouthWestCorner.X += this.projections[inputProjection].X0; inputExtent.SouthWestCorner.Y += this.projections[inputProjection].Y0; } ControlPointsClass inputControlPoints = inputProjection == enumProjection.BGS_SOFIA ? this.controlPoints[enumProjection.BGS_1950_3_24] : this.controlPoints[inputProjection]; ControlPointsClass outputControlPoints = outputProjection == enumProjection.BGS_SOFIA ? this.controlPoints[enumProjection.BGS_1950_3_24] : this.controlPoints[outputProjection]; List <GeoPoint> inputGeoPoints = inputControlPoints.GetPoints(inputExtent); List <GeoPoint> outputGeoPoints = outputControlPoints.GetPoints(inputGeoPoints.Select(p => p.ID).ToArray()); AffineTransformation transformation = new AffineTransformation(inputGeoPoints, outputGeoPoints); return(transformation.GetParameters()); }
/// <summary> /// Transforms from BGS 1930, BGS1950, BGS Sofia, BGS 1970 or BGS 2005 projected coordinates to the specified projection. /// Transforms a point by calculating local transformation parameters. Transformation parameters are calculated using predefiend /// control points. Control points are searched within 20 000m around the input point. If the point is close to the border of /// the projection an exception will be thrown. /// </summary> /// <param name="inputPoint">input projected coordinates in BGS 1930, BGS1950, BGS 1970 or BGS 2005</param> /// <param name="inputProjection">input coordinates projection</param> /// <param name="outputProjection">output projection</param> /// <param name="useTPS">use TPS or Affine transformations</param> /// <returns>coordinates in specified projection</returns> public GeoPoint TransformBGSCoordinates(GeoPoint inputPoint, enumProjection inputProjection = enumProjection.BGS_1970_K9, enumProjection outputProjection = enumProjection.BGS_2005_KK, bool useTPS = true) { double distance = 20000; if (inputProjection == enumProjection.BGS_SOFIA) { inputPoint.X += this.projections[inputProjection].X0; inputPoint.Y += this.projections[inputProjection].Y0; } ControlPointsClass inputControlPoints = inputProjection == enumProjection.BGS_SOFIA ? this.controlPoints[enumProjection.BGS_1950_3_24] : this.controlPoints[inputProjection]; ControlPointsClass outputControlPoints = outputProjection == enumProjection.BGS_SOFIA ? this.controlPoints[enumProjection.BGS_1950_3_24] : this.controlPoints[outputProjection]; List <GeoPoint> inputGeoPoints = inputControlPoints.GetPoints(inputPoint, distance); List <GeoPoint> outputGeoPoints = outputControlPoints.GetPoints(inputGeoPoints.Select(p => p.ID).ToArray()); #region transform using Affine or TPS transformation ITransformation transformation; if (useTPS) { transformation = new TPSTransformation(inputGeoPoints, outputGeoPoints); } else { transformation = new AffineTransformation(inputGeoPoints, outputGeoPoints); } GeoPoint resultPoint = transformation.Transform(inputPoint); #endregion if (outputProjection == enumProjection.BGS_SOFIA) { resultPoint.X -= this.projections[outputProjection].X0; resultPoint.Y -= this.projections[outputProjection].Y0; } return(resultPoint); }