I am trying to convert a EPSG:4326 Lat Long into a EPSG:3857 reference. I have looked all around and have found slight differences in WKTs but nothing with different values.

The following code provides me with an accurate X coordinate according to here.

    Dim EPSG3857 As String = "PROJCS[""WGS 84 / Pseudo-Mercator"",GEOGCS[""WGS 84"",DATUM[""WGS_1984"",SPHEROID[""WGS 84"",6378137,298.257223563,AUTHORITY[""EPSG"",""7030""]],AUTHORITY[""EPSG"",""6326""]],PRIMEM[""Greenwich"",0,AUTHORITY[""EPSG"",""8901""]],UNIT[""degree"",0.0174532925199433,AUTHORITY[""EPSG"",""9122""]],AUTHORITY[""EPSG"",""4326""]],PROJECTION[""Mercator_1SP""],PARAMETER[""Latitude_of_origin"", 0],PARAMETER[""central_meridian"",0],PARAMETER[""scale_factor"",1],PARAMETER[""false_easting"",0],PARAMETER[""false_northing"",0],UNIT[""metre"",1,AUTHORITY[""EPSG"",""9001""]],AXIS[""X"",EAST],AXIS[""Y"",NORTH],EXTENSION[""PROJ4"",""+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext  +no_defs""],AUTHORITY[""EPSG"",""3857""]]"

    Dim EPSG4326 As String = "GEOGCS[""WGS 84"",DATUM[""WGS_1984"",SPHEROID[""WGS 84"",6378137,298.257223563,AUTHORITY[""EPSG"",""7030""]],AUTHORITY[""EPSG"",""6326""]],PRIMEM[""Greenwich"",0,AUTHORITY[""EPSG"",""8901""]],UNIT[""degree"",0.01745329251994328,AUTHORITY[""EPSG"",""9122""]],AUTHORITY[""EPSG"",""4326""]]"

    Dim srcCRS As ICoordinateSystem = Converters.WellKnownText.CoordinateSystemWktReader.Parse(EPSG4326)
    Dim tgtCRS As ICoordinateSystem = Converters.WellKnownText.CoordinateSystemWktReader.Parse(EPSG3857)

    Dim ctFac As New ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory
    Dim trans As Transformations.ICoordinateTransformation = ctFac.CreateFromCoordinateSystems(srcCRS, tgtCRS)

    Dim fromPT() As Double = {longitude, latitude}
    Dim toPT() As Double = trans.MathTransform.Transform(fromPT)

    Return toPT(0) & " " & toPT(1)

Using coordinates

longitude = -77.056610183150184, latitude = 38.871810818181821

it produces

-8577902.61, 4676494.62

instead of

-8577902.61, 4703326.17

Where am I going wrong?

  • Looks like calculations on spheroid vs sphere. – BradHards Jul 1 '17 at 3:52
  • Maybe PROJ4NET is calculating wrong because it is not up-to-date with current proj.4. There had benn a lot of confusion around EPSG:3857 in the past years, until it was fixed in proj.4. proj4net.codeplex.com/SourceControl/list/changesets tells me there has been no activity since 5 years. – AndreJ Jul 1 '17 at 7:13
  • See also gis.stackexchange.com/questions/221552/… – AndreJ Jul 1 '17 at 7:22
  • Ok cool, you have directed me in the right direction. I have now got an accurate transform y just using the mathematical formula. I have now got another issue which is better off in its own thread. Thanks!! – Ando Jul 1 '17 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.