+ Reply to Thread
Results 1 to 5 of 5

Thread: code to convert xy coordinates to lat long

  1. #1
    Duane Whistle
    Join Date
    Jul 2010
    Posts
    7
    Points
    0
    Answers Provided
    0


    0

    Default code to convert xy coordinates to lat long

    Does anyone have code to convert xy coordinates to lat long?

  2. #2
    Akhil Parujanwala
    Join Date
    Aug 2010
    Posts
    280
    Points
    10
    Answers Provided
    2


    0

    Default Re: code to convert xy coordinates to lat long

    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.

  3. #3
    Melinda Frost
    Join Date
    Apr 2010
    Posts
    60
    Points
    0
    Answers Provided
    0


    0

    Default Re: code to convert xy coordinates to lat long

    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.

    Code:
    <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.

    Code:
    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

  4. #4
    Melinda Frost
    Join Date
    Apr 2010
    Posts
    60
    Points
    0
    Answers Provided
    0


    0

    Default Re: code to convert xy coordinates to lat long

    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:

    Code:
    // 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

  5. #5
    Ling Yang
    Join Date
    Nov 2010
    Posts
    2
    Points
    0
    Answers Provided
    0


    0

    Default Re: code to convert xy coordinates to lat long

    You could also use the SpatialReferenceConverter from ESRI.ArcGIS.Mobile.SpatialReferences to convert between any two coordinate systems that ESRI support, e.g.
    Code:
    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.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts