4 Replies Latest reply: Nov 1, 2010 12:41 PM by lingyang2014

    code to convert xy coordinates to lat long

    whistle_d
      Does anyone have code to convert xy coordinates to lat long?
        • Re: code to convert xy coordinates to lat long
          AkhilP
          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.
          • Re: code to convert xy coordinates to lat long
            buddha198
            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
            • Re: code to convert xy coordinates to lat long
              buddha198
              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
              • Re: code to convert xy coordinates to lat long
                lingyang2014
                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.