Transform coordinate from one coordinate system to other coordinate system
Download ProjNet dll and add reference in our .net application.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using ProjNet.Converters.WellKnownText;
- using ProjNet.CoordinateSystems;
- using ProjNet.CoordinateSystems.Transformations;
- namespace Transform32640To4326
- {
- public class CoordinateTransformZC
- {
- public double[] TransForm(double[] inputCoordinate)
- {
- double[] output = null;
- try
- {
- 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]]";
- IProjectedCoordinateSystem gcs_WGS84 = CoordinateSystemWktReader.Parse(wkt_WGS84N40) asIProjectedCoordinateSystem;
-
- 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]]";
- IGeographicCoordinateSystem geo = CoordinateSystemWktReader.Parse(wkt_WgsGeo) asIGeographicCoordinateSystem;
- CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();
- ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(gcs_WGS84, geo);
-
- double[] fromPoint = inputCoordinate;
- output = trans.MathTransform.Transform(fromPoint);
- }
- catch (Exception ex)
- {
- output = null;
- }
- return output;
- }
- }
- }