Converting coordinates

433
5
Jump to solution
09-24-2012 02:02 PM
Occasional Contributor III
I am listening to the OnMouseDown event of my IMapControl4, and the IMapControlEvents2_OnMouseDownEvent provides a mapX and mapY. How do I convert this coordinate to WGS84? I need to interface with another 3rd party library that requires WGS84 coordinates as its input.

Thanks,
George Faraj
Reply
0 Kudos
1 Solution

Accepted Solutions
Regular Contributor III
You need to project the data to that coordinate system.  The map x, y passed into the event are in whatever coordinate system the map is in, so just create a new point object, give it the same spatial reference as the map and set the x, y properties.  Then call Project and pass in the spatial reference you want to project it to.  You can get this spatial reference object from ISpatialReferenceFactory.CreateGeographicCoordinateSystem.  After calling Project, the x, y properties will have the updated coordinates.

View solution in original post

Reply
0 Kudos
5 Replies
Regular Contributor III
You need to project the data to that coordinate system.  The map x, y passed into the event are in whatever coordinate system the map is in, so just create a new point object, give it the same spatial reference as the map and set the x, y properties.  Then call Project and pass in the spatial reference you want to project it to.  You can get this spatial reference object from ISpatialReferenceFactory.CreateGeographicCoordinateSystem.  After calling Project, the x, y properties will have the updated coordinates.

View solution in original post

Reply
0 Kudos
Occasional Contributor III
Thank you Neil. That helped. I wrote the following method:


public static IPoint GetLatLngPointsFromMapPoints(this IActiveView view, IMapControl4 map, double controlX, double controlY)
{
var mapPoint = new PointClass();
mapPoint.SpatialReference = map.SpatialReference;
mapPoint.PutCoords(controlX, controlY);

if (mapPoint.SpatialReference.Name == "Unknown")
{
  mapPoint.SpatialReference = view.ScreenDisplay.DisplayTransformation.ToMapPoint(0, 0).SpatialReference;
}
if (double.IsNaN(mapPoint.Z))
{
  mapPoint.Z = 0;
}

if (mapPoint.SpatialReference.Name == "Unknown")
{
  return null;
}

var spatialRefFactory = new SpatialReferenceEnvironment();
var geoCoordSystem = spatialRefFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
mapPoint.Project(geoCoordSystem);
return mapPoint;
}


And I'm getting values like -122.545187727749 and 45.6971389559235. Not sure if these are degrees or if they are just incorrect. Does this sound right to you?
Reply
0 Kudos
Regular Contributor III
Without knowing what your original coordinate system and coordinates are I can't tell you if those values are correct or not.  The results you're getting will be in decimal degrees since you are projecting into a geographic coordinate system.  Remember that when expressed as x, y coordinates of a point that x = longitude and y = latitude.  Longitude values range from 0 to 180 with positive values being measured East and negative values being measured West.  Latitude values range from 0 to 90 with positive values being measured North and negative values being measured South.  The coordinates you posted are near Vancouver, Canada.
Reply
0 Kudos
Occasional Contributor III
Alright, so I think I have the correct coordinates in degrees now. Thanks a lot!
Reply
0 Kudos

Good morning everyone! I would like to ask if there is a way to define my coordinates, taking into account that I don't know their coordinates system. Is there a way to determine it? All I have is an xls file. Thank you very much for your collaboration!

Tags (1)
Reply
0 Kudos