/********************************************************************** * $Id$ * * Name: SidToTif.java * Project: * Purpose: Convierte una imágen MrSID en Tiff utilizando para la lectura * el wrapper jni-mrsid y para la escritura jni-gdal. Para el * funcionamiento de este ejemplo es necesaria tambien la libreria * jmrsid.dll/libjmrsid.so.x.x.x así como las librerias de mrsid. * Author: Nacho Brodin, brodin_ign@gva.es * **********************************************************************/ /* gvSIG. Sistema de Información Geográfica de la Generalitat Valenciana * * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. * * For more information, contact: * * Generalitat Valenciana * Conselleria d'Infraestructures i Transport * Av. Blasco Ibáñez, 50 * 46010 VALENCIA * SPAIN * * +34 963862235 * gvsig@gva.es * www.gvsig.gva.es * * or * * IVER T.I. S.A * Salamanca 50 * 46005 Valencia * Spain * * +34 963163400 * dac@iver.es */ import es.gva.cit.jmrsid.*; import es.gva.cit.jgdal.*; public class SidToTif { public static void main(String[] args){ Gdal dset_dstno; GdalRasterBand rband=null; Gdal migdal=new Gdal(); LTIImageReader img; LTIPixel pixel; int eColorSpace, nBands, eSampleType; int tamx=Integer.parseInt(args[1]); int tamy=Integer.parseInt(args[2]); int siz = tamx * tamy * 1; try{ img = new MrSIDImageReader(args[0]); img.initialize(); int overviews=((MrSIDImageReader)img).getNumLevels()-1; System.out.println("Overviews="+overviews); System.out.println("Width="+img.getWidth()); System.out.println("Height="+img.getHeight()); System.out.println("Stripsheigth="+img.getStripHeight()); nBands=img.getNumBands(); System.out.println("NumBands="+nBands); eColorSpace=img.getColorSpace(); System.out.println("ColorSpace="+eColorSpace); eSampleType=img.getDataType(); System.out.println("DataType="+eSampleType); pixel=new LTIPixel(eColorSpace, nBands, eSampleType); int[] dimsAtMag=img.getDimsAtMag(0.5); System.out.println("Dims At Mag 0,5="+dimsAtMag[0]+" "+dimsAtMag[1]); //Acceso a la información de georeferenciación LTIGeoCoord geoc = img.getGeoCoord(); System.out.println("X="+geoc.getX()); System.out.println("Y="+geoc.getY()); System.out.println("XRes="+geoc.getXRes()); System.out.println("YRes="+geoc.getYRes()); System.out.println("XRot="+geoc.getXRot()); System.out.println("YRot="+geoc.getYRot()); //Fin de acceso a la información de georeferenciación System.out.println("************************************"); LTIScene scene = new LTIScene(0,0,tamx,tamy,1.0); LTISceneBuffer buffer = new LTISceneBuffer(pixel, tamx, tamy, true); ((LTIImageStage)img).read(scene,buffer); GdalDriver drv=Gdal.getDriverByName("GTiff"); String[] params={"TILED=YES","PHOTOMETRIC=RGB","TFW=WORLDFILE"}; dset_dstno=drv.create("SiToTif.tif",tamx,tamy,3,Gdal.GDT_Byte,null); GdalBuffer b=new GdalBuffer(); b.buffByte=buffer.buf1; rband=dset_dstno.getRasterBand(1); rband.writeRaster(0,0, tamx, tamy, b,Gdal.GDT_Byte); b.buffByte=buffer.buf2; rband=dset_dstno.getRasterBand(2); rband.writeRaster(0,0, tamx, tamy, b,Gdal.GDT_Byte); b.buffByte=buffer.buf3; rband=dset_dstno.getRasterBand(3); rband.writeRaster(0,0, tamx, tamy, b,Gdal.GDT_Byte); dset_dstno.close(); }catch(Exception e){ e.printStackTrace(); } } }