2

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
 al.Add("C:\link\to\layer file\Map.lyr")
 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
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Feb 8, 2016 at 15:05
2
  • 1
    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. Commented Feb 8, 2016 at 18:25
  • Thanks for the reply. Would this work with layers that point to WMS server? The data is a raster layer. Commented Feb 9, 2016 at 14:51

1 Answer 1

2

As @mkennedy says the LayerFile is a "pointer" to the actual data but it can hold stuff like symbology, definition queries and basic metadata.

You can set up the IMapGeographicTransformations or how about doing away with the whole problem by projecting your data into OSGB, create a LayerFile for your data (now in OSGB) and load that? I suggest this alternative approach because:

  • All your data will be in a standard coordinate system.
  • Simplifies your code and any future maintenance of it.
  • You are assuming your end users are savvy enough to know that even though the data they are observing appears to be in the correct coordinate system the actual underlying data is in WGS84. This will affect any further downstream processing of data.

If it were me I would ensure all data going into your tool is OSGB and reject it if not, thus all datasets are the same coordinate system and reduces the likelihood of errors.

answered Feb 9, 2016 at 13:25
1
  • Good point, did not think of it that way. The layer actually points to a WMS server. Saving the layer file into OSGB did not work, every time I reload it goes back to the original state. However by amending the data frame transformation in the data frame properties I was able to set it so that any WGS1984 layer converts to OSGB 1936 automatically. So now I have 2 choices. 1. change the data frame properties for all the mxd's they use or 2. create a geotransformation sub. Commented Feb 9, 2016 at 14:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.