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:
- Cast the two world file settings variables to an IExport variable. See the following code example:
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
- Set the extent of the export for which you are generating a world file. See the following code example.
//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
- Copy the data frame's rotation angle from the DisplayTransformation to the MapRotation property. See the following code example:
//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.
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
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 |