svn-gvsig-desktop / trunk / libraries / libjni-mrsid / src-test / Example.java @ 1582
History | View | Annotate | Download (3.91 KB)
1 |
/**********************************************************************
|
---|---|
2 |
* $Id: Example.java 840 2005-01-10 14:12:36Z igbrotru $
|
3 |
*
|
4 |
* Name: Example.java
|
5 |
* Project:
|
6 |
* Purpose:
|
7 |
* Author: Nacho Brodin, brodin_ign@gva.es
|
8 |
*
|
9 |
**********************************************************************/
|
10 |
|
11 |
|
12 |
import es.gva.cit.jmrsid.*; |
13 |
import java.io.*; |
14 |
|
15 |
public class Example { |
16 |
public static void main(String[] args){ |
17 |
|
18 |
|
19 |
LTIImageReader img; |
20 |
LTIMetadataDatabase metadata; |
21 |
LTIPixel pixel; |
22 |
int eColorSpace, nBands, eSampleType;
|
23 |
|
24 |
int tamx=Integer.parseInt(args[1]); |
25 |
int tamy=Integer.parseInt(args[2]); |
26 |
int siz = tamx * tamy * 1; |
27 |
|
28 |
|
29 |
try{
|
30 |
img = new MrSIDImageReader(args[0]); |
31 |
img.initialize(); |
32 |
|
33 |
int overviews=((MrSIDImageReader)img).getNumLevels()-1; |
34 |
System.out.println("Overviews="+overviews); |
35 |
System.out.println("Width="+img.getWidth()); |
36 |
System.out.println("Height="+img.getHeight()); |
37 |
System.out.println("Stripsheigth="+img.getStripHeight()); |
38 |
nBands=img.getNumBands(); |
39 |
System.out.println("NumBands="+nBands); |
40 |
eColorSpace=img.getColorSpace(); |
41 |
System.out.println("ColorSpace="+eColorSpace); |
42 |
eSampleType=img.getDataType(); |
43 |
System.out.println("DataType="+eSampleType); |
44 |
pixel=new LTIPixel(eColorSpace, nBands, eSampleType);
|
45 |
int[] dimsAtMag=img.getDimsAtMag(0.5); |
46 |
System.out.println("Dims At Mag 0,5="+dimsAtMag[0]+" "+dimsAtMag[1]); |
47 |
|
48 |
|
49 |
System.out.println("************************************"); |
50 |
|
51 |
//Acceso a metadatos
|
52 |
|
53 |
metadata=img.getMetadata(); |
54 |
|
55 |
System.out.println("Metadatos="+metadata.getIndexCount()); |
56 |
for (int i=0; i<metadata.getIndexCount(); i++) |
57 |
{ |
58 |
LTIMetadataRecord rec = null;
|
59 |
rec = metadata.getDataByIndex(i); |
60 |
System.out.println(rec.getTagName());
|
61 |
|
62 |
//System.out.print("Dims="+rec.getNumDims());
|
63 |
//int[] longitudes=rec.getDims();
|
64 |
//for(int j=0;j<rec.getNumDims();j++)
|
65 |
//System.out.print("Dim["+j+"]="+longitudes[j]);
|
66 |
//System.out.println("");
|
67 |
|
68 |
if(rec.isScalar())System.out.println(rec.getScalarData()); |
69 |
else if(rec.isVector()){ |
70 |
String[] s = rec.getVectorData(); |
71 |
for(int j=0;j<s.length;j++)System.out.println("V"+j+"->"+s[j]); |
72 |
}else if(rec.isArray()){ |
73 |
String[] s = rec.getArrayData(); |
74 |
for(int j=0;j<s.length;j++)System.out.println("A"+j+"->"+s[j]); |
75 |
} |
76 |
|
77 |
else System.out.println(""); |
78 |
} |
79 |
|
80 |
//Fin metadatos
|
81 |
|
82 |
System.out.println("************************************"); |
83 |
|
84 |
//Acceso a la informaci?n de georeferenciaci?n
|
85 |
|
86 |
LTIGeoCoord geoc = img.getGeoCoord(); |
87 |
System.out.println("X="+geoc.getX()); |
88 |
System.out.println("Y="+geoc.getY()); |
89 |
System.out.println("XRes="+geoc.getXRes()); |
90 |
System.out.println("YRes="+geoc.getYRes()); |
91 |
System.out.println("XRot="+geoc.getXRot()); |
92 |
System.out.println("YRot="+geoc.getYRot()); |
93 |
|
94 |
//Fin de acceso a la informaci?n de georeferenciaci?n
|
95 |
|
96 |
System.out.println("************************************"); |
97 |
|
98 |
LTIScene scene=new LTIScene(0,0,tamx,tamy,1.0); |
99 |
LTISceneBuffer buffer=new LTISceneBuffer(pixel,tamx,tamy,1); |
100 |
((LTIImageStage)img).read(scene,buffer); |
101 |
|
102 |
FileOutputStream s=null; |
103 |
|
104 |
try{
|
105 |
File mifichero=new File("exit.raw"); |
106 |
s = new FileOutputStream(mifichero); |
107 |
}catch(Exception e){} |
108 |
|
109 |
|
110 |
try{
|
111 |
for(int j=0;j<buffer.size;j++){ |
112 |
s.write(buffer.buf1,j,1);
|
113 |
s.write(buffer.buf2,j,1);
|
114 |
s.write(buffer.buf3,j,1);
|
115 |
} |
116 |
}catch(IOException e){ |
117 |
System.out.println("Error writing a line in the file\n"); |
118 |
System.exit(1); |
119 |
} |
120 |
|
121 |
|
122 |
|
123 |
|
124 |
}catch(Exception e){ |
125 |
e.printStackTrace(); |
126 |
|
127 |
} |
128 |
|
129 |
|
130 |
|
131 |
} |
132 |
} |