/********************************************************************** * $Id$ * * Name: writetif.java * Project: gvSIG - Generalitat Valenciana SIG * Purpose: Escribe una imágen en formato geotiff a partir de otra en * otro formato. Los parámetros necesarios son imágen fuente, ancho * y alto de la escena a convertir. * java Writetif imagen_src.sid 2000 1500 * 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.jgdal.*; import es.gva.cit.jogr.*; public class Writetif{ public static void main(String[] args){ Gdal migdal=new Gdal(); Gdal dset_dstno=null; GeoTransform gt=null; int ancho=0,alto=0; GdalRasterBand mirasterband=null; GdalRasterBand rband=null; int nxsize=0; int nysize=0; int rastercount=0; float total=0; try{ if(args.length==3){ migdal.open(args[0],Gdal.GA_ReadOnly); ancho=Integer.parseInt(args[1]); alto=Integer.parseInt(args[2]); }else { System.out.println("Params: filename Xsize Ysize"); System.exit(1); } }catch(Exception ge){ ge.printStackTrace(); //... } try{ gt=migdal.getGeoTransform(); System.out.println("Origin = ("+gt.adfgeotransform[0]+","+gt.adfgeotransform[3]+")"); System.out.println("Pixel Size = ("+gt.adfgeotransform[1]+","+gt.adfgeotransform[5]+")"); }catch(GdalException e){ System.out.println("I can't obtain the array geoTransform for this image"); e.printStackTrace(); //........... } try{ rastercount=migdal.getRasterCount(); nxsize = migdal.getRasterXSize(); nysize = migdal.getRasterYSize(); System.out.println("N BANDAS="+rastercount+" SIZEX="+nxsize+" SIZEY="+nysize); System.out.println("WINDOWX="+ancho+" WINDOWY="+alto); System.out.println(migdal.getProjectionRef()); int ngcp=migdal.getGCPCount(); System.out.println("NGCP="+ngcp); }catch(GdalException ge){ ge.printStackTrace(); //... } try{ //Obtenemos el driver y creamos el dataset del destino GdalDriver drv=Gdal.getDriverByName("GTiff"); String[] params={"TILED=YES","PHOTOMETRIC=RGB","TFW=WORLDFILE"}; dset_dstno=drv.create("salidatif.tif",ancho,alto,rastercount,Gdal.GDT_Byte,null); //Añadimos la información de proyección (esta es de ejemplo. Hay que formatear la de la imágen de entrada) OGRSpatialReference oSRS=new OGRSpatialReference(); oSRS.setUTM(11,true); oSRS.setWellKnownGeogCS("NAD27"); System.out.println("Nueva Proyección ==> "+oSRS.exportToWkt()); dset_dstno.setProjection(oSRS.exportToWkt()); //Añadimos el vector geoTransform de la imagén fuente a la de destino dset_dstno.setGeoTransform(gt); GdalBuffer buf=null; for(int iBand=0;iBand