1

I converted UTM coordinates (X/Y) (Datum ED50) to latitude/longitude but the result is not accurate.There is an error of at least 500 meters.

I used the library https://proj4net.codeplex.com/

I think the key is the Datum ED50

This is my code:

//Zone: 30N
public static string ConvertTolatlngString(double utmX, double utmY)
{

//Transform to latlong
CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();
ICoordinateSystem wgs84geo = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84;
ICoordinateSystem utm = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(30, true);
ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(utm,wgs84geo);
double[] pUtm = trans.MathTransform.Transform(new double[] { utmX, utmY });

double latfromutm = pUtm[1];
double longfromutm = pUtm[0];

return String.Format("{0},{1}", latfromutm,longfromutm);
}

UPDATED

I have also used DotSpatial (https://dotspatial.codeplex.com) but I get the same result:

public static void UTMToLatLongDSP(double X, double Y, out double latitude, out double longitude)
{
    double[] XY = new double[2];
    XY[0] = X;
    XY[1] = Y;

    double[] Z = new double[1];
    Z[0] = 1;

    string utmStr = "+proj=utm +zone=30 +ellps=WGS84 +datum=WGS84 +units=m +no_defs ";
    }

    ProjectionInfo projIn = ProjectionInfo.FromProj4String(utmStr);
    ProjectionInfo projOut = KnownCoordinateSystems.Geographic.World.WGS1984;
    Reproject.ReprojectPoints(XY, Z, projIn, projOut, 0, 1);

    longitude = XY[0];
    latitude = XY[1];
}

UPDATE 2 I specified the EPGS code but I don't get the expected result. This is my new code:

public static void UTMToLatLongDSP(double X, double Y, out double latitude, out double longitude)
{
    double[] xy = new double[] { X, Y };
    double[] z = new double[] { 0 };

    // Source projection information.
    ProjectionInfo source = KnownCoordinateSystems.Projected.UtmOther.EuropeanDatum1950UTMZone30N;
    source.GeographicInfo.Datum.Spheroid.KnownEllipsoid = Proj4Ellipsoid.International_1909;
    source.AuthorityCode = 23030;

    // Destination projection information
    ProjectionInfo dest = KnownCoordinateSystems.Geographic.World.WGS1984;
    dest.AuthorityCode = 4326;

    // Call the projection utility.
    Reproject.ReprojectPoints(xy, z, source, dest, 0, 1);

    longitude = xy[0];
    latitude = xy[1];
}
ratillo89
  • 53
  • 2
  • 10

2 Answers2

0

I think the key is the Datum ED50

And you are right. You are converting UTM coordinates with datum WGS84 to LatLong coordinates with datum WGS84. Since your UTM coordinates use the datum ED50 you must specify it instead of WGS84 for the original coordinates.

I'm not familiar with DotSpatial but a wild guess would be that you need to do something like this:

string utmStr = "+proj=utm +zone=30 +ellps=Hayford +datum=ED50 +units=m +no_defs ";

(Provided that Hayford is the proper ellipsoid and ED50 the used in DotSpatial for such datum.)

jnovo
  • 5,659
  • 2
  • 38
  • 56
  • 1
    I implemented your solution but it has not worked for me. This is my current code: ProjectionInfo source = KnownCoordinateSystems.Projected.UtmOther.EuropeanDatum1950UTMZone30N; source.GeographicInfo.Datum.Spheroid.KnownEllipsoid = Proj4Ellipsoid.International_1909; source.AuthorityCode = 23030; ProjectionInfo dest = KnownCoordinateSystems.Geographic.World.WGS1984; dest.AuthorityCode = 4326; Reproject.ReprojectPoints(xy, z, source, dest, 0, 1); Now, I specific the "authorityCode" (EPSG code) but I don't get the expected result. – ratillo89 Dec 18 '15 at 08:38
  • How much error are you getting? Are you positive the source ellipsoid is the correct one for your source UTM coordinates? Btw, it'd be easier to read and maybe others can help if you edit your post adding that new code. – jnovo Dec 18 '15 at 08:43
  • @ratillo89, try with international 1924 (Hayford) – jnovo Dec 18 '15 at 08:51
  • Thanks! I edited my post. I get an error of 200m or more. I don't know my source ellipsoid but if I enter my source coordinates in this page http://www.sumapa.com/geocalc/geocalc.cfm works fine. – ratillo89 Dec 18 '15 at 08:56
  • Proj4Ellipsoid.International_1924 seems that don't exists in DosSpatial – ratillo89 Dec 18 '15 at 09:07
  • @ratillo89 did you find a solution to your issue because I have the same problem. – Kellie Dec 23 '20 at 00:28
0

For those of you wondering how to reproject to different coordinate systems using DotSpatial via a shape file, this is how I do it.

You'll need these dependencies though via nuget.

  • DotSpatial.Data (v2.0.0-rc1)
  • DotSpatial.GeoAPI (v1.7.4.3)
  • DotSpatial.NetTopologySuite (v1.14.4)

    // open the shape file into a feature set
    var fs = FeatureSet.Open("someshapefile.shp");
    
    // fill the attributes table including related data from the dbf file 
    // this is not required but if you plan to access the data within the .dbf then you'll need to
    fs.FillAttributes();
    
    // check if the projection is not lat/lng
    // this assumes that the shapefile has a .prj file with projection info that it can parse
    if (!fs.Projection.IsLatLon)
    {
        // reproject to the coordinate system of your choice
        fs.Reproject(KnownCoordinateSystems.Geographic.World.WGS1984);
    }
    

I assume this will work from any projection to any projection but I haven't tested others.