Suppose given a point (IPoint) in some coordinate system. Required to transform it to another coordinate system. If both of coordinate systems are predefined, we can use IGeometry2.ProjectEx with transformation specified by corresponded constant from esriSRGeoTransformationType, esriSRGeoTransformation2Type, or esriSRGeoTransformation3Type enumerations.
The code looks like (source)
package arcgissamples.geometry;
import com.esri.arcgis.geometry.*;
import com.esri.arcgis.system.*;
public class ProjectGeometry {
public static void main(String[] args) {
try {
EngineInitializer.initializeEngine();
AoInitialize aoInit = new AoInitialize();
// Create a point with Geographic coordinates...
Point point = new Point();
point.putCoords(-100.0, 40.0);
System.out.println("");
System.out.println("Original coordinates: " + point.getX() + ","
+ point.getY());
// Create the SpatialReferenceEnvironment...
SpatialReferenceEnvironment spatialReferenceEnvironment = new SpatialReferenceEnvironment();
// Apply the initial spatial reference...
ISpatialReference geographicCoordinateSystem = spatialReferenceEnvironment
.createGeographicCoordinateSystem(esriSRGeoCSType.esriSRGeoCS_NAD1927);
point.setSpatialReferenceByRef(geographicCoordinateSystem);
// Create the output projected coordinate system...
ISpatialReference projectedCoordinateSystem = spatialReferenceEnvironment
.createProjectedCoordinateSystem(esriSRProjCSType.esriSRProjCS_NAD1983UTM_13N);
// Create the GeoTransformation...
//***************************************************
// !!!! How to define arg for createGeoTransformation??
IGeoTransformation iGeoTransformation = (IGeoTransformation) spatialReferenceEnvironment
.createGeoTransformation(esriSRGeoTransformationType.esriSRGeoTransformation_NAD1927_To_WGS1984_5);
// Project the point...
point.projectEx(projectedCoordinateSystem, esriTransformDirection.esriTransformForward,
iGeoTransformation, false, 0.0, 0.0);
System.out.println("Projected coordinates: " + point.getX() + " , "
+ point.getY());
System.out.println("Done!");
aoInit.shutdown();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
But problem is that both original coordinate system and output coordinate system are defining at the time of program execution. So I need a function to define constant for ISpatialReferenceFactory.CreateGeoTransformation method like
int defineTransformationType(ISpatialReference srcCoordSystem, ISpatialReference destCoordSys)
Is it possible? And how to implement this function?