I'm writing Windows WPF application using ESRI's axMapControl, and I need to display points on the map, where the points are in lat/lon (WGS 1984), and the map projection is determined by the user. (User selects which .mxd to display, and I cannot mandate which projection it uses.)
I've been searching around the web, looking for examples of how to project lat/lon, and this is what I've found:
double lon = -3.159875;
double lat = 51.465615;
var srf = Activator.CreateInstance(Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment")) as ISpatialReferenceFactory3;
// Create Transformation from WGS84 to OSGB86
var geoTrans = srf.CreateGeoTransformation((int)esriSRGeoTransformationType.esriSRGeoTransformation_OSGB1936_To_WGS1984Petrol) as IGeoTransformation;
var wgs84GCS = srf.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
var bngPCS = srf.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_BritishNationalGrid);
IPoint point = new Point();
point.PutCoords(lon, lat);
var geometry = point as IGeometry5;
geometry.SpatialReference = wgs84GCS;
geometry.ProjectEx(bngPCS, esriTransformDirection.esriTransformReverse, geoTrans, false, 0.0, 0.0);
point = geometry as IPoint;
double x = point.X;
double y = point.Y;
The above works fine for converting from WGS84 to OSGB86. My problem is that it depends upon a particular predefined geographic transformation, and there's no way for me to know which one to use. I'll know that I'm converting from WGS84, but I'll want to convert to the coordinate system of the map.
In digging through the ESRI docs, I've found reference to IGeometry5 .Project(), which takes only a target spatial reference, which would seem to be what I need, except that it doesn't return the same values as ProjectEx(), in the example above, and the gives me this warning:
A geometry is not densified before it is projected. This can lead to the output geometries not reflecting the 'true' shape in the new coordinate system. A straight line in one coordinate system is not necessarily a straight line in a different coordinate system. Use IGeometry2::ProjectEx if you want to densify the geometries while they are projected.
So, assuming I want to use ProjectEx(), instead of Project(), is there some way of finding the appropriate geographic transformation, given WGS84, and the spatial reference of a map?
Or is there some other way of projecting a geometry, that does densify, and can work with just the two spatial references, instead of a predefined geographic transform?