svn-gvsig-desktop / tags / v1_1_2_Build_1043 / libraries / libjni-gdal-macosx / src-test / SidToTif.java @ 33768
History | View | Annotate | Download (4.39 KB)
1 | 8219 | nacho | /**********************************************************************
|
---|---|---|---|
2 | * $Id$
|
||
3 | *
|
||
4 | * Name: SidToTif.java
|
||
5 | * Project:
|
||
6 | * Purpose: Convierte una im?gen MrSID en Tiff utilizando para la lectura
|
||
7 | * el wrapper jni-mrsid y para la escritura jni-gdal. Para el
|
||
8 | * funcionamiento de este ejemplo es necesaria tambien la libreria
|
||
9 | * jmrsid.dll/libjmrsid.so.x.x.x as? como las librerias de mrsid.
|
||
10 | * Author: Nacho Brodin, brodin_ign@gva.es
|
||
11 | *
|
||
12 | **********************************************************************/
|
||
13 | |||
14 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
15 | *
|
||
16 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
17 | *
|
||
18 | * This program is free software; you can redistribute it and/or
|
||
19 | * modify it under the terms of the GNU General Public License
|
||
20 | * as published by the Free Software Foundation; either version 2
|
||
21 | * of the License, or (at your option) any later version.
|
||
22 | *
|
||
23 | * This program is distributed in the hope that it will be useful,
|
||
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
26 | * GNU General Public License for more details.
|
||
27 | *
|
||
28 | * You should have received a copy of the GNU General Public License
|
||
29 | * along with this program; if not, write to the Free Software
|
||
30 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
31 | *
|
||
32 | * For more information, contact:
|
||
33 | *
|
||
34 | * Generalitat Valenciana
|
||
35 | * Conselleria d'Infraestructures i Transport
|
||
36 | * Av. Blasco Ib??ez, 50
|
||
37 | * 46010 VALENCIA
|
||
38 | * SPAIN
|
||
39 | *
|
||
40 | * +34 963862235
|
||
41 | * gvsig@gva.es
|
||
42 | * www.gvsig.gva.es
|
||
43 | *
|
||
44 | * or
|
||
45 | *
|
||
46 | * IVER T.I. S.A
|
||
47 | * Salamanca 50
|
||
48 | * 46005 Valencia
|
||
49 | * Spain
|
||
50 | *
|
||
51 | * +34 963163400
|
||
52 | * dac@iver.es
|
||
53 | */
|
||
54 | |||
55 | import es.gva.cit.jmrsid.*; |
||
56 | import es.gva.cit.jgdal.*; |
||
57 | |||
58 | |||
59 | public class SidToTif { |
||
60 | public static void main(String[] args){ |
||
61 | |||
62 | Gdal dset_dstno; |
||
63 | GdalRasterBand rband=null;
|
||
64 | Gdal migdal=new Gdal();
|
||
65 | |||
66 | LTIImageReader img; |
||
67 | LTIPixel pixel; |
||
68 | int eColorSpace, nBands, eSampleType;
|
||
69 | |||
70 | int tamx=Integer.parseInt(args[1]); |
||
71 | int tamy=Integer.parseInt(args[2]); |
||
72 | int siz = tamx * tamy * 1; |
||
73 | |||
74 | |||
75 | try{
|
||
76 | |||
77 | img = new MrSIDImageReader(args[0]); |
||
78 | img.initialize(); |
||
79 | |||
80 | int overviews=((MrSIDImageReader)img).getNumLevels()-1; |
||
81 | System.out.println("Overviews="+overviews); |
||
82 | System.out.println("Width="+img.getWidth()); |
||
83 | System.out.println("Height="+img.getHeight()); |
||
84 | System.out.println("Stripsheigth="+img.getStripHeight()); |
||
85 | nBands=img.getNumBands(); |
||
86 | System.out.println("NumBands="+nBands); |
||
87 | eColorSpace=img.getColorSpace(); |
||
88 | System.out.println("ColorSpace="+eColorSpace); |
||
89 | eSampleType=img.getDataType(); |
||
90 | System.out.println("DataType="+eSampleType); |
||
91 | pixel=new LTIPixel(eColorSpace, nBands, eSampleType);
|
||
92 | int[] dimsAtMag=img.getDimsAtMag(0.5); |
||
93 | System.out.println("Dims At Mag 0,5="+dimsAtMag[0]+" "+dimsAtMag[1]); |
||
94 | |||
95 | |||
96 | //Acceso a la informaci?n de georeferenciaci?n
|
||
97 | |||
98 | LTIGeoCoord geoc = img.getGeoCoord(); |
||
99 | System.out.println("X="+geoc.getX()); |
||
100 | System.out.println("Y="+geoc.getY()); |
||
101 | System.out.println("XRes="+geoc.getXRes()); |
||
102 | System.out.println("YRes="+geoc.getYRes()); |
||
103 | System.out.println("XRot="+geoc.getXRot()); |
||
104 | System.out.println("YRot="+geoc.getYRot()); |
||
105 | |||
106 | //Fin de acceso a la informaci?n de georeferenciaci?n
|
||
107 | |||
108 | System.out.println("************************************"); |
||
109 | |||
110 | LTIScene scene = new LTIScene(0,0,tamx,tamy,1.0); |
||
111 | LTISceneBuffer buffer = new LTISceneBuffer(pixel, tamx, tamy, true); |
||
112 | ((LTIImageStage)img).read(scene,buffer); |
||
113 | |||
114 | |||
115 | GdalDriver drv=Gdal.getDriverByName("GTiff");
|
||
116 | String[] params={"TILED=YES","PHOTOMETRIC=RGB","TFW=WORLDFILE"}; |
||
117 | dset_dstno=drv.create("SiToTif.tif",tamx,tamy,3,Gdal.GDT_Byte,null); |
||
118 | |||
119 | GdalBuffer b=new GdalBuffer();
|
||
120 | b.buffByte=buffer.buf1; |
||
121 | |||
122 | rband=dset_dstno.getRasterBand(1);
|
||
123 | rband.writeRaster(0,0, tamx, tamy, b,Gdal.GDT_Byte); |
||
124 | |||
125 | b.buffByte=buffer.buf2; |
||
126 | |||
127 | rband=dset_dstno.getRasterBand(2);
|
||
128 | rband.writeRaster(0,0, tamx, tamy, b,Gdal.GDT_Byte); |
||
129 | |||
130 | b.buffByte=buffer.buf3; |
||
131 | |||
132 | rband=dset_dstno.getRasterBand(3);
|
||
133 | rband.writeRaster(0,0, tamx, tamy, b,Gdal.GDT_Byte); |
||
134 | |||
135 | dset_dstno.close(); |
||
136 | |||
137 | |||
138 | |||
139 | |||
140 | }catch(Exception e){ |
||
141 | e.printStackTrace(); |
||
142 | |||
143 | } |
||
144 | |||
145 | |||
146 | |||
147 | } |
||
148 | } |