The CoordinateSystem.DatumTransformationAdd method adds a datum transformation to the current drawing. If the datum transformation (the from and to coordinate systems) already exists, it is overwritten. This method will return the added datum transformation definition.
Note:
Datum transformations cannot be added when the drawing contains web feature layers.
Declaration
public Dictionary<string, object> Esri.ArcGISForAutoCAD.CoordinateSystem.DatumTransformationAdd(Document doc, string fromCS, string toCS, IEnumerable<(string Direction, string Step)> transformationSteps)
Parameters
| Type | Name | Description | Required |
|---|---|---|---|
Document | doc | The AutoCAD document to act on. | required |
string | fromCS | The valid well-known coordinate system ID (WKID) or well-known text (WKT) of the Esri coordinate system as a string. | required |
string | toCS | The valid WKID or WKT of the Esri coordinate system as a string. | required |
IEnumerable<(string Direction, string Step)> | transformationSteps | A collection of named tuples in which the first value is the Direction value and the second value is the Step value. The Direction value is the direction of the step, either "Forward" or "Reverse", to which the transformation step will be applied. The Step value is the WKID or WKT of the transformation step as a string. | required |
Returns
| Type | Description |
|---|---|
Dictionary<string, object> | The definition of the added datum transformation as a dictionary. The dictionary has the following keys: From, To, and Steps. The From and To keys have string values representing the coordinate systems. The value of the Steps key is a collection of dictionaries of coordinate system transformation steps. Each transformation step dictionary has the Step and Direction keys. The Step key has a value of the step as a string, and the Direction key indicates the order the transformation step is applied, either "Forward" or "Reverse". |
Remarks on error conditions
This method may throw an exception or return null if a parameter is invalid or web feature layers are present in the drawing.
Usage
When creating a composite datum transformation, the order of each step must be correct. For Example 2 below, 108355 is the first step and 108282 is the second and final step. The direction must be provided as "Forward" or "Reverse".
ArcGIS for AutoCAD does not validate the provided transformation steps. If any portion of the set method is invalid or applied in the wrong order, ArcGIS for AutoCAD may draw layers incorrectly.
Example 1
Add a single step datum transformation to the current drawing between the from and to coordinate systems denoted by the WKID, applied in the forward order, and print its datum transformation definition.// Initialize
var doc = Application.DocumentManager.MdiActiveDocument;
// Add the datum transformation
var transformationSteps = new List<(string, string)> { ("Forward", "1580") };
var newDT = Esri.ArcGISForAutoCAD.CoordinateSystem.DatumTransformationAdd(doc, "2882", "3857", transformationSteps);
// Print the datum transformation definition
doc.Editor.WriteMessage("\nFrom {0}: To {1}", newDT["From"], newDT["To"]);
doc.Editor.WriteMessage("\n");
foreach (var dict in newDT["Steps"] as List<Dictionary<string, object>>)
{
foreach (var kvp in dict)
{
doc.Editor.WriteMessage("\t{0}: {1}\n", kvp.Key, kvp.Value.ToString());
}
}
/* Example output
From 2882: To 3857
Direction: Forward
Step: 1580
*/
Example 2
Add a composite datum transformation to the current drawing between the from and to coordinate systems denoted by the WKID, with steps applied in the reverse order, and print its datum transformation definition.// Initialize
var doc = Application.DocumentManager.MdiActiveDocument;
// Add the datum transformation
var transformationSteps = new List<(string, string)> { ("Reverse", "108355"), ("Reverse", "108282") };
var newDT = Esri.ArcGISForAutoCAD.CoordinateSystem.DatumTransformationAdd(doc, "6425", "3857", transformationSteps);
// Print the datum transformation definition
doc.Editor.WriteMessage("\nFrom {0}: To {1}", newDT["From"], newDT["To"]);
doc.Editor.WriteMessage("\n");
foreach (var dict in newDT["Steps"] as List<Dictionary<string, object>>)
{
foreach (var kvp in dict)
{
doc.Editor.WriteMessage("\t{0}: {1}\n", kvp.Key, kvp.Value.ToString());
}
}
/* Example output
From 6425: To 3857
Direction: Reverse
Step: 108355
Direction: Reverse
Step: 108282
*/
See also
esri_coordsys_DatumTransformations_set—An AutoLISP function that sets a datum transformation in the current drawing.