code to convert xy coordinates to lat long

3230
4
09-14-2010 01:21 PM
DuaneWhistle
New Contributor
Does anyone have code to convert xy coordinates to lat long?
0 Kudos
4 Replies
AkhilParujanwala
New Contributor III
I dont have the code to do that, but I can suggest the solution I am doing if this helps.

When you deploy your Mobile Application, have 2 fields, one for Lat and Long make them text fields.

Once your field crew upload points to the Server, you can have someone at a computer using ArcMap, calculate Lat and Long in those fields, and then your field crew can download the data accordingly.

If you are interested in doing it this way, let me know and I can help you out some more.
0 Kudos
MelindaFrost
Occasional Contributor
I have done conversions using the free corpson code libraries. You will have to copy the libraries to each machine and either put in same folder path location or use a config the application reads to know the stored path of the corpson libaries.

http://http://www.agc.army.mil/corpscon/index.html

here is some code snippet of setting it up. there are some other calls you need to set up first that  I did not include. If you want the rest of the code snippet- just let me know. Believe the download of corpscon includes a user guide.

<DllImport("F:\ArcIMS\Corpscon6\corpscon_v6.dll", EntryPoint:="GetXOut", SetLastError:=True, _
                CharSet:=CharSet.Unicode, ExactSpelling:=True, _
                CallingConvention:=CallingConvention.StdCall)> _
                Public Shared Function getoutx() As Double
        ' Leave function empty - DllImport attribute forces calls 
        ' to Corpsconconfig to be forwarded to MoveFileW in KERNEL32.DLL.
    End Function

    <DllImport("F:\ArcIMS\Corpscon6\corpscon_v6.dll", EntryPoint:="GetYOut", SetLastError:=True, _
                CharSet:=CharSet.Unicode, ExactSpelling:=True, _
                CallingConvention:=CallingConvention.StdCall)> _
                Public Shared Function getouty() As Double
        ' Leave function empty - DllImport attribute forces calls 
        ' to Corpsconconfig to be forwarded to MoveFileW in KERNEL32.DLL.
    End Function


then you just need to call your methods to convert to and from whatever.

Private Sub convertDegreestoFeet(ByVal inx As Double, ByVal iny As Double, ByRef outx As Double, ByRef outy As Double)
        Dim RetVal As Integer

        RetVal = setinsystem(1)
        RetVal = setindatum(1983)
        RetVal = setoutstystem(2)
        RetVal = setoutdatum(1983)
        RetVal = setoutzone(1900)
        RetVal = setoutunits(1)

        RetVal = Corpscon_initialize()

        RetVal = setiny(iny)
        RetVal = setinx(inx)
        Dim script As String

        RetVal = Corpscon_convert()

        Dim outdbl As Double
        outdbl = getoutx()
        script = "<script language=JavaScript>window.alert('" & outdbl & "'); </script>"
        'ClientScript.RegisterStartupScript(Me.GetType, "tab3", script)
        outx = outdbl

        outdbl = getouty()
        script = "<script language=JavaScript>window.alert('" & outdbl & "'); </script>"
        'ClientScript.RegisterStartupScript(Me.GetType, "tab4", script)
        outy = outdbl

    End Sub
0 Kudos
MelindaFrost
Occasional Contributor
Another suggestion. If the x,y being collected is the same soordinate system (e.g. state plane) as what is in your map document, then you can do the following:

// Create a spatial reference object from mobile service 
SpatialReference spatialReference = mobileService.SpatialReference; 
// specify input X and Y coordinates 
double x = 6220900; 
double y = 2300141; 
// Transform coordinate from map's coordinate system to WGS84. 
Coordinate coordinate = spatialReference.ToWgs84(x, y); 


much simpler than going through corpscon
0 Kudos
lingyang
New Contributor
You could also use the SpatialReferenceConverter from ESRI.ArcGIS.Mobile.SpatialReferences to convert between any two coordinate systems that ESRI support, e.g.
SpatialReferenceConverter src = new SpatialReferenceConverter(
                    SpatialReference.CreateWgs84SpatialReference(),
                    SpatialReference.Create(2264));
Coordinate xy = src.FromSpatialReference1ToSpatialReference2(new Coordinate(lng, lat));

To convert from WGS84 to NAD_1983_StatePlane_North_Carolina_FIPS_3200_Feet.
0 Kudos