[GIS] VB.net Converting UTM to Lat/Lon (State Plane with WKID) – ArcGis

arcgis-runtimecoordinatesvb.net

I have looked at many libraries. Many simply don't work, others are very poorly documented.

I have a very long list of X/Y coordinates (US FT) and an associated WKID. I am trying to convert that to Lat/Lon format for mapping.

Can anyone suggest routes for completing this process in vb.net?

(the closest I've come to success is finding the esri.arcgisruntime.geometry.ProjectionConverter.convert – This seems to give me the option to suggest a wkid, x & y coord… but It's poorly documented and, unfortunately, I can't get it to do any conversions)

    Dim wkid as integer= 102100
    Dim ref As New Esri.ArcGISRuntime.Geometry.SpatialReference(wkid)
    Dim converter = New Esri.ArcGISRuntime.Geometry.ProjectionConverter()
    Dim mappoint = New Esri.ArcGISRuntime.Geometry.MapPoint(-9638404.7886215933, 3990218.2857465576, ref)
    Dim typ As Type = GetType(Esri.ArcGISRuntime.Geometry.MapPoint)
    Dim glob As New Globalization.CultureInfo("en")
    Dim result = converter.Convert(mappoint, typ, wkid, glob)

FYI, if there are some arcgis account auth required, I do not have that.

Best Answer

For those interested I've managed to get this working, I'm converting from MGA meters to a local map grid projection, also in meters.

private Esri.ArcGISRuntime.Geometry.MapPoint ConvertToLocalMapGridCoords(Esri.ArcGISRuntime.Geometry.MapPoint sourceMapPoint, string projectionFile)
{
    var wkTextDest = System.IO.File.ReadAllText(projectionFile);

    var projectionConverter = new Esri.ArcGISRuntime.Geometry.ProjectionConverter();
    var result = projectionConverter.Convert(sourceMapPoint, typeof(MapPoint), wkTextDest, System.Globalization.CultureInfo.InvariantCulture);

    return (Esri.ArcGISRuntime.Geometry.MapPoint)result;
}

I'm calling it using: (You will most likely be doing something completely different here!)

const int wkidSource = 102100;
var coordPoint = newMapControl.ScreenPointToCoordPoint(e.Location);

var mouseMapPoint = Esri.ArcGISRuntime.Geometry.ConvertCoordinate.FromDecimalDegrees(string.Format("{0},{1}", coordPoint.GetY(), coordPoint.GetX()), new Esri.ArcGISRuntime.Geometry.SpatialReference(wkidSource));

var convertedMapPoint = ConvertToLocalMapGridCoords(mouseMapPoint, @"C:\abc\xyz.prj");

I'm creating a spacial reference from a well known text (ESRI Projection File .prj).

Note: coordPoint.GetY(), coordPoint.GetX() are just Decimal latitudes and longitudes respectively.