From: Dinesh D. S. <sdi...@gm...> - 2012-02-28 06:29:27
|
Hi, I am trying to develop a web service using gdaltransform utility that fetches a particular portion of image from the entire coverage. The Java code is being developed in eclipse IDE and successfully built by importing necessary libraries from geotools. But when I try to create the web service with that code, it's showing an error message '' The service class 'org.geotools.rawimg.GetrawImage' does not comply to one or more requirements of the JAX-RPC-1.1 specification''. The code is attached below. Please help me resolving this issue. Thanks. ------------------------- CODE ----------------------- /** * */ package org.geoserver.wps.gs.rawimg; import java.awt.Rectangle; import java.awt.image.RenderedImage; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; import javax.imageio.ImageIO; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.ExecTask; import org.apache.tools.ant.types.Commandline; import org.geotools.coverage.grid.GridCoverage2D; import org.opengis.referencing.crs.CoordinateReferenceSystem; import com.vividsolutions.jts.geom.Envelope; /** * @author dinesh * */ public class GetrawImage { private final static String SYSTEM_TEMP_DIR = System.getProperty("java.io.tmpdir"); private final static int TEMP_DIR_ATTEMPTS = 5; // Default Constructor public GetrawImage() { } public RenderedImage execute(GridCoverage2D coverage, throws IOException { Envelope bbox, CoordinateReferenceSystem crs) /* Integer width, Integer height) throws IOException {*/ /*GeoTiffReader reader = null; List<File> removeFiles = new ArrayList<File>();*/ // Getting the raw dataset // create image files RenderedImage renderedImage = coverage.getRenderedImage(); // create temp folder // File tempFolder = initFolder(TEMP_DIR); File tempFolder = createTempDir(); // String filePath = System.getProperty("catalina.base") + File.separator + "temp"; String filePath = tempFolder.getAbsolutePath(); // Create Input and output filepath String inputFilePath = filePath + File.separator + "inputFile." + "tif"; String outputFilePath = filePath + File.separator + "outputFile." /* + outputFormat.toLowerCase(); */ + "tif"; File inputFile = new File(inputFilePath); File outputFile = new File(outputFilePath); // File result = new File(filePath); inputFile.createNewFile(); outputFile.createNewFile(); try { /*ImageIO.write(renderedImage, inputFormat, inputFile);*/ ImageIO.write(renderedImage, "tif", inputFile); } catch (IOException e) { throw e; } // Creating the input and output text files containing user AOI to be given as arguments to gdaltransform String inputAoiPath = filePath + File.separator + "inputAOI." + "txt"; String outputAoiPath = filePath + File.separator + "outputAOI." + "txt"; File inputAoi = new File(inputAoiPath); File outputAoi = new File(outputAoiPath); inputAoi.createNewFile(); outputAoi.createNewFile(); Writer aoiWrite = new BufferedWriter(new FileWriter(inputAoi)); try { aoiWrite.write(bbox.getMinX() + " " + bbox.getMinY() + "\n" + bbox.getMaxX() + " " + bbox.getMaxY()); aoiWrite.close(); } catch (IOException e) { throw e; } // Building gdaltransform command with arguments String argument = "-i -rpc -to \"Method=RPC\"" + inputFilePath + "<" + inputAoiPath + ">" + outputAoiPath; String arguments[] = new String[1]; arguments[0] = argument; String gdalCommand = "gdaltransform " + argument; // Execute gdaltransform command and the resulting AOI in pixel/line is stored in outputAoi Project project = new Project(); project.init(); ExecTask execTask = new ExecTask(); execTask.setProject(project); Commandline command = new Commandline(gdalCommand); // command.addArguments(arguments); execTask.setCommand(command); execTask.execute(); inputAoi.delete(); // Delete inputAoi file // Extract the user AOI in the image using information from outputAoi BufferedReader aoiRead = new BufferedReader(new FileReader(outputAoi)); String str; int coordinates[] = new int[4]; int i = 0; int index; try { while ((str = aoiRead.readLine()) != null) { index = str.indexOf(' '); coordinates[i] = (int) Float.valueOf(str.substring(0, index-1)).floatValue(); coordinates coordinates[i+1] = (int) Float.valueOf(str.substring(index+1)).floatValue(); coordinates i++; } aoiRead.close(); } catch (IOException e) { throw e; } outputAoi.delete(); //Delete outputAoi file int width = Math.abs(coordinates[0]-coordinates[2]);// Pixel int height = Math.abs(coordinates[1]-coordinates[3]);// Line RenderedImage result = (RenderedImage) renderedImage.getData(new Rectangle(coordinates[0],coordinates[1],width,height)); return result; } /** * Create temporary directory */ public static File createTempDir() { File baseDir = new File(SYSTEM_TEMP_DIR); String baseName = System.currentTimeMillis() + "-"; for (int counter = 0; counter < TEMP_DIR_ATTEMPTS; counter++) { File tempDir = new File(baseDir, baseName + counter); if (tempDir.mkdir()) { return tempDir; } } throw new IllegalStateException("Failed to create directory within " + TEMP_DIR_ATTEMPTS + " attempts (tried " + baseName + "0 to " + baseName + (TEMP_DIR_ATTEMPTS - 1) + ')'); } } -- Regards, S.Dinesh Dass, M.Tech - Remote Sensing, Institute of Remote Sensing, Anna University, Chennai. Mob: +91-9976033932 |