arcgissamples\raster\BuildPyramids.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 BuildPyramids { public static void main(String[] args) { System.out.println("Starting BuildPyramids - 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 path = devKitHome + File.separator + "java" + File.separator + "samples" + File.separator + "data" + File.separator + "raster"; String name = "dem1"; BuildPyramids thisSampleApp = new BuildPyramids(); thisSampleApp.buildPyramids(path, name); aoInit.shutdown(); } catch (Exception e) { e.printStackTrace(); } } /** * Create a reduced-resolution dataset (pyramid) on a raster dataset. * * @param path * path to raster dataset on disk * @param name * raster dataset name * @throws IOException * if couldn't create the pyramid */ private void buildPyramids(String path, String name) throws IOException { RasterDataset rasterDataset = null; // Get a raster dataset upon which to create the reduced-resolution dataset, by calling create, // which is from the IRasterPyramids interface. System.out.println("Opening raster data..."); try { 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 data."); throw e; } // Check that the rasterdataset doesn't already have a pyramid, if (rasterDataset.isPresent()) { System.out.println("Reduced-resolution dataset already exists for " + rasterDataset.getCompleteName()); } System.out.println("Creating reduced-resolution dataset ..."); try { rasterDataset.create(); } catch (IOException e) { System.out.println("Couldn't create reduced-resolution dataset."); throw e; } System.out.println("Done creating reduced-resolution dataset for " + rasterDataset.getCompleteName()); } /** * 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); } } catch (Exception e) { e.printStackTrace(); } } }