arcgissamples\geometry\CreateCustomGeographicXformation.java
/* Copyright 2010 ESRI * * All rights reserved under the copyright laws of the United States * and applicable international laws, treaties, and conventions. * * You may freely redistribute and use this sample code, with or * without modification, provided you include the original copyright * notice and use restrictions. * * See the use restrictions. * */ package arcgissamples.geometry; import com.esri.arcgis.geometry.CoordinateFrameTransformation; import com.esri.arcgis.geometry.IGeoTransformationOperationSet; import com.esri.arcgis.geometry.IGeographicCoordinateSystem; import com.esri.arcgis.geometry.IProjectedCoordinateSystem; import com.esri.arcgis.geometry.SpatialReferenceEnvironment; import com.esri.arcgis.geometry.esriSRProjCSType; import com.esri.arcgis.geometry.esriTransformDirection; import com.esri.arcgis.system.AoInitialize; import com.esri.arcgis.system.EngineInitializer; import com.esri.arcgis.system.esriLicenseProductCode; import com.esri.arcgis.system.esriLicenseStatus; public class CreateCustomGeographicXformation { public CreateCustomGeographicXformation() { } public static void main(String[] args) { try { EngineInitializer.initializeEngine(); AoInitialize aoInit = new AoInitialize(); initializeArcGISLicenses(aoInit); SpatialReferenceEnvironment sre = new SpatialReferenceEnvironment(); // The key to understanding this is that all projected coordinate system IDs are // found in the esriSRProjCSType static class... IProjectedCoordinateSystem proj1 = sre.createProjectedCoordinateSystem(esriSRProjCSType.esriSRProjCS_PeruCentral); IProjectedCoordinateSystem proj2 = sre.createProjectedCoordinateSystem(esriSRProjCSType.esriSRProjCS_WGS1984UTM_38N); // Create a coordinateframetransformation CoordinateFrameTransformation cft = new CoordinateFrameTransformation(); cft.putParameters(1.234, -2.345, 658.3, 4.3829, -2.48591, 2.18943, 2.48585); cft.setName("Custom Geotrans"); // Retrieve the geographic coordinate systems from the two projected coordinate systems IGeographicCoordinateSystem gcs1 = proj1.getGeographicCoordinateSystem(); IGeographicCoordinateSystem gcs2 = proj2.getGeographicCoordinateSystem(); cft.putSpatialReferences(gcs1, gcs2); /* * The SpatialReferenceEnvironment has a GeoTransformationOperationSet that you * can use to maintain a list of active geographic transformations. * * Note: Once you add a geographic transformation to the operation set, FeatureDataConverter can access the * transformations. Add the transformation to the operation set */ IGeoTransformationOperationSet set = sre.getGeoTransformationDefaults(); // Always add a geographic transformation in both directions. set.set(esriTransformDirection.esriTransformForward, cft); set.set(esriTransformDirection.esriTransformReverse, cft); // Done. There is nothing of interest produced from this program, other than // The demonstration of a coding practice System.out.println("Done!"); aoInit.shutdown(); } catch (Exception e) { e.printStackTrace(); } } /** * Initializes the lowest available ArcGIS License */ private static void initializeArcGISLicenses(AoInitialize aoInit) { try { if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngine) == esriLicenseStatus.esriLicenseAvailable) { aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine); } else if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeArcView) == esriLicenseStatus.esriLicenseAvailable) { aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeArcView); } else { System.err.println("Could not initialize an Engine or ArcView license. Exiting application."); System.exit(-1); } } catch (Exception e) { e.printStackTrace(); } } }