public ProjectionTransform(ISpatialReference srcSpatialRef, ISpatialReference dstSpatialRef) { if (srcSpatialRef == null) { throw new ArgumentNullException("源空间参考对象为空。"); } if (dstSpatialRef == null) { throw new ArgumentNullException("目标空间参考对象为空。"); } _srcProjection = new Proj4Projection(srcSpatialRef.ToProj4String()); _dstProjection = new Proj4Projection(dstSpatialRef.ToProj4String()); _srcProjection._coordinateDomain = srcSpatialRef.CoordinateDomain; _dstProjection._coordinateDomain = dstSpatialRef.CoordinateDomain; }
private void DoTransform(Proj4Projection srcPrj, Proj4Projection desPrj, ShapePoint[] points) { double[] xs = new double[points.Length]; double[] ys = new double[points.Length]; for (int i = 0; i < points.Length; i++) { xs[i] = points[i].X; ys[i] = points[i].Y; } Proj4Projection.Transform(srcPrj, desPrj, xs, ys); // for (int i = 0; i < points.Length; i++) { points[i].X = xs[i]; points[i].Y = ys[i]; } }
public void InverTransform(double[] xs, double[] ys) { Proj4Projection.Transform(_dstProjection, _srcProjection, xs, ys); }
/// <summary> /// Instance version checks initialization status. /// </summary> private void CheckInitialized() { Proj4Projection.CheckInitialized(this); }
public static void Transform(Proj4Projection src, Proj4Projection dst, double[] x, double[] y, double[] z) { lock (lockObj) { //Proj4Projection.CheckInitialized(src); //Proj4Projection.CheckInitialized(dst); if (x == null) { throw new ArgumentException("Argument is required", "x"); } if (y == null) { throw new ArgumentException("Argument is required", "y"); } if (x.Length != y.Length || (z != null && z.Length != x.Length)) { throw new ArgumentException("Coordinate arrays must have the same length"); } if (src.IsLatLong) { CoordinateDomain cd = dst._coordinateDomain; if (cd == null) { for (int i = 0; i < x.Length; i++) { x[i] *= Proj.DEG_TO_RAD; y[i] *= Proj.DEG_TO_RAD; } } else { for (int i = 0; i < x.Length; i++) { cd.CorrectX(ref x[i]); cd.CorrectY(ref y[i]); // x[i] *= Proj.DEG_TO_RAD; y[i] *= Proj.DEG_TO_RAD; } } } int result = Proj.pj_transform(src.prj, dst.prj, x.Length, 1, x, y, z); if (result != 0) { string message = "Tranformation Error"; int errno = GetErrNo(); if (errno != 0) { message = Proj4Projection.GetErrorMessage(errno); } throw new ApplicationException(message); } if (dst.IsLatLong) { for (int i = 0; i < x.Length; i++) { x[i] *= Proj.RAD_TO_DEG; y[i] *= Proj.RAD_TO_DEG; } } } }
/// <summary> /// Transform coordinates from one projection system to another /// </summary> /// <param name="src">The source projection</param> /// <param name="dst">The destination projection</param> /// <param name="x">The "X" coordinate values.</param> /// <param name="y">The "Y" coordinate values.</param> /// <exception cref="System.ApplicationException">Thrown when the projection is /// not initialized or the transformation failed. The message will indicate the error. /// </exception> /// <exception cref="System.ArgumentException"> /// May be thrown for any of the following reasons: /// <list type="bullet"> /// <item>The "x" array is null</item> /// <item>The "y" array is null</item> /// <item>The length of the x and y arrays don't match</item> /// </list> /// </exception> public static void Transform(Proj4Projection src, Proj4Projection dst, double[] x, double[] y) { Proj4Projection.Transform(src, dst, x, y, null); }
/// <summary> /// Transform coordinates from one projection system to another /// </summary> /// <param name="dst">The destination projection</param> /// <param name="x">The "X" coordinate values.</param> /// <param name="y">The "Y" coordinate values.</param> /// <param name="z">The "Z" coordinate values.</param> /// <exception cref="System.ApplicationException">Thrown when the projection is /// not initialized or the transformation failed. The message will indicate the error. /// </exception> /// <exception cref="System.ArgumentException"> /// May be thrown for any of the following reasons: /// <list type="bullet"> /// <item>The "x" array is null</item> /// <item>The "y" array is null</item> /// <item>The length of the x, y and z (if not null) arrays don't match</item> /// </list> /// </exception> public void Transform(Proj4Projection dst, double[] x, double[] y, double[] z) { Proj4Projection.Transform(this, dst, x, y, z); }
/// <summary> /// Transform coordinates from one projection system to another /// </summary> /// <param name="dst">The destination projection</param> /// <param name="x">The "X" coordinate values.</param> /// <param name="y">The "Y" coordinate values.</param> /// <exception cref="System.ApplicationException">Thrown when the projection is /// not initialized or the transformation failed. The message will indicate the error. /// </exception> /// <exception cref="System.ArgumentException"> /// May be thrown for any of the following reasons: /// <list type="bullet"> /// <item>The "x" array is null</item> /// <item>The "y" array is null</item> /// <item>The length of the x and y arrays don't match</item> /// </list> /// </exception> public void Transform(Proj4Projection dst, double[] x, double[] y) { this.Transform(dst, x, y, null); }