# Arcobjects Assign projection transformation to layer file in VB.net

I want to be able to transform a layer from WGS1984 to OSGB1936. I created a tool that extracts layers from several folders on our company network folders, using check boxes that user clicks. One of the layers is in WGS1984 and when the tool brings it in, it does not transform very well. I know I need to transform it using OSGB_1936_To_WGS_1984_5. But I am not sure how to transform a layer file.

So far I have:

Private Sub CheckBox59_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox59.CheckedChanged
If CheckBox59.Checked = True Then
End If
End Sub


The above adds the layer name to a array list then I use another sub to add layer to Arcmap. But how can I say "if the layer is Map.lyr then transform using OSGB_1936_To_WGS_1984_5"

I found the code below originally written in c# and I converted into vb.net, it transforms points from WGS1984 to British National Grid, but how can I incorporate that into my layer file?

Private Shared Sub TestProjection()
Dim factoryType As Type = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment")
Dim obj As System.Object = Activator.CreateInstance(factoryType)
Dim srf = TryCast(obj, ISpatialReferenceFactory3)

Dim geoTrans = TryCast(srf.CreateGeoTransformation(CInt(esriSRGeoTransformationType.esriSRGeoTransformation_OSGB1936_To_WGS1984_5)), IGeoTransformation)

Dim fromSpatialReference As ISpatialReference
Dim toSpatialReference As ISpatialReference
geoTrans.GetSpatialReferences(fromSpatialReference, toSpatialReference)

Dim wgs84GCS = srf.CreateGeographicCoordinateSystem(CInt(esriSRGeoCSType.esriSRGeoCS_WGS1984))
Dim bngPCS = srf.CreateProjectedCoordinateSystem(CInt(esriSRProjCSType.esriSRProjCS_BritishNationalGrid))
If (wgs84GCS.FactoryCode <> toSpatialReference.FactoryCode) OrElse (bngPCS.GeographicCoordinateSystem.FactoryCode <> fromSpatialReference.FactoryCode) Then
Throw New Exception("invalid geotransformation")
End If

Dim geometry As IGeometry5
Dim point As IPoint = New PointClass()
point.PutCoords(-3.159875, 51.465615)
geometry = TryCast(point, IGeometry5)
geometry.SpatialReference = wgs84GCS

geometry.ProjectEx(bngPCS, esriTransformDirection.esriTransformReverse, geoTrans, False, 0.0, 0.0)
point = TryCast(geometry, IPoint)
Debug.Print("{0} {1}", point.X, point.Y)
End Sub

• Layers just contain links to actual data. I think you should instead look at getting the transformation into the active GeoTransformationOperationSet. There's some general code here. Map has its own IMapGeographicTransformations which links to GTOpSet. – mkennedy Feb 8 '16 at 18:25
• Thanks for the reply. Would this work with layers that point to WMS server? The data is a raster layer. – Daz Feb 9 '16 at 14:51