/********************************************************************** * $Id$ * * Name: example.java * Project: JGDAL. Interface java to gdal (Frank Warmerdam). * Purpose: Example code to test java interface of gdal. * 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 */ /** * Sections that correspond with GDAL Api Tutorial (publicated in * http://www.remotesensing.org:16080/gdal/gdal_tutorial.html) have * been marked. */ //Opening the file ---------------------------- import java.io.BufferedOutputStream; import java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import es.gva.cit.jgdal.Gdal; import es.gva.cit.jgdal.GdalBuffer; import es.gva.cit.jgdal.GdalColorEntry; import es.gva.cit.jgdal.GdalColorTable; import es.gva.cit.jgdal.GdalException; import es.gva.cit.jgdal.GdalRasterBand; import es.gva.cit.jgdal.GeoTransform; public class example{ public static void main(String[] args){ Gdal migdal=new Gdal(); try{ if(args.length>0){ migdal.open(args[0],Gdal.GA_ReadOnly); }else { System.out.println("You must introduce the file name"); System.exit(1); } }catch(Exception ge){ ge.printStackTrace(); //........... } //End Opening the file ---------------------------- GdalRasterBand mirasterband=null; GdalRasterBand mioverview=null; FileOutputStream s=null; DataOutputStream midataOS=null; BufferedOutputStream miBS=null; String st; int nxsize=0; int nysize=0; int rastercount=0; String rasterband; int xoverview=0; int yoverview=0; GeoTransform gt; int noverviews=0; //Getting dataset Information ---------------------------- try{ rastercount=migdal.getRasterCount(); nxsize = migdal.getRasterXSize(); nysize = migdal.getRasterYSize(); System.out.println("N BANDAS="+rastercount+" SIZEX="+nxsize+" SIZEY="+nysize); System.out.println(migdal.getProjectionRef()); }catch(GdalException 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(); //........... } //End Getting dataset Information ---------------------------- try{ File mifichero = new File("exit.raw"); s = new FileOutputStream(mifichero); }catch(Exception e){} for(int iBand=0;iBand= 0) System.out.println("NoData="+noData); String[] metadata = mirasterband.getMetadata(); if(metadata.length > 0){ System.out.println("-METADATA-"); for(int i=0;i"+iBand); //Información de overview try{ if(noverviews>0){ //Muestra el tamaño de cada overview y selecccionamos el 0 for(int t=0;t 0){ System.out.println("-METADATA-"); System.out.println("Number of values:"+metadata.length); for(int i=0;i