Transform Coordinate from One Coordinate System to Other Coordinate System

Transform coordinate from one coordinate system to other coordinate system

Download ProjNet dll and add reference in our .net application.

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using ProjNet.Converters.WellKnownText;  
  6. using ProjNet.CoordinateSystems;  
  7. using ProjNet.CoordinateSystems.Transformations;  
  8. namespace Transform32640To4326  
  9. {  
  10.     public class CoordinateTransformZC  
  11.     {  
  12.         public double[] TransForm(double[] inputCoordinate)  
  13.         {  
  14.             double[] output = null;  
  15.             try  
  16.             {  
  17.                 string wkt_WGS84N40 = "PROJCS[\"WGS_1984_UTM_Zone_40N\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",500000.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",57.0],PARAMETER[\"Scale_Factor\",0.9996],PARAMETER[\"Latitude_Of_Origin\",0.0],UNIT[\"Meter\",1.0]]";  
  18.                 IProjectedCoordinateSystem gcs_WGS84 = CoordinateSystemWktReader.Parse(wkt_WGS84N40) asIProjectedCoordinateSystem;  
  19.                 //Destination  
  20.                 string wkt_WgsGeo = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]";  
  21.                 IGeographicCoordinateSystem geo = CoordinateSystemWktReader.Parse(wkt_WgsGeo) asIGeographicCoordinateSystem;  
  22.                 CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();  
  23.                 ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(gcs_WGS84, geo);  
  24.                 //Console.WriteLine("Original Coordinates:");  
  25.                 double[] fromPoint = inputCoordinate; // U2U Consult Head Office, in degrees  
  26.                 output = trans.MathTransform.Transform(fromPoint);  
  27.             }  
  28.             catch (Exception ex)  
  29.             {  
  30.                 output = null;  
  31.             }  
  32.             return output;  
  33.         }  
  34.     }  
  35. }