Select to view content in your preferred language

How do I modify automatic coordinate transformation in ArcMap?

935
8
11-29-2010 11:54 AM
BobCave
Emerging Contributor
When loading layers, ArcMap will automatically transform input coordinates to the coordinate system currently defined on the data frame.  As part of this process, ArcMap may display a dialog that asks the user which datum transformation to use.  We have a requirement to implement an extension that will automate the selection of the datum transformation based on the source and target coordinate systems and the bounds of the data.

To this end, I need a mechanism to get access to the process before ArcMap performs the automatic transformation so that I can modify the IGeoTransformation parameters, but I have not been able to find an event or other way to do this.  I tried hooking up the IActiveViewEvents.ItemAdded event, but that gets fired after the transformation has already taken place.

Is there an event that will allow me to change the IGeoTransformation definition before ArcMap performs its transformation?  If so, a pointer to an example or a code snippet would be greatly appreciated (I will be using C#).

Thanks,

Bob
0 Kudos
8 Replies
Venkata_RaoTammineni
Regular Contributor
Hi,

  Please find below code that might help you...


private void Transform()
{
    ISpatialReferenceFactory2 spatialReferenceFactory2 = new
        SpatialReferenceEnvironmentClass();

    //Mean for Great Britain.
    IGeoTransformation geoTransformation =
        spatialReferenceFactory2.CreateGeoTransformation((int)
        esriSRGeoTransformationType.esriSRGeoTransformation_OSGB1936_To_WGS1984_1)as
        IGeoTransformation;

    ISpatialReference fromSpatialReference;
    ISpatialReference toSpatialReference;
    geoTransformation.GetSpatialReferences(out fromSpatialReference, out
        toSpatialReference);

    System.Windows.Forms.MessageBox.Show(geoTransformation.Name);
    System.Windows.Forms.MessageBox.Show(fromSpatialReference.Name + ", " +
        toSpatialReference.Name);
}


Thanks and Regards,

Venkat
0 Kudos
BobCave
Emerging Contributor
Thanks, Venkat.

Is there an event that fires before ArcMap starts the automatic transformation?
Is this automatic transformation done using a geoprocessor?  If so, how do I get access to the geoprocessor so I can handle its ToolExecuting event? 

I'm looking for something that will allow me to hook into ArcMap in order to possibly update the IGeoTransformation before the input features get transformed to the data frame's coordinate system.

Thanks,

Bob
0 Kudos
Venkata_RaoTammineni
Regular Contributor
hi,

  Before start arcmap...you need to change coordinate system...means  you need to go for stand alone application ...from that you can play something before....but your using arcmap and you are looking for plugin.. i dont think it is possible for start arcmap...

There is one option in VBA.you can look that option i think...

Private Function MxDocument_OpenDocument() As Boolean

End Function

Something like that...

Thanks and Regards,

Venkat
0 Kudos
MelitaKennedy
Esri Notable Contributor
Thanks, Venkat.

Is there an event that fires before ArcMap starts the automatic transformation?
Is this automatic transformation done using a geoprocessor?  If so, how do I get access to the geoprocessor so I can handle its ToolExecuting event? 

I'm looking for something that will allow me to hook into ArcMap in order to possibly update the IGeoTransformation before the input features get transformed to the data frame's coordinate system.

Thanks,

Bob


I don't know if there's an event, but part of what you're looking for is IMapGeographicTransformations. See VBA (sorry!) below on how to change the default transformation loaded upon opening a new map document. Only NAD_1927_To_NAD_1983_NADCON is loaded by default.


Private Function MXDocument_NewDocument() as Boolean

   ' 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

   Dim pSpRFc As SpatialReferenceEnvironment
   Set pSpRFc = New SpatialReferenceEnvironment

   Dim pAlaskaNADCON As IGeoTransformation
   set pAlaskaNADCON = pSpRFc.CreateGeoTRansformation(esriSRGeoTransformation_NAD_1927_TO_NAD_1983_AK)    

'  Add the transformation to the operation set
   Dim pGTSet As IGeoTransformationOperationSet
   Set pGTSet = New GeoTransformationOperationSet

'  The Map uses IMapGeographicTransformations to access the geogtrans
   Dim pMapGeo As IMapGeographicTransformations
   Set pMapGeo = pMap
   Set pGTSet = pMapGeo.GeographicTransformations

   pGTSet.Set esriTransformForward, pAlaskaNADCON
   pGTSet.Set esriTransformReverse, pAlaskaNADCON

End Function



Melita
0 Kudos
BobCave
Emerging Contributor
Thanks, Melita.  That info looks promising.

A couple of questions:

1) In your example, you say that only NAD_1927_To_NAD_1983_NADCON is loaded by default, then the code adds NAD_1927_TO_NAD_1983_AK to the collection.  Does this replace the original NAD_1927_To_NAD_1983 transformation, or add a second one?  If it adds a second one, how does ArcMap determine which one to use when converting from NAD27 to NAD83?  Does it prompt the user?

2) Will changes to the geographic transformation list is be saved with the map document?

Cheers,

Bob
0 Kudos
MelitaKennedy
Esri Notable Contributor
Thanks, Melita.  That info looks promising.

A couple of questions:

1) In your example, you say that only NAD_1927_To_NAD_1983_NADCON is loaded by default, then the code adds NAD_1927_TO_NAD_1983_AK to the collection.  Does this replace the original NAD_1927_To_NAD_1983 transformation, or add a second one?  If it adds a second one, how does ArcMap determine which one to use when converting from NAD27 to NAD83?  Does it prompt the user?

2) Will changes to the geographic transformation list is be saved with the map document?

Cheers,

Bob


Hi Bob,

I'm sorry that I wasn't clearer.

1) Only one transformation per pair of GCS is allowed, so the Alaska transformation will replace the "NADCON" (actually for contiguous US, the lower 48).

2) Yes, the GeographicTransformationOperationSet is saved in the map document.

Melita
0 Kudos
BobCave
Emerging Contributor
Thanks, Melita.  Just a couple more questions:

1) Is it possible to store the geographic transformation on the layer, rather than on the map, so that each layer could use a different transformation?  I looked through the documentation and I didn't see anything, so I suspect the answer is 'no', but I thought I would ask anyway.

2) Can I create an IGeoTransformation using an EPSG code instead of the ESRI code, or map an EPSG code to its associated ESRI code?  I tried to create a NAD83 to WGS84 NADCON transformation using the EPSG code, but I got an error saying that the code was not valid for a geographic transformation.  The documentation describes a method for creating a spatial reference from an EPSG code, but not a geographic transformation.

Thanks.

Bob
0 Kudos
MelitaKennedy
Esri Notable Contributor
Thanks, Melita.  Just a couple more questions:

1) Is it possible to store the geographic transformation on the layer, rather than on the map, so that each layer could use a different transformation?  I looked through the documentation and I didn't see anything, so I suspect the answer is 'no', but I thought I would ask anyway.

2) Can I create an IGeoTransformation using an EPSG code instead of the ESRI code, or map an EPSG code to its associated ESRI code?  I tried to create a NAD83 to WGS84 NADCON transformation using the EPSG code, but I got an error saying that the code was not valid for a geographic transformation.  The documentation describes a method for creating a spatial reference from an EPSG code, but not a geographic transformation.

Thanks.

Bob


Hi Bob,

1) No. We have had several people ask for that functionality, but haven't scheduled it for a software release yet.

2) ISpatialReferenceFactory:CreateGeoTransformation which takes an integer 'code'. Where we can, we use the EPSG codes for our well-known IDs/codes. If you use an EPSG code and the object isn't created (using the appropriate function), we don't support it yet. We also have macros, or enumerations, under esriSR<objtype>. There's some code on GeoTransformationOperationSet here:

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/How_to_use_the_IGeoTran...

Hope this helps!
Melita
0 Kudos