SpatialReference Parameters

Created:01/05/2001
Description:

This ArcMap sample illustrates how to change parameters for a Projected Coordinate System. The SpatialReferenceFactory is used to create a pre-defined "factory" projected coordinate system. Here, we're using a Sinusoidal projection. We shall modify the Central Meridan parameter within a For loop to give the impression that the Earth is rotating (in future releases of ArcGIS we can use an Orthographic projection for a more realistic visual effect).

The Central Meridian is modified within a loop that iterates 10 times, incrementing the Central Meridian parameter by 36 degrees each time. If more steps are used the result will be less "jerky" but the display time will take longer.

This is what you should see:

Search for esriSRParameterType within the online help for a list of all the available types of Parameters available. There are fifteen different types of parameters for projected coordinate systems, and eight different types of parameters for a geographic transformation. When retrieving parameters, define a receiving array to hold them with sixteen elements. Not all the array will be populated and it may contain empty elements, depending on which parameters are being used. The following tables show which array indices are used for each type of parameter:

Parameters for Projected Coordinate System:

IndexDescription
0False easting
1False northing
2Central meridian, Longitude of origin
3Standard parallel 1, Latitude of 1st point
4Standard parallel 2, Latitude of 2nd point
5Scale factor
6Central parallel, Latitude of origin
7Azimuth
8Longitude of 1st point
9Longitude of 2nd point
10Longitude of Centre
11Latitude of Centre
12X Scale
13Y Scale
14XY Plane Rotation

Parameters for Geographic Transformation:

IndexDescription
0X-axis translation
1Y-axis translation
2Z-axis translation
3X-axis rotation
4Y-axis rotation
5Z-axis rotation
6Scale difference
15Name of Dataset for Grid transformations

Two points to note:

  1. When using Visual Basic, retrieve the array of parameters by passing the first element of the array.

    Sub SpatialReferenceParameters()
    
      ' Start by getting a handle on the current FocusMap
      Dim pMxDoc As IMxDocument
      Set pMxDoc = Application.Document
    
      Dim pMap As IMap
      Set pMap = pMxDoc.FocusMap
    
      ' Use a SpatialReferenceFactory to create the Projected Coordinate System.
      ' Here we are using a Factory Code for the Sinusoidal projected coordinate system.
      ' Ideally we would use an Orthographic projection.  This will be available in a later release.
      Dim pSpatRefFact As ISpatialReferenceFactory2
      Set pSpatRefFact = New SpatialReferenceEnvironment
    
      Dim pProjCoordSys As IProjectedCoordinateSystem
      Set pProjCoordSys = pSpatRefFact.CreateProjectedCoordinateSystem(esriSRProjCS_World_Sinusoidal)
    
      'Now set the Map to use the coordsys
      Set pMap.SpatialReference = pProjCoordSys
    
      ' For maximum aesthetic effect, ensure map is at full extent
      pMxDoc.ActiveView.Extent = pMxDoc.ActiveView.FullExtent
    
      ' Now modify the Central Meridian so that the projection is based on a different
      ' meridian with each redraw - this gives a crude illustration of the earth spinning
    
      'Create an array of IParameters with 16 elements.
      Dim pParams(16) As IParameter
    
    
      'Pass the address of the first element of the array and get the parameters
      pProjCoordSys.GetParameters pParams(0)
    
      ' iterate through the array of Parameters and print them out
      Dim pParam As IParameter
    
      Dim i As Integer
      For i = 0 To 15
        Set pParam = pParams(i)
        If Not (pParam Is Nothing) Then
          Debug.Print pParam.Name, pParam.Index, pParam.Value
        End If
      Next i
    
      'Get the Central Meridian Parameter
      Set pParam = pParams(2)
     
      ' Loop through 360 degrees in steps of 10.  The more steps, the less jerky it will
      ' be, but the faster your machine needs to be!
      Dim j As Integer
      For j = 0 To 10
        'set the new value, make it negative so that the earth spins West to East
        pParam.Value = pParam.Value - 36
        'tell the projected coordinate system that it has changed
        pProjCoordSys.Changed
        
        'Now refresh the map
        DoEvents
        pMxDoc.ActiveView.PartialRefresh esriViewGeography, Nothing, Nothing
      Next j
    
    End Sub
    
  2. After a parameter has been changed, you must notify the Projected Coordinate System by calling "Changed".


How to use:
  1. This sample uses shape files that, depending on your installation, can be found in the following folder:

    C:\ArcGIS\arcexe83\ArcObjects Developer Kit\Samples\Data\World

    File NameDescriptionShapeTypeCoordinate System
    dissolveCntryCountries dissolved into continentsPolygonUnprojected WGS1984 Geographicals
    world30LatLon for the worldPolygonUnprojected WGS1984 Geographicals

  2. Start ArcMap.

  3. Add a feature layer - browse and add dissolveCntry. As this is the first layer to be added, the Map display will use the same Spatial Reference that is associated with this layer, i.e. WGS1984 Geographicals, which means that the display is currently unprojected.

  4. Add the World30 shape file. Ensure that it goes underneath the dissolveCntry feature layer
  5. Add a new ArcMap Macro called SpatialReferenceParameters and in the VBA editor, paste the following code into it.
  6. Run the Macro. You will see that the country feature layers are now projected, with the appearance of the Earth spinning


Sub SpatialReferenceParameters()

  ' Start by getting a handle on the current FocusMap
  Dim pMxDoc As IMxDocument
  Set pMxDoc = Application.Document

  Dim pMap As IMap
  Set pMap = pMxDoc.FocusMap

  ' Use a SpatialReferenceFactory to create the Projected Coordinate System.
  ' Here we are using a Factory Code for the Sinusoidal projected coordinate system.
  ' Ideally we would use an Orthographic projection.  This will be available in a later release.
  Dim pSpatRefFact As ISpatialReferenceFactory2
  Set pSpatRefFact = New SpatialReferenceEnvironment

  Dim pProjCoordSys As IProjectedCoordinateSystem
  Set pProjCoordSys = pSpatRefFact.CreateProjectedCoordinateSystem(esriSRProjCS_World_Sinusoidal)

  'Now set the Map to use the coordsys
  Set pMap.SpatialReference = pProjCoordSys

  ' For maximum aesthetic effect, ensure map is at full extent
  pMxDoc.ActiveView.Extent = pMxDoc.ActiveView.FullExtent

  ' Now modify the Central Meridian so that the projection is based on a different
  ' meridian with each redraw - this gives a crude illustration of the earth spinning

  'Create an array of IParameters with 16 elements.
  Dim pParams(16) As IParameter


  'Pass the address of the first element of the array and get the parameters
  pProjCoordSys.GetParameters pParams(0)

  ' iterate through the array of Parameters and print them out
  Dim pParam As IParameter

  Dim i As Integer
  For i = 0 To 15
    Set pParam = pParams(i)
    If Not (pParam Is Nothing) Then
      Debug.Print pParam.Name, pParam.Index, pParam.Value
    End If
  Next i

  'Get the Central Meridian Parameter
  Set pParam = pParams(2)
 
  ' Loop through 360 degrees in steps of 10.  The more steps, the less jerky it will
  ' be, but the faster your machine needs to be!
  Dim j As Integer
  For j = 0 To 10
    'set the new value, make it negative so that the earth spins West to East
    pParam.Value = pParam.Value - 36
    'tell the projected coordinate system that it has changed
    pProjCoordSys.Changed
    
    'Now refresh the map
    DoEvents
    pMxDoc.ActiveView.PartialRefresh esriViewGeography, Nothing, Nothing
  Next j

End Sub