svn-gvsig-desktop / tags / v1_0_2_Build_902 / libraries / libjni-mrsid / src-test / Example.java @ 33778
History | View | Annotate | Download (5.43 KB)
1 | 662 | igbrotru | /**********************************************************************
|
---|---|---|---|
2 | * $Id$
|
||
3 | *
|
||
4 | * Name: Example.java
|
||
5 | * Project:
|
||
6 | * Purpose:
|
||
7 | * Author: Nacho Brodin, brodin_ign@gva.es
|
||
8 | *
|
||
9 | **********************************************************************/
|
||
10 | 2214 | igbrotru | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
11 | *
|
||
12 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
13 | *
|
||
14 | * This program is free software; you can redistribute it and/or
|
||
15 | * modify it under the terms of the GNU General Public License
|
||
16 | * as published by the Free Software Foundation; either version 2
|
||
17 | * of the License, or (at your option) any later version.
|
||
18 | *
|
||
19 | * This program is distributed in the hope that it will be useful,
|
||
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
22 | * GNU General Public License for more details.
|
||
23 | *
|
||
24 | * You should have received a copy of the GNU General Public License
|
||
25 | * along with this program; if not, write to the Free Software
|
||
26 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
27 | *
|
||
28 | * For more information, contact:
|
||
29 | *
|
||
30 | * Generalitat Valenciana
|
||
31 | * Conselleria d'Infraestructures i Transport
|
||
32 | * Av. Blasco Ib??ez, 50
|
||
33 | * 46010 VALENCIA
|
||
34 | * SPAIN
|
||
35 | *
|
||
36 | * +34 963862235
|
||
37 | * gvsig@gva.es
|
||
38 | * www.gvsig.gva.es
|
||
39 | *
|
||
40 | * or
|
||
41 | *
|
||
42 | * IVER T.I. S.A
|
||
43 | * Salamanca 50
|
||
44 | * 46005 Valencia
|
||
45 | * Spain
|
||
46 | *
|
||
47 | * +34 963163400
|
||
48 | * dac@iver.es
|
||
49 | */
|
||
50 | 662 | igbrotru | |
51 | import es.gva.cit.jmrsid.*; |
||
52 | import java.io.*; |
||
53 | |||
54 | 2216 | igbrotru | /**
|
55 | * Genera una imagen .raw a partir de un mrsid. Hay que definir el tama?o de la ventana que
|
||
56 | * queremos convertir pasando el ancho y el alto. Adem?s mostrar? alguna informaci?n sobre la
|
||
57 | * imagen.
|
||
58 | *
|
||
59 | * @author Nacho Brodin <brodin_ign@gva.es>.<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
|
||
60 | * @version 0.0
|
||
61 | * @link http://www.gvsig.gva.es
|
||
62 | */
|
||
63 | 662 | igbrotru | public class Example { |
64 | public static void main(String[] args){ |
||
65 | |||
66 | |||
67 | LTIImageReader img; |
||
68 | LTIMetadataDatabase metadata; |
||
69 | LTIPixel pixel; |
||
70 | int eColorSpace, nBands, eSampleType;
|
||
71 | |||
72 | int tamx=Integer.parseInt(args[1]); |
||
73 | int tamy=Integer.parseInt(args[2]); |
||
74 | int siz = tamx * tamy * 1; |
||
75 | |||
76 | |||
77 | 3539 | nacho | try{
|
78 | 662 | igbrotru | img = new MrSIDImageReader(args[0]); |
79 | img.initialize(); |
||
80 | 3539 | nacho | |
81 | 662 | igbrotru | int overviews=((MrSIDImageReader)img).getNumLevels()-1; |
82 | System.out.println("Overviews="+overviews); |
||
83 | System.out.println("Width="+img.getWidth()); |
||
84 | System.out.println("Height="+img.getHeight()); |
||
85 | System.out.println("Stripsheigth="+img.getStripHeight()); |
||
86 | nBands=img.getNumBands(); |
||
87 | System.out.println("NumBands="+nBands); |
||
88 | eColorSpace=img.getColorSpace(); |
||
89 | System.out.println("ColorSpace="+eColorSpace); |
||
90 | eSampleType=img.getDataType(); |
||
91 | System.out.println("DataType="+eSampleType); |
||
92 | pixel=new LTIPixel(eColorSpace, nBands, eSampleType);
|
||
93 | 720 | igbrotru | int[] dimsAtMag=img.getDimsAtMag(0.5); |
94 | System.out.println("Dims At Mag 0,5="+dimsAtMag[0]+" "+dimsAtMag[1]); |
||
95 | |||
96 | 662 | igbrotru | |
97 | 746 | igbrotru | System.out.println("************************************"); |
98 | |||
99 | 720 | igbrotru | //Acceso a metadatos
|
100 | |||
101 | metadata=img.getMetadata(); |
||
102 | 746 | igbrotru | |
103 | 720 | igbrotru | System.out.println("Metadatos="+metadata.getIndexCount()); |
104 | for (int i=0; i<metadata.getIndexCount(); i++) |
||
105 | { |
||
106 | LTIMetadataRecord rec = null;
|
||
107 | rec = metadata.getDataByIndex(i); |
||
108 | System.out.println(rec.getTagName());
|
||
109 | |||
110 | 840 | igbrotru | //System.out.print("Dims="+rec.getNumDims());
|
111 | //int[] longitudes=rec.getDims();
|
||
112 | //for(int j=0;j<rec.getNumDims();j++)
|
||
113 | //System.out.print("Dim["+j+"]="+longitudes[j]);
|
||
114 | //System.out.println("");
|
||
115 | |||
116 | 720 | igbrotru | if(rec.isScalar())System.out.println(rec.getScalarData()); |
117 | else if(rec.isVector()){ |
||
118 | String[] s = rec.getVectorData(); |
||
119 | for(int j=0;j<s.length;j++)System.out.println("V"+j+"->"+s[j]); |
||
120 | }else if(rec.isArray()){ |
||
121 | String[] s = rec.getArrayData(); |
||
122 | for(int j=0;j<s.length;j++)System.out.println("A"+j+"->"+s[j]); |
||
123 | } |
||
124 | |||
125 | else System.out.println(""); |
||
126 | } |
||
127 | |||
128 | //Fin metadatos
|
||
129 | |||
130 | 746 | igbrotru | System.out.println("************************************"); |
131 | 720 | igbrotru | |
132 | 746 | igbrotru | //Acceso a la informaci?n de georeferenciaci?n
|
133 | |||
134 | LTIGeoCoord geoc = img.getGeoCoord(); |
||
135 | System.out.println("X="+geoc.getX()); |
||
136 | System.out.println("Y="+geoc.getY()); |
||
137 | System.out.println("XRes="+geoc.getXRes()); |
||
138 | System.out.println("YRes="+geoc.getYRes()); |
||
139 | System.out.println("XRot="+geoc.getXRot()); |
||
140 | System.out.println("YRot="+geoc.getYRot()); |
||
141 | |||
142 | //Fin de acceso a la informaci?n de georeferenciaci?n
|
||
143 | |||
144 | System.out.println("************************************"); |
||
145 | |||
146 | 662 | igbrotru | LTIScene scene=new LTIScene(0,0,tamx,tamy,1.0); |
147 | 2222 | igbrotru | LTISceneBuffer buffer=new LTISceneBuffer(pixel,tamx,tamy,true); |
148 | 662 | igbrotru | ((LTIImageStage)img).read(scene,buffer); |
149 | |||
150 | FileOutputStream s=null; |
||
151 | |||
152 | try{
|
||
153 | File mifichero=new File("exit.raw"); |
||
154 | s = new FileOutputStream(mifichero); |
||
155 | }catch(Exception e){} |
||
156 | |||
157 | |||
158 | try{
|
||
159 | for(int j=0;j<buffer.size;j++){ |
||
160 | s.write(buffer.buf1,j,1);
|
||
161 | s.write(buffer.buf2,j,1);
|
||
162 | s.write(buffer.buf3,j,1);
|
||
163 | } |
||
164 | }catch(IOException e){ |
||
165 | System.out.println("Error writing a line in the file\n"); |
||
166 | System.exit(1); |
||
167 | } |
||
168 | |||
169 | 3539 | nacho | img.close(); |
170 | 662 | igbrotru | |
171 | |||
172 | }catch(Exception e){ |
||
173 | e.printStackTrace(); |
||
174 | |||
175 | } |
||
176 | |||
177 | |||
178 | |||
179 | } |
||
180 | } |