root / trunk / libraries / libjni-gdal / src-test / SidToTif.java @ 879
History | View | Annotate | Download (3.24 KB)
1 |
/**********************************************************************
|
---|---|
2 |
* $Id: SidToTif.java 879 2005-01-11 15:23:01Z igbrotru $
|
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 |
|
15 |
import es.gva.cit.jmrsid.*; |
16 |
import es.gva.cit.jgdal.*; |
17 |
|
18 |
|
19 |
public class SidToTif { |
20 |
public static void main(String[] args){ |
21 |
|
22 |
Gdal dset_dstno; |
23 |
GdalRasterBand rband=null;
|
24 |
Gdal migdal=new Gdal();
|
25 |
|
26 |
LTIImageReader img; |
27 |
LTIPixel pixel; |
28 |
int eColorSpace, nBands, eSampleType;
|
29 |
|
30 |
int tamx=Integer.parseInt(args[1]); |
31 |
int tamy=Integer.parseInt(args[2]); |
32 |
int siz = tamx * tamy * 1; |
33 |
|
34 |
|
35 |
try{
|
36 |
|
37 |
img = new MrSIDImageReader(args[0]); |
38 |
img.initialize(); |
39 |
|
40 |
int overviews=((MrSIDImageReader)img).getNumLevels()-1; |
41 |
System.out.println("Overviews="+overviews); |
42 |
System.out.println("Width="+img.getWidth()); |
43 |
System.out.println("Height="+img.getHeight()); |
44 |
System.out.println("Stripsheigth="+img.getStripHeight()); |
45 |
nBands=img.getNumBands(); |
46 |
System.out.println("NumBands="+nBands); |
47 |
eColorSpace=img.getColorSpace(); |
48 |
System.out.println("ColorSpace="+eColorSpace); |
49 |
eSampleType=img.getDataType(); |
50 |
System.out.println("DataType="+eSampleType); |
51 |
pixel=new LTIPixel(eColorSpace, nBands, eSampleType);
|
52 |
int[] dimsAtMag=img.getDimsAtMag(0.5); |
53 |
System.out.println("Dims At Mag 0,5="+dimsAtMag[0]+" "+dimsAtMag[1]); |
54 |
|
55 |
|
56 |
//Acceso a la informaci?n de georeferenciaci?n
|
57 |
|
58 |
LTIGeoCoord geoc = img.getGeoCoord(); |
59 |
System.out.println("X="+geoc.getX()); |
60 |
System.out.println("Y="+geoc.getY()); |
61 |
System.out.println("XRes="+geoc.getXRes()); |
62 |
System.out.println("YRes="+geoc.getYRes()); |
63 |
System.out.println("XRot="+geoc.getXRot()); |
64 |
System.out.println("YRot="+geoc.getYRot()); |
65 |
|
66 |
//Fin de acceso a la informaci?n de georeferenciaci?n
|
67 |
|
68 |
System.out.println("************************************"); |
69 |
|
70 |
LTIScene scene=new LTIScene(0,0,tamx,tamy,1.0); |
71 |
LTISceneBuffer buffer=new LTISceneBuffer(pixel,tamx,tamy,1); |
72 |
((LTIImageStage)img).read(scene,buffer); |
73 |
|
74 |
|
75 |
GdalDriver drv=Gdal.getDriverByName("GTiff");
|
76 |
String[] params={"TILED=YES","PHOTOMETRIC=RGB","TFW=WORLDFILE"}; |
77 |
dset_dstno=drv.create("SiToTif.tif",tamx,tamy,3,Gdal.GDT_Byte,null); |
78 |
|
79 |
GdalBuffer b=new GdalBuffer();
|
80 |
b.buffByte=buffer.buf1; |
81 |
|
82 |
rband=dset_dstno.getRasterBand(1);
|
83 |
rband.writeRaster(0,0, tamx, tamy, b,Gdal.GDT_Byte); |
84 |
|
85 |
b.buffByte=buffer.buf2; |
86 |
|
87 |
rband=dset_dstno.getRasterBand(2);
|
88 |
rband.writeRaster(0,0, tamx, tamy, b,Gdal.GDT_Byte); |
89 |
|
90 |
b.buffByte=buffer.buf3; |
91 |
|
92 |
rband=dset_dstno.getRasterBand(3);
|
93 |
rband.writeRaster(0,0, tamx, tamy, b,Gdal.GDT_Byte); |
94 |
|
95 |
dset_dstno.close(); |
96 |
|
97 |
|
98 |
|
99 |
|
100 |
}catch(Exception e){ |
101 |
e.printStackTrace(); |
102 |
|
103 |
} |
104 |
|
105 |
|
106 |
|
107 |
} |
108 |
} |