Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Please can someone help me convert a point in WGS1984 to OSGB1936, I have followed all the documentation (or so i think...) and yet have not made any headway into this problem. This is my code :

Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
System.Object obj = Activator.CreateInstance(factoryType);
ISpatialReferenceFactory3 spacialReferenceFactory3 = obj as ISpatialReferenceFactory3;

// Create Transformation from WGS84 to OSGB86
IGeoTransformation geoTrans = spacialReferenceFactory3.CreateGeoTransformation((int)esriSRGeoTransformationType.esriSRGeoTransformation_OSGB1936_To_WGS1984Petrol) as IGeoTransformation;

ISpatialReference fromSpatialReference;
ISpatialReference toSpatialReference;
geoTrans.GetSpatialReferences(out fromSpatialReference, out toSpatialReference);

IGeometry5 geometry;
IPoint point = new PointClass();
point.PutCoords(51.465615, -3.159875);
geometry = point as IGeometry5;
geometry.SpatialReference = toSpatialReference;
geometry.ProjectEx(fromSpatialReference, esriTransformDirection.esriTransformForward, geoTrans, false, 0.0, 0.0);
point = new PointClass();
point = geometry as IPoint;

My point is being returned from the Geometry object as 51.46200954514034, -3.1549783406850165. I have tried using the reverse transformation as specified in geometry.ProjectEx(), and all i get is the same X and Y as the original point. I have also tried different combinations of reverse / forward and also swapping the fromSpatialReference and toSpatialReference.

share|improve this question
1  
Maybe your x & y are reversed? This point is out in the Indian Ocean. –  Kirk Kuykendall Feb 13 '13 at 18:08

1 Answer 1

up vote 2 down vote accepted

This prints: 319524.804848596 174709.885049006.

private static void TestProjection()
{
    Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment"); 
    System.Object obj = Activator.CreateInstance(factoryType); 
    var srf = obj as ISpatialReferenceFactory3;

    // Create Transformation from WGS84 to OSGB86
    var geoTrans = srf.CreateGeoTransformation((int)esriSRGeoTransformationType.esriSRGeoTransformation_OSGB1936_To_WGS1984Petrol) as IGeoTransformation;

    ISpatialReference fromSpatialReference;
    ISpatialReference toSpatialReference;
    geoTrans.GetSpatialReferences(out fromSpatialReference, out toSpatialReference);

    var wgs84GCS =  srf.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
    var bngPCS = srf.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_BritishNationalGrid);
    if((wgs84GCS.FactoryCode != toSpatialReference.FactoryCode)
        || (bngPCS.GeographicCoordinateSystem.FactoryCode != fromSpatialReference.FactoryCode))
    {
        throw new Exception("invalid geotransformation");
    }

    IGeometry5 geometry;
    IPoint point = new PointClass();
    point.PutCoords(-3.159875, 51.465615);
    geometry = point as IGeometry5;
    geometry.SpatialReference =wgs84GCS;

    geometry.ProjectEx(bngPCS, esriTransformDirection.esriTransformReverse, geoTrans, false, 0.0, 0.0);
    point = geometry as IPoint;
    Debug.Print("{0} {1}", point.X, point.Y);
}
share|improve this answer
    
Thanks for taking time to look at this Kirk, i am getting the values you mentioned - but my GIS specialist said that the point should convert to 319525, 174710. We want British National Grid Coords and he thought OSGB1936 Petrol would have converted to what we needed, this assumption was obviously incorrect. You don't happen to know how we could convert to British Nation Coordinates? –  leinad13 Feb 13 '13 at 18:48
    
I've updated my answer to do this. –  Kirk Kuykendall Feb 13 '13 at 19:10
    
@leinad13 also, note that I flipped x & y. –  Kirk Kuykendall Feb 13 '13 at 19:16
    
Worked a treat thanks Kirk –  leinad13 Feb 20 '13 at 14:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.