ThinkGeo.com    |     Blog    |     Wiki    |     Support

How can I convert x y co-ordinate to degree decimal

hi…

I have created map app. with using thinkgeo. I am currently trying to put marker on map with specific x and y positions, but I have faced problem with that I can’t transform my own co-ordinate’s because it is for google map and I want to convert it into thinkgeo map co-ordinate’s. I have put here my code for converting this with javascript. Please, reply as soon as possible.



 var point = new OpenLayers.Geometry.Point(x, y);

        var srcProj = new OpenLayers.Projection(‘EPSG:3857’);

        var desProj = new OpenLayers.Projection(‘EPSG:32723’);

        var newPoint = OpenLayers.Projection.transform(point, srcProj, desProj);

        var newX = newPoint.x;

        var newY = newPoint.y;

        Map1.panToWorldCoordinate(newX, newY);

    

Hi, 
  
 try this: 
  
 public Proj4Projection Prj4Mercator() 
 { 
   Proj4Projection _prj = new Proj4Projection(); 
   _prj.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString(); 
   _prj.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326); 
   _prj.Open(); 
   return (_prj); 
 } 
  
  
 then use this code. 
  
 PointShape _gpsPointShape = new PointShape(); 
 double _GPSlongitude = 0; 
 double _GPSlatitude = 0; 
  
 Proj4Projection proj4 = this.Prj4Mercator(); 
 proj4.Open(); 
 _GPSlongitude = Convert.ToDouble(args["x"], CultureInfo.InvariantCulture); 
 _GPSlatitude = Convert.ToDouble(args["y"], CultureInfo.InvariantCulture); 
 _gpsPointShape = new PointShape(new Vertex(_GPSlongitude, _GPSlatitude)); 
 GpsFeature = new Feature(proj4.ConvertToExternalProjection(_gpsPointShape)); 
 proj4.Close(); 
  


Sorry it was C# code  
  
 now this is for javascript: 
  
  
 function findProperty(lon, lat) { 
     var fromProjection = new OpenLayers.Projection("EPSG:4326");   // Transform from WGS 1984 
     var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection 
     var position = new OpenLayers.LonLat(lon, lat).transform(fromProjection, toProjection); 
     Map1.setCenter(position, 12); 
 } 


Hi Yogesh And JM, 
  
 Thanks for Yogesh’S post and welcoem to MapSuite World. Thanks for Jean Marie’s sharing. Jean Marie’s reply on “08-19-2013 09:39 PM” is basicly right, but there might be a slight admendment: If the marker’s srcProj might not be the “EPSG:4326”, please replace it with marker’s srcProj, So the code should be: 
  
 function findProperty(lon, lat) {  
  var fromProjection = new OpenLayers.Projection(”EPSG:marker’s srcProj"); // Transform from WGS 1984  
  var toProjection = new OpenLayers.Projection(“EPSG:900913”); // to Spherical Mercator Projection  
  var position = new OpenLayers.LonLat(lon, lat).transform(fromProjection, toProjection);  
  Map1.setCenter(position, 12);  
  }  
  
 if you have any more question , please feel free to let us know. 
  
 Best Regards 
  
 Summer

hi…



I have tried this code but I don’t get the solution. It is not converted with latitude and longitude values. Please give another solution for that. I am not getting the marker with proper place on google map.

Hi Yogesh, 
  
 Thanks for your further information, and sorry for missing " my own co-ordinate’s because it is for google map" in your statment, from this statement your maker srcProj should be OpenLayers.Projection(‘EPSG:3857’), and the desProj should be OpenLayers.Projection(‘EPSG:4326’)(EPSG:4326 is our default projection). So, the right code should be: 
  
  var point = new OpenLayers.Geometry.Point(x, y); 
         var srcProj = new OpenLayers.Projection(‘EPSG:3857’); 
         var desProj = new OpenLayers.Projection(‘EPSG:4326’); 
         var newPoint = OpenLayers.Projection.transform(point, srcProj, desProj); 
         var newX = newPoint.x; 
         var newY = newPoint.y; 
         Map1.panToWorldCoordinate(newX, newY); 
  
 Would you please try it again? And if the marker still don’t show, would you please give the marker’s coordinate? we will make a small sample for you. 
  
 Waiting for your furhter information. 
  
 Summer

Hi Summer,



I try your code,

Coordinate is change but still I don’t get marker to perfect place.



My Marker Coordinate is:

X: 229425.8125

Y: 7575127.5



This is in UTM Format.



If I try this coordinate in Google Map so that time it show me perfect place but in my project

this Coordinate is not work I mean in my project this coordinates show me different location.



In my Project when I hover the mouse to the place where I want marker so it show me:

-5301084.63677, -2500736.94520 this coordinate while in my database Coordinate of that place is mention as above X and Y.

Hi Yogesh,



Thanks for your data, attached is our test sample on our end, and here is a guiding test vedio for you: screencast.com/t/YgQ2xupOoE3t



Hope ie helps



Summer

TransformSample.zip (1.49 MB)

Hi, summer



Thanks for giving this example can you please give this example in MapsuiteMVC application. Because, my application is in MVC 3 application



Thanks & Regards,

Hi Yogesh,



here is the mvc sample.



if you have any more question , please feel free to let us know.



Best Regards






Summer

MVCSample.zip (1.62 MB)

Thankx for help

Thank You Summer

Hi Yogesh, 
  
 Great to hear it helped, if you have any more question, please feel free to let us know. 
  
 Best Regards 
  
 Summer

I want to catch coordinates from map like these Dallas(32.776664,-96.796988) and my code is…

private Location ProjectLocation(Location location)
{
Proj4Projection prj4 = new Proj4Projection();
(Edit)prj4.InternalProjectionParametersString = Proj4Projection.GetGoogleMapsParametersString();
prj4.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
prj4.Open();
PointShape projectedPoint = prj4.ConvertToExternalProjection(new PointShape(location.Longitude, location.Latitude)) as PointShape;

        Location projectedLocation = new Location();
        projectedLocation.Longitude = Math.Round(projectedPoint.X, 6);
        projectedLocation.Latitude = Math.Round(projectedPoint.Y, 6);
        return location;
    }

What changes should I make…Please help

Hi Ankit_Singh,

Your code convert location(wgs84) to decimal degree, so what’s the detail question here?

Regards,

Ethan

Hi Ethan…
So in my project i am using a database which stores location in x,y coordinates to display on map…
Through the above procedure they are correctly displayed as x,y coordinates…
But my team requires me to store normal lat long coordinates in database(degree decimal)…like 32.776664,-96.796988…but through this code it fails to display such coordinates.
So,what changes should i do…?
Thanks

Hi Ankit_Singh,

In fact I still have a little confused about your question.

Please let me know if I misunderstand your question here:

  1. Your database save the meter coordinate before and it works well
  2. Now you want to change the data to decimal degree coordinate and you still want to show it correct

Does it right?

If that’s true, that means your original MapUnit is DecimalDegree, so you don’t need do reprojection now, jure remove the projection related code, and directly render the data should be works.

If you think the text is hard to describe your question please build a simple sample and upload it here, here is the guide about that: http://wiki.thinkgeo.com/wiki/map_suite_project_template_guide

Regards,

Ethan

Actually I am not much familiar with the coordinate system…
Simply…I have these coordinates in my database (8149809.385,2547105.881) which are displayed correctly but i want to use (23.196685,72.631305) and through the code i have these are displayed on the equator as (0,0)

Hi Ankit_Singh,

Thanks for your sample, I see your question.

The code as below should works for your scenario:

PointShape pointInDatabaseNow = new PointShape(23.196685, 72.631305);

Proj4Projection prj4 = new Proj4Projection();
prj4.InternalProjectionParametersString = Proj4Projection.GetDecimalDegreesParametersString();
prj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
prj4.Open();
PointShape pointOnMapNow = prj4.ConvertToExternalProjection(pointInDatabaseNow) as PointShape; // It should be the format like 8149809.385,2547105.881

Wish that’s helpful.

Regards,

Ethan