This document is archived and information here might be outdated.  Recommended version.


How to initialize a world file with rotation (ArcObjects .NET 10.5 SDK)

How to initialize a world file with rotation


Summary
This topic discusses the new IWorldFileSettings2.MapRotation interface. By using this interface, a world file can be created for image exports that contain rotation parameters.

Initializing a world file with rotation

The following code example sets up a world file for a given IExport passed in as docExport. It assumes that a HookHelper object has been set up to obtain the active view. If the docExport is not coming from IExportFileDialog, the mapWorldFileSettings.OutputWorldFile parameter must be set to true for a world file to be output. Do the following steps to initialize a world file with rotation:
  1. Cast the two world file settings variables to an IExport variable. See the following code example:
[C#]
IWorldFileSettings mapWorldFileSettings;
IWorldFileSettings2 mapWorldFileSettings2;

//Cast the following two world file settings variables to docExport.
mapWorldFileSettings=docExport as IWorldFileSettings;
mapWorldFileSettings2=docExport as IWorldFileSettings2;
[VB.NET]
Dim mapWorldFileSettings As IWorldFileSettings
Dim mapWorldFileSettings2 As IWorldFileSettings2

'Cast the following two world file settings variables to docExport.
mapWorldFileSettings=docExport
mapWorldFileSettings2=docExport
  1. Set the extent of the export for which you are generating a world file. See the following code example.
[C#]
//The mapWorldFileSettings.OutputWorldFile is set by the dialog box.
mapWorldFileSettings.MapExtent=m_GraphicsExtentEnv;
[VB.NET]
'The mapWorldFileSettings.OutputWorldFile is set by the dialog box.
mapWorldFileSettings.MapExtent=m_GraphicsExtentEnv
  1. Copy the data frame's rotation angle from the DisplayTransformation to the MapRotation property. See the following code example:
[C#]
//The mapWorldFileSettings2.MapRotation must be copied for the world file to properly reflect rotation.
mapWorldFileSettings2.MapRotation =
    m_ActiveView.ScreenDisplay.DisplayTransformation.Rotation;
[VB.NET]
'The mapWorldFileSettings2.MapRotation must be copied for the world file to properly reflect rotation.
mapWorldFileSettings2.MapRotation=m_ActiveView.ScreenDisplay.DisplayTransformation.Rotation
If you are using an export dialog box, the state of the IWorldFileSettings2 member property OutputWorldFile will be set by that dialog box. If not, initialize that property to true to ensure that a world file is output.
[C#]
private void InitWorldFile(IExport docExport)
{
    IWorldFileSettings mapWorldFileSettings;
    IWorldFileSettings2 mapWorldFileSettings2;
    //Use the new IWorldFileSettings2 interface to write the rotation to the world file.
    if (docExport is IExportImage && m_pHookHelper.ActiveView is IMap)
    {
        //Cast these two world file settings variables to docExport.
        mapWorldFileSettings=docExport as IWorldFileSettings;
        mapWorldFileSettings2=docExport as IWorldFileSettings2;
        //The mapWorldFileSettings.OutputWorldFile is set by the dialog box.
        mapWorldFileSettings.MapExtent=m_GraphicsExtentEnv;
        //The mapWorldFileSettings2.MapRotation must be copied for the world file to properly reflect rotation.
        mapWorldFileSettings2.MapRotation =
            m_ActiveView.ScreenDisplay.DisplayTransformation.Rotation;
    }

}
[VB.NET]
Private Sub InitWorldFile(ByVal docExport As IExport)
    Dim mapWorldFileSettings As IWorldFileSettings
    Dim mapWorldFileSettings2 As IWorldFileSettings2
    'Use the new IWorldFileSettings2 interface to write the rotation to the world file.
    If TypeOf docExport Is IExportImage And m_pHookHelper.ActiveView Is IMap Then
        'Cast these two world file settings variables to docExport.
        mapWorldFileSettings=docExport
        mapWorldFileSettings2=docExport
        'The mapWorldFileSettings.OutputWorldFile is set by the dialog.
        mapWorldFileSettings.MapExtent=m_GraphicsExtentEnv
        'The mapWorldFileSettings2.MapRotation must be copied for the world file to properly reflect rotation.
        mapWorldFileSettings2.MapRotation=m_ActiveView.ScreenDisplay.DisplayTransformation.Rotation
    End If
    
End Sub






Additional Requirements
  • docExport is already an initialized IExport object—The code assumes the use of the HookHelper object to obtain the active view.
  • Global Envelope object m_GraphicsExtentEnv—The extent of the area you are exporting to.

Development licensing Deployment licensing
ArcGIS for Desktop Basic ArcGIS for Desktop Basic
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced
Engine Developer Kit Engine