Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Instead of creating a geotransformation, I would try finding one. This can be done by looping through all the predefined geotransformations via CreatePredefinedGeographicTransformations and checking to see if the input and output spatialreferenceID's match the GCS's of your spatialreferences. See code here.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.