arcgissamples\raster\CreateWorldFile.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. * */ /* 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 at <your ArcGIS install location>/DeveloperKit10.0/userestrictions.txt. * */ package arcgissamples.raster; import java.io.File; import java.io.IOException; import com.esri.arcgis.datasourcesraster.RasterDataset; import com.esri.arcgis.datasourcesraster.RasterWorkspace; import com.esri.arcgis.datasourcesraster.RasterWorkspaceFactory; import com.esri.arcgis.system.AoInitialize; import com.esri.arcgis.system.EngineInitializer; public class CreateWorldFile { public CreateWorldFile() { } public static void main(String[] args) { System.out.println("Starting CreateWorldFile - An ArcObjects Java SDK Developer Sample"); try { // Initialize the engine and licenses. EngineInitializer.initializeEngine(); AoInitialize aoInit = new AoInitialize(); initializeArcGISLicenses(aoInit); //Get DEVKITHOME Home String devKitHome = System.getenv("AGSDEVKITJAVA"); String inPath = devKitHome + "java" + File.separator + "samples" + File.separator + "data" + File.separator + "raster" ; CreateWorldFile create = new CreateWorldFile(); create.createWorldFile(inPath, "dem1"); aoInit.shutdown(); } catch (Exception e) { e.printStackTrace(); } } /** * Export a raster dataset's georeference information to a world file. * * @param path * path to raster dataset on disk * @param name * raster dataset name * @throws IOException * if couldn't create a world file from the input raster data */ private void createWorldFile(String path, String name) throws IOException { RasterDataset rasterDataset = null; try { // Get a raster dataset so as to create the world file, by calling // write(), which is defined in the IWorldFileExport interface which is // implemented by RasterDataset. RasterWorkspaceFactory rasterWorkspaceFactory = new RasterWorkspaceFactory(); RasterWorkspace rasterWorkspace = new RasterWorkspace(rasterWorkspaceFactory.openFromFile(path, 0)); rasterDataset = (RasterDataset) rasterWorkspace.openRasterDataset(name); } catch (IOException e) { System.out.println("Couldn't access raster dataset."); throw e; } try { rasterDataset.write(); System.out.println("World File has been created for " + rasterDataset.getCompleteName()); } catch (IOException e) { System.out.println("Couldn't create world file."); throw e; } } /** * Initializes the lowest available ArcGIS License */ static void initializeArcGISLicenses(AoInitialize ao) { try { if (ao.isProductCodeAvailable(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngine) == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable) ao.initialize(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngine); else if (ao.isProductCodeAvailable(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeArcView) == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable) ao.initialize(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeArcView); else if (ao.isProductCodeAvailable(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeArcEditor) == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable) ao.initialize(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeArcEditor); else if (ao.isProductCodeAvailable(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeArcInfo) == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable) ao.initialize(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeArcInfo); else { System.err.println("Could not initialize an Engine, ArcView, ArcEditor, or ArcInfo license. Exiting application."); System.exit(-1); } ao.checkOutExtension(com.esri.arcgis.system.esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst); } catch (Exception e) { e.printStackTrace(); } } }