10 Replies Latest reply on Jun 22, 2011 1:59 PM by shirleydd

    Is there a way to project the coordinates without using geometry service?

    shirleydd
      Hi guys,

      I am using mouse_move event to show the coordinates of the position. Just like this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#MouseCoords

      But the projection of the maps in the map service is Transverse_Mercator and I want to display the coordinates in lat/long. I know geometry service supports projection task and I tied this method in my codes. But since we all move mouse very quickly and frequently and every move needs projection, this method really slows down the response time...

      I really would like to know whether there is a api or method to do this without projection every mousemove point nor kill the performance. Any thoughts or clues? Thank you!!

      Below are my codes:
      private void MyMap_MouseMove(object sender, System.Windows.Input.MouseEventArgs args)
              {
                  if (MyMap.Extent != null)
                  {
                      System.Windows.Point screenPoint = args.GetPosition(MyMap);
                      ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = MyMap.ScreenToMap(screenPoint);
                      //MapCoordsTextBlock.Text = string.Format("Map Coords: X = {0}, Y = {1}",
                          //Math.Round(mapPoint.X, 4), Math.Round(mapPoint.Y, 4));
      
                      //MapPoint inputMapPoint = new MapPoint(x, y, new SpatialReference(4326));
      
                      //use geometryservice's project utility
                      //GeometryService geometryService = new GeometryService("http://rmms-dev.atlas.illinois.edu/ArcGIS/rest/services/Geometry/GeometryServer");
                      //geometryService.ProjectCompleted += MouseCoordinate_geometryService_ProjectCompleted;
                      //geometryService.Failed += GeometryService_Failed;
                      //geometryService.ProjectAsync(new List<Graphic>() { new Graphic() { Geometry = mapPoint } }, new SpatialReference(4326), mapPoint);
                  }
              }
      
      void MouseCoordinate_geometryService_ProjectCompleted(object sender, GraphicsEventArgs e)
              {
                  Graphic resultGraphic = e.Results[0];
                  MapPoint resultMapPoint = resultGraphic.Geometry as MapPoint;
                  MapCoordsTextBlock.Text = string.Format("Map Coords: X = {0}, Y = {1}",
                          Math.Round(resultMapPoint.X, 4), Math.Round(resultMapPoint.Y, 4));
              }
      
        • Re: Is there a way to project the coordinates without using geometry service?
          charanp
          Don't know if this will work for you but you can take a look at it...

          http://projnet.codeplex.com/
          • Re: Is there a way to project the coordinates without using geometry service?
            shirleydd
            Don't know if this will work for you but you can take a look at it...

            http://projnet.codeplex.com/


            Hey Doc, thanks a lot! From the live sample I think that's what I want (convert coordinates from UTM to lat/long). But it looks like there is no readme in it. I can only add the dll file from XX.Web --Add reference. If I try to add it from XX--Add reference, it says:" You cannot add a reference to ProjNet.dll as it was not build against the silverlight runtime. Silverlight projects will only work with silverlight assemblies"

            Any guessing for that? Thank you:)
            • Re: Is there a way to project the coordinates without using geometry service?
              shirleydd
              ESRI.ArcGIS.Client.Bing.Transform does just that


              Hi Brandon, thank you for your suggestion. I checked this one, but this is only for converting from between webmercator (WKID=102100) and geographic WGS84. And I would like to convert UTM to geographic WGS84.
              • Re: Is there a way to project the coordinates without using geometry service?
                danwallie
                ProjNet has a Silverlight library too. Just hunt around, it's in there.
                • Re: Is there a way to project the coordinates without using geometry service?
                  charanp
                  Hi Brandon, thank you for your suggestion. I checked this one, but this is only for converting from between webmercator (WKID=102100) and geographic WGS84. And I would like to convert UTM to geographic WGS84.


                  I was able to do utm from/to geographic using Proj.Net you can do it... let me know if you need a sample...
                  • Re: Is there a way to project the coordinates without using geometry service?
                    shirleydd
                    ProjNet has a Silverlight library too. Just hunt around, it's in there.

                    Hey Daniel, thank you! I found this: Is it the one you mentioned above? http://projnet.codeplex.com
                    • Re: Is there a way to project the coordinates without using geometry service?
                      shirleydd
                      I was able to do utm from/to geographic using Proj.Net you can do it... let me know if you need a sample...


                      Hi Doc, I really appreciate that you would share a sample :) This task really burns my head...
                      BTW: In the weblink you gave me I download the dll file, but I cannot add this reference to the project reference, I can only add it to project's web reference. Was it normal or just I did some mistake. ..Thank you!
                      • Re: Is there a way to project the coordinates without using geometry service?
                        charanp
                        I never tested the following code how accurate it is... it was just a part of my dirty prototype... so would recommend test it...
                        I followed the sample given on ProjNet

                            /// <summary>
                            /// Class that performs conversions using the ProjNet library.
                            /// </summary>
                            public class CoordinateConversion
                            {
                                /// <summary>
                                /// Function that converts UTM x,y to lat long.
                                /// </summary>
                                /// <param name="x">UTM x coordinate.</param>
                                /// <param name="y">UTM y coordinate.</param>
                                /// <param name="zone">The zone of the UTM.</param>
                                /// <param name="zoneisnorth">If Zone is north.</param>
                                /// <returns>The lat long value.</returns>
                                public static Point UTMtoLATLONG(double x, double y, int zone, bool zoneisnorth)
                                {
                                    System.Windows.Point p = new System.Windows.Point(x, y);
                        
                                    CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();
                                    ICoordinateSystem wgs84geo = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84;
                                    ICoordinateSystem utm = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(zone, zoneisnorth);
                                    ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(wgs84geo, utm);
                        
                                    IMathTransform test = trans.MathTransform.Inverse();
                                    Point pxy = test.Transform(p);
                        
                                    return pxy;
                                }
                        
                                /// <summary>
                                /// Lat long to UTM.
                                /// </summary>
                                /// <param name="latitude">The longitude value.</param>
                                /// <param name="longitude">The latitude value.</param>
                                /// <param name="zone">The UTM Zone.</param>
                                /// <param name="zoneisnorth">If the UTM zone is north.</param>
                                /// <returns>The UTM X and Y values.</returns>
                                public static Point LATLONGtoUTM(double latitude, double longitude, int zone, bool zoneisnorth)
                                {
                                    System.Windows.Point pointGeo = new Point(longitude, latitude);
                        
                                    // Transform to UTM - Calculates UTM coordinates and zone
                                    CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();
                                    ICoordinateSystem wgs84geo = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84;
                                    int calculatedZone = (int)Math.Ceiling((pointGeo.X + 180) / 6);
                                    ICoordinateSystem utm = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(calculatedZone, pointGeo.Y > 0);
                                    ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(wgs84geo, utm);
                                    Point pointUtm = trans.MathTransform.Transform(pointGeo);
                                    
                                    // If calculated zone is not same as the supplied zone then convert the calculated UTM to the supplied UTM zone
                                    if (calculatedZone != zone)
                                    {
                                        // The original UTM zone that the map is in
                                        ICoordinateSystem utmto = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(zone, zoneisnorth);
                                        
                                        // The UTM of calculated zone
                                        ICoordinateSystem utmfrom = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(calculatedZone, zoneisnorth);
                        
                                        trans = ctfac.CreateFromCoordinateSystems(utmfrom, utmto);
                                        pointUtm = trans.MathTransform.Transform(pointUtm);
                                    }
                        
                                    return pointUtm;
                                }
                            }
                        • Re: Is there a way to project the coordinates without using geometry service?
                          shirleydd
                          Hey Doc, I really really want to try this sample code. But I still cannot add the ProNet.dll to the reference...(I can only add it from XX.Web --Reference--Add reference) I assume you must successfully added it. Could you share your ProNet.dll file? I am going to give another shot to add it. Thanks a lot! :) My email is shirleydd@gmail.com