+ Reply to Thread
Results 1 to 11 of 11

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

  1. #1
    Dan Dong
    Join Date
    Sep 2010
    Posts
    197
    Points
    7
    Answers Provided
    0


    0

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

    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/sil...tm#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:
    Code:
    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));
            }

  2. #2
    doc ock
    Join Date
    Mar 2011
    Posts
    122
    Points
    0
    Answers Provided
    0


    0

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

    Don't know if this will work for you but you can take a look at it...

    http://projnet.codeplex.com/

  3. #3
    Brandon Copeland
    Join Date
    Apr 2010
    Posts
    25
    Points
    1
    Answers Provided
    0


    0

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

    Brandon Copeland

  4. #4
    Dan Dong
    Join Date
    Sep 2010
    Posts
    197
    Points
    7
    Answers Provided
    0


    0

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

    Quote Originally Posted by doc21 View Post
    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

  5. #5
    Dan Dong
    Join Date
    Sep 2010
    Posts
    197
    Points
    7
    Answers Provided
    0


    0

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

    Quote Originally Posted by copeland View Post
    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.

  6. #6
    Daniel Walton
    Join Date
    Apr 2010
    Posts
    188
    Points
    6
    Answers Provided
    1


    0

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

    ProjNet has a Silverlight library too. Just hunt around, it's in there.
    Dan Walton
    Lead Developer, intterra

  7. #7
    doc ock
    Join Date
    Mar 2011
    Posts
    122
    Points
    0
    Answers Provided
    0


    0

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

    Quote Originally Posted by shirleydd View Post
    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...

  8. #8
    Dan Dong
    Join Date
    Sep 2010
    Posts
    197
    Points
    7
    Answers Provided
    0


    0

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

    Quote Originally Posted by danwallie View Post
    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
    Last edited by shirleydd; 06-21-2011 at 08:32 PM.

  9. #9
    Dan Dong
    Join Date
    Sep 2010
    Posts
    197
    Points
    7
    Answers Provided
    0


    0

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

    Quote Originally Posted by doc21 View Post
    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!

  10. #10
    doc ock
    Join Date
    Mar 2011
    Posts
    122
    Points
    0
    Answers Provided
    0


    0

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

    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

    Code:
        /// <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;
            }
        }
    Last edited by doc21; 06-22-2011 at 09:55 AM.

  11. #11
    Dan Dong
    Join Date
    Sep 2010
    Posts
    197
    Points
    7
    Answers Provided
    0


    0

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

    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

+ Reply to 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