Revision 1527
branches/v02_desarrollo/libraries/libCq CMS for java.old/src-dvp/org/cresques/io/GrafCanMapServerClient.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 12-dic-2004 |
|
3 |
*/ |
|
4 |
package org.cresques.io; |
|
5 |
|
|
6 |
import org.cresques.px.Extent; |
|
7 |
|
|
8 |
/** |
|
9 |
* Consulta el servidor de mapas de grafcan. |
|
10 |
* Implementa una llamada del tipo: |
|
11 |
* http://www.dgtcan.com/MapServer/Mapa.asp? |
|
12 |
* XMin=219900&YMax=3151900&XMax=221000&YMin=3151300& |
|
13 |
* Ancho=1000&Alto=1000&NumeroCapas=6&Capas=2&Servicio=NavGRAFCAN2 |
|
14 |
* @author Luis W. Sevilla (sevilla_lui@gva.es) |
|
15 |
*/ |
|
16 |
public class GrafCanMapServerClient extends MapServerClient { |
|
17 |
public final static int CAPA_ORTOFOTO = 2; |
|
18 |
public final static int CAPA_CARTOGRAFIA = 1; |
|
19 |
|
|
20 |
private int numeroCapas = 6; |
|
21 |
private int capas = CAPA_CARTOGRAFIA; |
|
22 |
private String servicio = "NavGRAFCAN2"; |
|
23 |
|
|
24 |
public GrafCanMapServerClient(String serverName) { |
|
25 |
super(serverName); |
|
26 |
urlBase = "http://www.dgtcan.com/MapServer/Mapa.asp"; |
|
27 |
/**/ setExtent(new Extent(180020,3270000,660000,3035000)); |
|
28 |
} |
|
29 |
|
|
30 |
public void setCapas(int c) { capas = c; } |
|
31 |
|
|
32 |
public void setNumeroCapas(int c) { numeroCapas = c; } |
|
33 |
|
|
34 |
public void setServicio(String s) { servicio = s; } |
|
35 |
|
|
36 |
public String getUrl() { |
|
37 |
String url = urlBase+"?"+ |
|
38 |
"XMin="+xMin+"&"+ "XMax="+xMax+"&"+ |
|
39 |
"YMin="+yMin+"&"+ "YMax="+yMax+"&"+ |
|
40 |
"Ancho="+ancho+"&"+"Alto="+alto+"&"+ |
|
41 |
"NumeroCapas="+numeroCapas+"&"+"Capas="+capas+"&"+ |
|
42 |
"Servicio="+servicio; |
|
43 |
return url; |
|
44 |
} |
|
45 |
} |
|
0 | 46 |
branches/v02_desarrollo/libraries/libCq CMS for java.old/src-dvp/org/cresques/io/BsbFile.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 25-sep-2004 |
|
3 |
* |
|
4 |
* TODO To change the template for this generated file go to |
|
5 |
* Window - Preferences - Java - Code Style - Code Templates |
|
6 |
*/ |
|
7 |
package org.cresques.io; |
|
8 |
|
|
9 |
import java.awt.Color; |
|
10 |
import java.awt.Image; |
|
11 |
import java.awt.geom.Point2D; |
|
12 |
import java.awt.image.BufferedImage; |
|
13 |
import java.io.IOException; |
|
14 |
import java.util.Vector; |
|
15 |
|
|
16 |
import org.cresques.cts.ICoordTrans; |
|
17 |
import org.cresques.cts.IProjection; |
|
18 |
import org.cresques.io.GeoFile; |
|
19 |
import org.cresques.io.GeoRasterFile; |
|
20 |
import org.cresques.px.Extent; |
|
21 |
|
|
22 |
import es.gva.cit.jbsb.BsbException; |
|
23 |
|
|
24 |
/** |
|
25 |
* Soporte 'nativo' para Bsb. |
|
26 |
* Este conjunto de funcionalidades est? tomado de manera casi literal |
|
27 |
* del soporte para ECW de ermapper.<br> |
|
28 |
* Probablemente esto deber?a formar parte del JNI que recubre a la |
|
29 |
* librer?a en C extraida de gdal.<br> |
|
30 |
* Lo pongo aqu? a manera de ejemplo de como atacar un formato binario |
|
31 |
* desde Java.<br><br> |
|
32 |
* @author Luis W. Sevilla. |
|
33 |
*/ |
|
34 |
|
|
35 |
class BsbNative extends es.gva.cit.jbsb.Bsb { |
|
36 |
// Polilinea con extent |
|
37 |
class Contour extends Vector { |
|
38 |
public double minX = Double.MAX_VALUE, minY = Double.MAX_VALUE; |
|
39 |
public double maxX = -Double.MAX_VALUE, maxY = -Double.MAX_VALUE; |
|
40 |
public Contour() { |
|
41 |
super(); |
|
42 |
} |
|
43 |
public void add(Point2D pt) { |
|
44 |
super.add(pt); |
|
45 |
if (pt.getX() > maxX) maxX = pt.getX(); |
|
46 |
if (pt.getX() < minX) minX = pt.getX(); |
|
47 |
if (pt.getY() > maxY) maxY = pt.getY(); |
|
48 |
if (pt.getY() < minY) minY = pt.getY(); |
|
49 |
} |
|
50 |
} |
|
51 |
private int [] paleta = null; |
|
52 |
/** |
|
53 |
* Contorno en coordenadas geogr?ficas. (y Extent del raster). |
|
54 |
*/ |
|
55 |
public Contour esq = new Contour(); |
|
56 |
public int width = 0, height = 0; |
|
57 |
public double originX = 0D, originY = 0D; |
|
58 |
public String version = ""; |
|
59 |
|
|
60 |
public BsbNative(String fName) throws BsbException { |
|
61 |
super(); |
|
62 |
try { |
|
63 |
init(fName); |
|
64 |
} catch (IOException e) { |
|
65 |
// TODO Auto-generated catch block |
|
66 |
e.printStackTrace(); |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
private void init(String fName) throws BsbException, IOException { |
|
71 |
bsbOpen(fName); |
|
72 |
width = g_psInfo.nXSize; |
|
73 |
height = g_psInfo.nYSize; |
|
74 |
Vector pal = new Vector(); |
|
75 |
String buf = null; |
|
76 |
for (int i=0; i<g_psInfo.papszHeader.length; i++) { |
|
77 |
buf = g_psInfo.papszHeader[i]; |
|
78 |
if (buf.length()<1) continue; |
|
79 |
if (buf.startsWith("RGB/")) { |
|
80 |
String [] dat = buf.split(","); |
|
81 |
pal.add(new Color(Integer.parseInt(dat[1]), |
|
82 |
Integer.parseInt(dat[2]), |
|
83 |
Integer.parseInt(dat[3]))); |
|
84 |
} else if (buf.startsWith("VER/")) { |
|
85 |
version = buf.substring(4); |
|
86 |
} /*else if (buf.startsWith("PLY/")) { // Marco de hoja |
|
87 |
String [] dat = buf.split(","); |
|
88 |
esq.add(new Point2D.Double(Double.parseDouble(dat[2]), |
|
89 |
Double.parseDouble(dat[1]))); |
|
90 |
}*/ |
|
91 |
} |
|
92 |
if (true) { //version.startsWith("1")) { |
|
93 |
esq.add(new Point2D.Double(0D,height)); |
|
94 |
esq.add(new Point2D.Double(0D,0D)); |
|
95 |
esq.add(new Point2D.Double(width,0D)); |
|
96 |
esq.add(new Point2D.Double(width,height)); |
|
97 |
} |
|
98 |
paleta = new int[pal.size()]; |
|
99 |
for (int i=0; i<pal.size(); i++) |
|
100 |
paleta[i] = ((Color) pal.get(i)).getRGB(); |
|
101 |
|
|
102 |
originX = esq.minX; |
|
103 |
originY = esq.maxY; |
|
104 |
} |
|
105 |
|
|
106 |
double lastReadLine = -1; |
|
107 |
int currentViewWidth = -1; |
|
108 |
int currentViewHeight = -1; |
|
109 |
double currentViewX = 0D; |
|
110 |
double viewportScale = 0D; |
|
111 |
double step = 0D; |
|
112 |
|
|
113 |
public Point2D worldToRaster(Point2D pt) { |
|
114 |
double x = (((double) width)/(esq.maxX-esq.minX))*(pt.getX()-esq.minX); |
|
115 |
double y = (((double) height)/(esq.maxY-esq.minY))*(esq.maxY-pt.getY()); |
|
116 |
Point2D ptRes = new Point2D.Double(x, y); |
|
117 |
return ptRes; |
|
118 |
} |
|
119 |
|
|
120 |
public int setView(double dWorldTLX, double dWorldTLY, |
|
121 |
double dWorldBRX, double dWorldBRY, |
|
122 |
int nWidth, int nHeight) { |
|
123 |
int err = 0; |
|
124 |
Point2D tl = worldToRaster(new Point2D.Double(dWorldTLX, dWorldTLY)); |
|
125 |
Point2D br = worldToRaster(new Point2D.Double(dWorldBRX, dWorldBRY)); |
|
126 |
// Calcula cual es la primera l?nea a leer; |
|
127 |
currentViewWidth = nWidth; |
|
128 |
currentViewHeight = nHeight; |
|
129 |
|
|
130 |
currentViewX = tl.getX(); |
|
131 |
viewportScale = (double) currentViewWidth/(br.getX()-tl.getX()); |
|
132 |
step = 1D/viewportScale; |
|
133 |
lastReadLine = tl.getY(); |
|
134 |
|
|
135 |
System.out.println("BsbFile: TL=("+dWorldTLX+","+dWorldTLY+ |
|
136 |
"); BR=("+dWorldBRX+","+dWorldBRY+")\n"+ |
|
137 |
"BsbFile: escala="+viewportScale+"; lastReadLine="+lastReadLine); |
|
138 |
return err; |
|
139 |
} |
|
140 |
|
|
141 |
public int readLineRGBA(int [] line) throws BsbException { |
|
142 |
int err = 0; |
|
143 |
bsbReadLine((int) lastReadLine); |
|
144 |
|
|
145 |
lastReadLine += step; |
|
146 |
|
|
147 |
byte [] l = g_buffer.pabyScanLineBuf; |
|
148 |
int white = Color.BLUE.getRGB(); |
|
149 |
float j =(float) currentViewX; |
|
150 |
for (int i=0; i<currentViewWidth && j<l.length; i++, j+=step) { |
|
151 |
line[i] = paleta[l[(int) j]-1]; |
|
152 |
} |
|
153 |
//for (int i=0; i<currentViewWidth; i++) line[i] = 128+128*256+128*256*256; |
|
154 |
|
|
155 |
return err; |
|
156 |
} |
|
157 |
|
|
158 |
void pintaInfo() { |
|
159 |
System.out.println("Fichero BSB: Info ("+g_psInfo.papszHeader.length+" l?neas):"); |
|
160 |
for (int i=0; i<g_psInfo.papszHeader.length; i++) { |
|
161 |
if (g_psInfo.papszHeader[i].length()<1) continue; |
|
162 |
System.out.println("info["+i+"] = "+g_psInfo.papszHeader[i]); |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
void pintaPaleta() { |
|
167 |
System.out.println("Fichero BSB: Paleta ("+paleta.length+" colores):"); |
|
168 |
for (int i=0; i<paleta.length; i++) |
|
169 |
System.out.println("color("+i+")="+paleta[i]); |
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* @author Luis W. Sevilla |
|
175 |
*/ |
|
176 |
public class BsbFile extends GeoRasterFile { |
|
177 |
private BsbNative file = null; |
|
178 |
|
|
179 |
private Extent v = null; |
|
180 |
|
|
181 |
|
|
182 |
static { |
|
183 |
GeoRasterFile.registerExtension("nos", BsbFile.class); |
|
184 |
GeoRasterFile.registerExtension("kap", BsbFile.class); |
|
185 |
} |
|
186 |
public BsbFile(IProjection proj, String fName) { |
|
187 |
super(proj, fName); |
|
188 |
extent = new Extent(); |
|
189 |
try { |
|
190 |
file = new BsbNative(fName); |
|
191 |
showOnOpen(); |
|
192 |
load(); |
|
193 |
} catch(BsbException e){ |
|
194 |
System.out.println("Error en BSBOpen"); |
|
195 |
e.printStackTrace(); |
|
196 |
file = null; |
|
197 |
} |
|
198 |
} |
|
199 |
|
|
200 |
public GeoFile load() { |
|
201 |
/*double minX, minY, maxX, maxY; |
|
202 |
minX = minY = 0D; |
|
203 |
maxX = (double) width; |
|
204 |
maxY = (double) height;*/ |
|
205 |
extent = new Extent(file.esq.minX, file.esq.minY, file.esq.maxX, file.esq.maxY); |
|
206 |
return this; |
|
207 |
} |
|
208 |
public void setView(Extent e) { v = new Extent(e); } |
|
209 |
public Extent getView() { return v; } |
|
210 |
|
|
211 |
public int getWidth() { return file.width; } |
|
212 |
public int getHeight() { return file.height;} |
|
213 |
|
|
214 |
/* (non-Javadoc) |
|
215 |
* @see org.cresques.io.GeoRasterFile#reProject(org.cresques.cts.ICoordTrans) |
|
216 |
*/ |
|
217 |
public void reProject(ICoordTrans rp) { |
|
218 |
// TODO Auto-generated method stub |
|
219 |
|
|
220 |
} |
|
221 |
/* (non-Javadoc) |
|
222 |
* @see org.cresques.io.GeoRasterFile#setTransparency(boolean) |
|
223 |
*/ |
|
224 |
public void setTransparency(boolean t) { |
|
225 |
// TODO Auto-generated method stub |
|
226 |
} |
|
227 |
public void setTransparency(int t) { |
|
228 |
// TODO Auto-generated method stub |
|
229 |
} |
|
230 |
/* (non-Javadoc) |
|
231 |
* @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.cts.ICoordTrans) |
|
232 |
*/ |
|
233 |
public Image updateImage(int width, int height, ICoordTrans rp) { |
|
234 |
double dFileAspect, dWindowAspect; |
|
235 |
int line, pRGBArray[] = null; |
|
236 |
Image image = null; |
|
237 |
|
|
238 |
// Work out the correct aspect for the setView call. |
|
239 |
dFileAspect = (double)v.width()/(double)v.height(); |
|
240 |
dWindowAspect = (double)width /(double)height; |
|
241 |
|
|
242 |
if (dFileAspect > dWindowAspect) { |
|
243 |
height =(int)((double)width/dFileAspect); |
|
244 |
} else { |
|
245 |
width = (int)((double)height*dFileAspect); |
|
246 |
} |
|
247 |
|
|
248 |
// Set the view |
|
249 |
file.setView(v.minX(), v.maxY(), v.maxX(), v.minY(), |
|
250 |
width, height); |
|
251 |
|
|
252 |
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); |
|
253 |
pRGBArray = new int[width]; |
|
254 |
try { |
|
255 |
for (line=0; line < height; line++) { |
|
256 |
file.readLineRGBA(pRGBArray); |
|
257 |
((BufferedImage)image).setRGB(0, line, width, 1, pRGBArray, 0, width); |
|
258 |
} |
|
259 |
} catch (Exception e) { |
|
260 |
// TODO Auto-generated catch block |
|
261 |
e.printStackTrace(); |
|
262 |
} |
|
263 |
|
|
264 |
return image; |
|
265 |
} |
|
266 |
private void showOnOpen() { |
|
267 |
// Report en la apertura (quitar) |
|
268 |
System.out.println("Fichero BSB '"+getName()+"' abierto."); |
|
269 |
System.out.println("Version = "+file.version); |
|
270 |
System.out.println(" Size = ("+file.width+","+file.height+")"); |
|
271 |
file.pintaInfo(); |
|
272 |
file.pintaPaleta(); |
|
273 |
|
|
274 |
} |
|
275 |
|
|
276 |
/* (non-Javadoc) |
|
277 |
* @see org.cresques.io.GeoRasterFile#close() |
|
278 |
*/ |
|
279 |
public void close() { |
|
280 |
} |
|
281 |
|
|
282 |
/* (non-Javadoc) |
|
283 |
* @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.cts.ICoordTrans, java.awt.Image, int) |
|
284 |
*/ |
|
285 |
public Image updateImage(int width, int height, ICoordTrans rp, Image img, int flags) { |
|
286 |
// TODO Auto-generated method stub |
|
287 |
return null; |
|
288 |
} |
|
289 |
|
|
290 |
/* (non-Javadoc) |
|
291 |
* @see org.cresques.io.GeoRasterFile#getData(int, int, int) |
|
292 |
*/ |
|
293 |
public Object getData(int x, int y, int band) { |
|
294 |
// TODO Auto-generated method stub |
|
295 |
return null; |
|
296 |
} |
|
297 |
} |
|
298 |
|
|
299 |
|
|
0 | 300 |
branches/v02_desarrollo/libraries/libCq CMS for java.old/src-dvp/org/cresques/io/GdalFile.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 25-sep-2004 (20-oct-2004) |
|
3 |
*/ |
|
4 |
package org.cresques.io; |
|
5 |
|
|
6 |
import java.awt.Color; |
|
7 |
import java.awt.Image; |
|
8 |
import java.awt.Point; |
|
9 |
import java.awt.geom.Point2D; |
|
10 |
import java.awt.image.BandedSampleModel; |
|
11 |
import java.awt.image.BufferedImage; |
|
12 |
import java.awt.image.DataBuffer; |
|
13 |
import java.awt.image.Raster; |
|
14 |
import java.awt.image.WritableRaster; |
|
15 |
import java.io.IOException; |
|
16 |
import java.util.Vector; |
|
17 |
|
|
18 |
import org.cresques.cts.ICoordTrans; |
|
19 |
import org.cresques.cts.IProjection; |
|
20 |
import org.cresques.px.Extent; |
|
21 |
|
|
22 |
import es.gva.cit.jgdal.Gdal; |
|
23 |
import es.gva.cit.jgdal.GdalBuffer; |
|
24 |
import es.gva.cit.jgdal.GdalException; |
|
25 |
import es.gva.cit.jgdal.GdalRasterBand; |
|
26 |
import es.gva.cit.jgdal.GeoTransform; |
|
27 |
/** |
|
28 |
* Soporte 'nativo' para ficheros desde GDAL. |
|
29 |
* Este conjunto de funcionalidades est? tomado de manera casi literal |
|
30 |
* del soporte para ECW de ermapper.<br> |
|
31 |
* Probablemente esto deber?a formar parte del JNI que recubre a la |
|
32 |
* librer?a en C extraida de gdal.<br> |
|
33 |
* Lo pongo aqu? a manera de ejemplo de como atacar un formato binario |
|
34 |
* desde Java.<br><br> |
|
35 |
* @author Luis W. Sevilla. |
|
36 |
*/ |
|
37 |
|
|
38 |
class GdalNative extends Gdal { |
|
39 |
static boolean WITH_OVERVIEWS = true; |
|
40 |
// Polilinea con extent |
|
41 |
class Contour extends Vector { |
|
42 |
public double minX = Double.MAX_VALUE, minY = Double.MAX_VALUE; |
|
43 |
public double maxX = -Double.MAX_VALUE, maxY = -Double.MAX_VALUE; |
|
44 |
public Contour() { |
|
45 |
super(); |
|
46 |
} |
|
47 |
public void add(Point2D pt) { |
|
48 |
super.add(pt); |
|
49 |
if (pt.getX() > maxX) maxX = pt.getX(); |
|
50 |
if (pt.getX() < minX) minX = pt.getX(); |
|
51 |
if (pt.getY() > maxY) maxY = pt.getY(); |
|
52 |
if (pt.getY() < minY) minY = pt.getY(); |
|
53 |
} |
|
54 |
} |
|
55 |
/** |
|
56 |
* Contorno en coordenadas geogr?ficas. (y Extent del raster). |
|
57 |
*/ |
|
58 |
public Contour esq = new Contour(); |
|
59 |
public int width = 0, height = 0; |
|
60 |
public double originX = 0D, originY = 0D; |
|
61 |
public String version = ""; |
|
62 |
|
|
63 |
private int alpha = 0; |
|
64 |
protected int rBandNr = 1, gBandNr = 2, bBandNr = 3; |
|
65 |
private int dataType = GDT_Byte; |
|
66 |
|
|
67 |
public GdalNative(String fName) throws GdalException, IOException { |
|
68 |
super(); |
|
69 |
init(fName); |
|
70 |
} |
|
71 |
|
|
72 |
private void init(String fName) throws GdalException, IOException { |
|
73 |
open(fName,GA_ReadOnly); |
|
74 |
String ext = fName.toLowerCase().substring(fName.lastIndexOf('.')+1); |
|
75 |
if (ext.compareTo("tif") == 0) |
|
76 |
WITH_OVERVIEWS = false; |
|
77 |
width = getRasterXSize(); |
|
78 |
height = getRasterYSize(); |
|
79 |
if (true) { //ext.compareTo("sid") == 0) { |
|
80 |
String [] metadata = getMetadata(); |
|
81 |
double ox=0D, oy=0D, resx=0D, resy=0D; |
|
82 |
|
|
83 |
GeoTransform trans = getGeoTransform(); |
|
84 |
ox = trans.adfgeotransform[0]; |
|
85 |
oy = trans.adfgeotransform[3]; |
|
86 |
resx = trans.adfgeotransform[1]; |
|
87 |
resy = trans.adfgeotransform[5]; |
|
88 |
|
|
89 |
System.out.println("Origin = ("+ox+","+oy+")"); |
|
90 |
System.out.println("Pixel Size = ("+resx+","+resy+")"); |
|
91 |
esq.add(new Point2D.Double(ox, oy)); |
|
92 |
esq.add(new Point2D.Double(ox+resx*width, oy)); |
|
93 |
esq.add(new Point2D.Double(ox, oy+resy*height)); |
|
94 |
esq.add(new Point2D.Double(ox+resx*width, oy+resy*height)); |
|
95 |
} else { //version.startsWith("1")) { |
|
96 |
//double [] transParam = getGeoTransform(); |
|
97 |
esq.add(new Point2D.Double(0D,height)); |
|
98 |
esq.add(new Point2D.Double(0D,0D)); |
|
99 |
esq.add(new Point2D.Double(width,0D)); |
|
100 |
esq.add(new Point2D.Double(width,height)); |
|
101 |
} |
|
102 |
setDataType(this.getRasterBand(1).getRasterDataType()); |
|
103 |
} |
|
104 |
|
|
105 |
public void setAlpha(int a) { alpha = a; } |
|
106 |
|
|
107 |
public void setDataType(int dt) { dataType = dt; } |
|
108 |
public int getDataType() { return dataType; } |
|
109 |
|
|
110 |
double lastReadLine = -1; |
|
111 |
int currentFullWidth = -1; |
|
112 |
int currentFullHeight = -1; |
|
113 |
int currentViewWidth = -1; |
|
114 |
int currentViewHeight = -1; |
|
115 |
double currentViewX = 0D; |
|
116 |
double viewportScale = 0D; |
|
117 |
double step = 0D; |
|
118 |
int currentOverview = -1; |
|
119 |
|
|
120 |
protected GdalRasterBand bandR=null, bandG=null, bandB=null; |
|
121 |
|
|
122 |
|
|
123 |
/** |
|
124 |
* Devuelve la banda actualmente en uso para el color especificado. |
|
125 |
* @param color 0=Rojo, 1=Green, 2=Blue. |
|
126 |
* @return |
|
127 |
*/ |
|
128 |
public GdalRasterBand getCurrentBand(int color) { |
|
129 |
if (color == 0) return bandR; |
|
130 |
else if (color == 1) return bandG; |
|
131 |
return bandB; |
|
132 |
} |
|
133 |
// Supone rasters no girados |
|
134 |
public Point2D worldToRaster(Point2D pt) { |
|
135 |
double x = (((double) currentFullWidth)/(esq.maxX-esq.minX))*(pt.getX()-esq.minX); |
|
136 |
double y = (((double) currentFullHeight)/(esq.maxY-esq.minY))*(esq.maxY-pt.getY()); |
|
137 |
Point2D ptRes = new Point2D.Double(x, y); |
|
138 |
return ptRes; |
|
139 |
} |
|
140 |
|
|
141 |
public int setView(double dWorldTLX, double dWorldTLY, |
|
142 |
double dWorldBRX, double dWorldBRY, |
|
143 |
int nWidth, int nHeight) { |
|
144 |
int err = 0; |
|
145 |
currentFullWidth = width; |
|
146 |
currentFullHeight = height; |
|
147 |
Point2D tl = worldToRaster(new Point2D.Double(dWorldTLX, dWorldTLY)); |
|
148 |
Point2D br = worldToRaster(new Point2D.Double(dWorldBRX, dWorldBRY)); |
|
149 |
// Calcula cual es la primera l?nea a leer; |
|
150 |
currentViewWidth = nWidth; |
|
151 |
currentViewHeight = nHeight; |
|
152 |
|
|
153 |
currentViewX = tl.getX(); |
|
154 |
viewportScale = (double) currentViewWidth/(br.getX()-tl.getX()); |
|
155 |
step = 1D/viewportScale; |
|
156 |
lastReadLine = tl.getY(); |
|
157 |
try { |
|
158 |
// calcula el overview a usar |
|
159 |
bandR = getRasterBand(1); |
|
160 |
currentOverview = -1; |
|
161 |
if (WITH_OVERVIEWS && bandR.getOverviewCount() > 0) { |
|
162 |
GdalRasterBand ovb = null; |
|
163 |
for (int i=bandR.getOverviewCount()-1; i>0; i--) { |
|
164 |
ovb = bandR.getOverview(i); |
|
165 |
if (ovb.getRasterBandXSize()>getRasterXSize()*viewportScale) { |
|
166 |
currentOverview = i; |
|
167 |
viewportScale *= ((double) width/(double) ovb.getRasterBandXSize()); |
|
168 |
step = 1D/viewportScale; |
|
169 |
currentFullWidth = ovb.getRasterBandXSize(); |
|
170 |
currentFullHeight = ovb.getRasterBandYSize(); |
|
171 |
tl = worldToRaster(new Point2D.Double(dWorldTLX, dWorldTLY)); |
|
172 |
currentViewX = tl.getX(); |
|
173 |
lastReadLine = tl.getY(); |
|
174 |
break; |
|
175 |
} |
|
176 |
} |
|
177 |
} |
|
178 |
|
|
179 |
// Selecciona las bandas y los overviews necesarios |
|
180 |
bandR = getRasterBand(rBandNr); |
|
181 |
setDataType(bandR.getRasterDataType()); |
|
182 |
if (this.getRasterCount() > 1) { |
|
183 |
bandG = getRasterBand(gBandNr); |
|
184 |
bandB = getRasterBand(bBandNr); |
|
185 |
} |
|
186 |
if (currentOverview > 0) { |
|
187 |
bandR = bandR.getOverview(currentOverview); |
|
188 |
if (this.getRasterCount() > 1) { |
|
189 |
bandG = bandG.getOverview(currentOverview); |
|
190 |
bandB = bandB.getOverview(currentOverview); |
|
191 |
} |
|
192 |
} |
|
193 |
|
|
194 |
//System.out.println(band.) |
|
195 |
} catch (GdalException e) { |
|
196 |
// TODO Auto-generated catch block |
|
197 |
e.printStackTrace(); |
|
198 |
} |
|
199 |
|
|
200 |
System.out.println("GdalFile: TL=("+dWorldTLX+","+dWorldTLY+ |
|
201 |
"); BR=("+dWorldBRX+","+dWorldBRY+")\n"+ |
|
202 |
"GdalFile: escala="+viewportScale+"; lastReadLine="+lastReadLine+"\n"+ |
|
203 |
"Actual Raster Size="+currentFullWidth+"x"+currentFullHeight+ |
|
204 |
"\nDataType="+dataType); |
|
205 |
return err; |
|
206 |
} |
|
207 |
|
|
208 |
int lastY = -1; |
|
209 |
|
|
210 |
public void readLine(int[][] line) throws GdalException { |
|
211 |
int err = 0; |
|
212 |
int nbands = getRasterCount(); |
|
213 |
GdalRasterBand band = null; |
|
214 |
int w = (int)(((double)currentViewWidth)*step); |
|
215 |
int x = (int) currentViewX; |
|
216 |
int y = (int) lastReadLine; |
|
217 |
GdalBuffer r = null, g = null, b = null; |
|
218 |
//if (alpha > 0) a = alpha << 24; |
|
219 |
if (x+w > bandR.getRasterBandXSize()) |
|
220 |
w = bandR.getRasterBandXSize()-x; |
|
221 |
r = bandR.readRaster(x, y, w, 1, w, 1, dataType); |
|
222 |
if (bandG != null) |
|
223 |
g = bandG.readRaster(x, y, w, 1, w, 1, dataType); |
|
224 |
if (bandB != null) |
|
225 |
b = bandB.readRaster(x, y, w, 1, w, 1, dataType); |
|
226 |
|
|
227 |
lastReadLine += step; |
|
228 |
|
|
229 |
int white = Color.BLUE.getRGB(), i2=0, i=0; |
|
230 |
float j =0F; |
|
231 |
|
|
232 |
if (dataType == GDT_CInt16 || dataType == GDT_Int16 || dataType == GDT_UInt16) |
|
233 |
if (g == null) // Sibgle Band (Typical DEM) |
|
234 |
/*for (i=0, j=0F, i2 = 1; i<currentViewWidth && i2<r.length; |
|
235 |
i++, j+=step, i2 = (((int) j)*2)+1) { |
|
236 |
line[i] = a + ((r[i2-1]) << 8) + r[i2]; |
|
237 |
}*/ |
|
238 |
for (i=0, j=0F; i<currentViewWidth && j<r.getSize(); i++, j+=step) { |
|
239 |
line[0][i] = r.buffShort[(int) j] & 0xffff; |
|
240 |
line[1][i] = r.buffShort[(int) j] & 0xffff; |
|
241 |
line[2][i] = r.buffShort[(int) j] & 0xffff; |
|
242 |
} |
|
243 |
else { // Multiband |
|
244 |
short px; |
|
245 |
//System.err.println("readLine(): Raster 16bits multibanda"); |
|
246 |
for (i=0, j=0F; i<currentViewWidth && j<r.getSize(); i++, j+=step) { |
|
247 |
line[0][i] = r.buffShort[(int) j] & 0xffff; |
|
248 |
line[1][i] = g.buffShort[(int) j] & 0xffff; |
|
249 |
line[2][i] = b.buffShort[(int) j] & 0xffff; |
|
250 |
} |
|
251 |
} |
|
252 |
//for (int i=0; i<currentViewWidth; i++) line[i] = 128+128*256+128*256*256; |
|
253 |
|
|
254 |
return; |
|
255 |
} |
|
256 |
|
|
257 |
public int readLineRGBA(int [] line) throws GdalException { |
|
258 |
int err = 0; |
|
259 |
int nbands = getRasterCount(); |
|
260 |
GdalRasterBand band = null; |
|
261 |
int w = (int)(((double)currentViewWidth)*step); |
|
262 |
int x = (int) currentViewX; |
|
263 |
int y = (int) lastReadLine; |
|
264 |
GdalBuffer r = null, g = null, b = null; |
|
265 |
//if (alpha > 0) a = alpha << 24; |
|
266 |
if (x+w > bandR.getRasterBandXSize()) |
|
267 |
w = bandR.getRasterBandXSize()-x; |
|
268 |
r = bandR.readRaster(x, y, w, 1, w, 1, dataType); |
|
269 |
if (bandG != null) |
|
270 |
g = bandG.readRaster(x, y, w, 1, w, 1, dataType); |
|
271 |
if (bandB != null) |
|
272 |
b = bandB.readRaster(x, y, w, 1, w, 1, dataType); |
|
273 |
|
|
274 |
lastReadLine += step; |
|
275 |
|
|
276 |
int white = Color.BLUE.getRGB(), i2=0, i=0; |
|
277 |
float j =0F; |
|
278 |
int alpha = (this.alpha & 0xff) << 24; |
|
279 |
if (dataType == GDT_Byte) |
|
280 |
if (g != null) |
|
281 |
for (i=0; i<currentViewWidth && j<r.getSize(); i++, j+=step) { |
|
282 |
line[i] = alpha + ((r.buffByte[(int) j] & 0xff) << 16) + ((g.buffByte[(int) j] & 0xff) << 8) + (b.buffByte[(int) j] & 0xff); |
|
283 |
} |
|
284 |
else |
|
285 |
for (i=0; i<currentViewWidth && j<r.getSize(); i++, j+=step) { |
|
286 |
line[i] = alpha + ((r.buffByte[(int) j] & 0xff) << 16) + |
|
287 |
((r.buffByte[(int) j] & 0xff) << 8) + (r.buffByte[(int) j] & 0xff); |
|
288 |
} |
|
289 |
else if (dataType == GDT_CInt16 || dataType == GDT_Int16 || dataType == GDT_UInt16) |
|
290 |
if (g == null) // Sibgle Band (Typical DEM) |
|
291 |
/*for (i=0, j=0F, i2 = 1; i<currentViewWidth && i2<r.length; |
|
292 |
i++, j+=step, i2 = (((int) j)*2)+1) { |
|
293 |
line[i] = a + ((r[i2-1]) << 8) + r[i2]; |
|
294 |
}*/ |
|
295 |
for (i=0, j=0F; i<currentViewWidth && j<r.getSize(); i++, j+=step) { |
|
296 |
line[i] = alpha + r.buffShort[(int) j]; |
|
297 |
} |
|
298 |
else { // Multiband |
|
299 |
System.err.println("Raster 16bits multibanda"); |
|
300 |
for (i=0, j=0F; i<currentViewWidth && j<r.getSize(); i++, j+=step) { |
|
301 |
line[i] = alpha | (((r.buffShort[(int) j] & 0xfff0) << 12) & 0xff0000 ) | |
|
302 |
(((g.buffShort[(int) j] & 0xfff0) << 4 ) & 0xff00 ) | |
|
303 |
(((b.buffShort[(int) j] & 0xfff0) >> 4 ) & 0xff ); |
|
304 |
} |
|
305 |
} |
|
306 |
//for (int i=0; i<currentViewWidth; i++) line[i] = 128+128*256+128*256*256; |
|
307 |
|
|
308 |
return err; |
|
309 |
} |
|
310 |
|
|
311 |
/** |
|
312 |
* Lee una franja de la imagen. |
|
313 |
* @param bandH Altura de la franja |
|
314 |
* @param bufH Altura del buffer |
|
315 |
* @param buf Buffer con la franja (retorno) |
|
316 |
* @return |
|
317 |
* @throws GdalException |
|
318 |
*/ |
|
319 |
public int readBandRGBA(int bandH, int bufH, int [] buf) throws GdalException { |
|
320 |
int err = 0; |
|
321 |
int nbands = getRasterCount(); |
|
322 |
GdalRasterBand band = null; |
|
323 |
int w = (int)(((double)currentViewWidth)*step); |
|
324 |
int x = (int)(((double)currentViewX)*step); |
|
325 |
int y = (int) lastReadLine; |
|
326 |
int h = (int) (((double)bandH)*step); |
|
327 |
System.out.println("Leyendo "+y); |
|
328 |
|
|
329 |
if (x+w > bandR.getRasterBandXSize()) |
|
330 |
w = bandR.getRasterBandXSize()-x; |
|
331 |
GdalBuffer r = bandR.readRaster(x, y, w, h, w, h, GDT_Byte); |
|
332 |
GdalBuffer g = bandG.readRaster(x, y, w, h, w, h, GDT_Byte); |
|
333 |
GdalBuffer b = bandB.readRaster(x, y, w, h, w, h, GDT_Byte); |
|
334 |
|
|
335 |
lastReadLine += ((double)bandH)*step; |
|
336 |
|
|
337 |
// TODO Acabar de implementarlo |
|
338 |
float k=0F; |
|
339 |
int alpha = (this.alpha & 0xff) << 24; |
|
340 |
for (int j=0, t=0; j<bandH; j++) { |
|
341 |
k = j*w; t=j*currentViewWidth; |
|
342 |
for (int i=0; i<currentViewWidth && k<r.getSize(); i++, k+=step) { |
|
343 |
buf[t+i] = alpha + ((r.buffByte[(int) k]) << 16) + ((g.buffByte[(int) k]) << 8) + b.buffByte[(int) k]; |
|
344 |
} |
|
345 |
} |
|
346 |
//for (int i=0; i<currentViewWidth; i++) line[i] = 128+128*256+128*256*256; |
|
347 |
|
|
348 |
return err; |
|
349 |
|
|
350 |
} |
|
351 |
|
|
352 |
void pintaInfo() { |
|
353 |
try { |
|
354 |
//System.out.println("Origin = "+originX+","+originY); |
|
355 |
//System.out.println("Origin = "+this.); |
|
356 |
System.out.println("GeoTransform:"); |
|
357 |
GeoTransform trans = getGeoTransform(); |
|
358 |
for (int i=0; i<6; i++) |
|
359 |
System.out.println(" param["+i+"]="+trans.adfgeotransform[i]); |
|
360 |
System.out.println("Metadata:"); |
|
361 |
String [] metadata = getMetadata(); |
|
362 |
for (int i=0; i<metadata.length; i++) { |
|
363 |
System.out.println(metadata[i]); |
|
364 |
} |
|
365 |
} catch (GdalException e) { |
|
366 |
// TODO Auto-generated catch block |
|
367 |
e.printStackTrace(); |
|
368 |
} |
|
369 |
|
|
370 |
} |
|
371 |
|
|
372 |
void pintaPaleta() { |
|
373 |
} |
|
374 |
} |
|
375 |
|
|
376 |
/** |
|
377 |
* @author Luis W. Sevilla |
|
378 |
*/ |
|
379 |
public class GdalFile extends GeoRasterFile { |
|
380 |
public final static int BAND_HEIGHT = 64; |
|
381 |
protected GdalNative file = null; |
|
382 |
|
|
383 |
private Extent v = null; |
|
384 |
|
|
385 |
static { |
|
386 |
//GeoRasterFile.registerExtension("sid", GdalFile.class); |
|
387 |
GeoRasterFile.registerExtension("img", GdalFile.class); |
|
388 |
GeoRasterFile.registerExtension("tif", GdalFile.class); |
|
389 |
} |
|
390 |
|
|
391 |
public GdalFile(IProjection proj, String fName) { |
|
392 |
super(proj, fName); |
|
393 |
extent = new Extent(); |
|
394 |
try { |
|
395 |
file = new GdalNative(fName); |
|
396 |
showOnOpen(); |
|
397 |
load(); |
|
398 |
bandCount = file.getRasterCount(); |
|
399 |
if ( bandCount > 2) { |
|
400 |
setBand(RED_BAND, 0); |
|
401 |
setBand(GREEN_BAND, 1); |
|
402 |
setBand(BLUE_BAND, 2); |
|
403 |
} else |
|
404 |
setBand(RED_BAND|GREEN_BAND|BLUE_BAND, 0); |
|
405 |
} catch(Exception e){ |
|
406 |
System.out.println("Error en GdalOpen"); |
|
407 |
e.printStackTrace(); |
|
408 |
file = null; |
|
409 |
} |
|
410 |
int dataType = file.getDataType(); |
|
411 |
if (dataType == Gdal.GDT_Byte) |
|
412 |
setDataType(DataBuffer.TYPE_BYTE); |
|
413 |
else if (dataType == Gdal.GDT_CInt16 || dataType == Gdal.GDT_Int16) |
|
414 |
setDataType(DataBuffer.TYPE_SHORT); |
|
415 |
else if(dataType == Gdal.GDT_UInt16) |
|
416 |
setDataType(DataBuffer.TYPE_USHORT); |
|
417 |
} |
|
418 |
|
|
419 |
public GeoFile load() { |
|
420 |
/*double minX, minY, maxX, maxY; |
|
421 |
minX = minY = 0D; |
|
422 |
maxX = (double) width; |
|
423 |
maxY = (double) height;*/ |
|
424 |
extent = new Extent(file.esq.minX, file.esq.minY, file.esq.maxX, file.esq.maxY); |
|
425 |
return this; |
|
426 |
} |
|
427 |
|
|
428 |
public void close() { |
|
429 |
try { |
|
430 |
file.close(); |
|
431 |
} catch (GdalException e) { |
|
432 |
// TODO Auto-generated catch block |
|
433 |
e.printStackTrace(); |
|
434 |
} |
|
435 |
} |
|
436 |
|
|
437 |
public void setBand(int flag, int bandNr) { |
|
438 |
super.setBand(flag, bandNr); |
|
439 |
if ((flag & GeoRasterFile.RED_BAND) == GeoRasterFile.RED_BAND) file.rBandNr = bandNr+1; |
|
440 |
if ((flag & GeoRasterFile.GREEN_BAND) == GeoRasterFile.GREEN_BAND) file.gBandNr = bandNr+1; |
|
441 |
if ((flag & GeoRasterFile.BLUE_BAND) == GeoRasterFile.BLUE_BAND) file.bBandNr = bandNr+1; |
|
442 |
} |
|
443 |
public void setView(Extent e) { v = new Extent(e); } |
|
444 |
public Extent getView() { return v; } |
|
445 |
|
|
446 |
public int getWidth() { return file.width; } |
|
447 |
public int getHeight() { return file.height;} |
|
448 |
|
|
449 |
/* (non-Javadoc) |
|
450 |
* @see org.cresques.io.GeoRasterFile#reProject(org.cresques.cts.ICoordTrans) |
|
451 |
*/ |
|
452 |
public void reProject(ICoordTrans rp) { |
|
453 |
// TODO Auto-generated method stub |
|
454 |
|
|
455 |
} |
|
456 |
/* (non-Javadoc) |
|
457 |
* @see org.cresques.io.GeoRasterFile#setTransparency(boolean) |
|
458 |
* / |
|
459 |
public void setTransparency(boolean t) { |
|
460 |
// TODO Auto-generated method stub |
|
461 |
} |
|
462 |
public void setTransparency(int t) { |
|
463 |
// TODO Auto-generated method stub |
|
464 |
}*/ |
|
465 |
/* (non-Javadoc) |
|
466 |
* @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.cts.ICoordTrans) |
|
467 |
*/ |
|
468 |
public Image updateImage(int width, int height, ICoordTrans rp) { |
|
469 |
double dFileAspect, dWindowAspect; |
|
470 |
int line, pRGBArray[] = null; |
|
471 |
Image image = null; |
|
472 |
|
|
473 |
// Work out the correct aspect for the setView call. |
|
474 |
dFileAspect = (double)v.width()/(double)v.height(); |
|
475 |
dWindowAspect = (double)width /(double)height; |
|
476 |
|
|
477 |
if (dFileAspect > dWindowAspect) { |
|
478 |
height =(int)((double)width/dFileAspect); |
|
479 |
} else { |
|
480 |
width = (int)((double)height*dFileAspect); |
|
481 |
} |
|
482 |
|
|
483 |
// Set the view |
|
484 |
file.setView(v.minX(), v.maxY(), v.maxX(), v.minY(), |
|
485 |
width, height); |
|
486 |
|
|
487 |
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); |
|
488 |
//image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); |
|
489 |
pRGBArray = new int[width/**BAND_HEIGHT*/]; |
|
490 |
try { |
|
491 |
//int nLin = height % BAND_HEIGHT; |
|
492 |
file.setAlpha(getAlpha()); |
|
493 |
setBand(RED_BAND, rBandNr); |
|
494 |
setBand(GREEN_BAND, gBandNr); |
|
495 |
setBand(BLUE_BAND, bBandNr); |
|
496 |
for (line=0; line < height; line++) { //+=BAND_HEIGHT) { |
|
497 |
//int bandH = Math.min(BAND_HEIGHT, height-line); |
|
498 |
//file.readBandRGBA(bandH, BAND_HEIGHT, pRGBArray); |
|
499 |
file.readLineRGBA(pRGBArray); |
|
500 |
setRGBLine((BufferedImage) image, 0, line, width, 1/*bandH*/, pRGBArray, 0, width); |
|
501 |
} |
|
502 |
} catch (Exception e) { |
|
503 |
// TODO Auto-generated catch block |
|
504 |
e.printStackTrace(); |
|
505 |
} |
|
506 |
|
|
507 |
return image; |
|
508 |
} |
|
509 |
|
|
510 |
public Raster getRaster(int width, int height, ICoordTrans rp) { |
|
511 |
double dFileAspect, dWindowAspect; |
|
512 |
int line, pRGBArray[][] = null; |
|
513 |
WritableRaster raster = null; |
|
514 |
|
|
515 |
// Work out the correct aspect for the setView call. |
|
516 |
dFileAspect = (double)v.width()/(double)v.height(); |
|
517 |
dWindowAspect = (double)width /(double)height; |
|
518 |
|
|
519 |
if (dFileAspect > dWindowAspect) { |
|
520 |
height =(int)((double)width/dFileAspect); |
|
521 |
} else { |
|
522 |
width = (int)((double)height*dFileAspect); |
|
523 |
} |
|
524 |
|
|
525 |
// Set the view |
|
526 |
file.setView(v.minX(), v.maxY(), v.maxX(), v.minY(), |
|
527 |
width, height); |
|
528 |
|
|
529 |
raster = Raster.createBandedRaster(getDataType(), width, height, 3, new Point(0,0)); |
|
530 |
//image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); |
|
531 |
pRGBArray = new int[3][width/**BAND_HEIGHT*/]; |
|
532 |
try { |
|
533 |
//int nLin = height % BAND_HEIGHT; |
|
534 |
file.setAlpha(getAlpha()); |
|
535 |
setBand(RED_BAND, rBandNr); |
|
536 |
setBand(GREEN_BAND, gBandNr); |
|
537 |
setBand(BLUE_BAND, bBandNr); |
|
538 |
for (line=0; line < height; line++) { //+=BAND_HEIGHT) { |
|
539 |
//int bandH = Math.min(BAND_HEIGHT, height-line); |
|
540 |
//file.readBandRGBA(bandH, BAND_HEIGHT, pRGBArray); |
|
541 |
file.readLine(pRGBArray); |
|
542 |
raster.setSamples(0, line, width, 1, 0, pRGBArray[0]); |
|
543 |
raster.setSamples(0, line, width, 1, 1, pRGBArray[1]); |
|
544 |
raster.setSamples(0, line, width, 1, 2, pRGBArray[2]); |
|
545 |
// setRGBLine((BufferedImage) image, 0, line, width, 1/*bandH*/, pRGBArray, 0, width); |
|
546 |
} |
|
547 |
} catch (Exception e) { |
|
548 |
// TODO Auto-generated catch block |
|
549 |
e.printStackTrace(); |
|
550 |
} |
|
551 |
|
|
552 |
return raster; |
|
553 |
} |
|
554 |
protected void setRGBLine(BufferedImage image, int startX, int startY, int w, int h, int[] rgbArray, |
|
555 |
int offset, int scansize) { |
|
556 |
image.setRGB(startX, startY, w, h, rgbArray, offset, scansize); |
|
557 |
} |
|
558 |
|
|
559 |
protected void setRGBLine(BufferedImage image, int startX, int startY, int w, int h, int[] rgbArray, |
|
560 |
int offset, int scansize, int flags) { |
|
561 |
int [] line = new int[rgbArray.length]; |
|
562 |
image.getRGB(startX, startY, w, h, line, offset, scansize); |
|
563 |
if (flags == GeoRasterFile.RED_BAND) |
|
564 |
for (int i=0; i<line.length; i++) |
|
565 |
line[i] = (line[i] & 0x0000ffff) | (rgbArray[i] & 0xffff0000); |
|
566 |
else if (flags == GeoRasterFile.GREEN_BAND) |
|
567 |
for (int i=0; i<line.length; i++) |
|
568 |
line[i] = (line[i] & 0x00ff00ff) | (rgbArray[i] & 0xff00ff00); |
|
569 |
else if (flags == GeoRasterFile.BLUE_BAND) |
|
570 |
for (int i=0; i<line.length; i++) |
|
571 |
line[i] = (line[i] & 0x00ffff00) | (rgbArray[i] & 0xff0000ff); |
|
572 |
image.setRGB(startX, startY, w, h, line, offset, scansize); |
|
573 |
} |
|
574 |
|
|
575 |
private void showOnOpen() { |
|
576 |
// Report en la apertura (quitar) |
|
577 |
System.out.println("Fichero GDAL '"+getName()+"' abierto."); |
|
578 |
System.out.println("Version = "+file.version); |
|
579 |
System.out.println(" Size = ("+file.width+","+file.height+")"); |
|
580 |
try { |
|
581 |
System.out.println(" NumBands = ("+file.getRasterCount()+")"); |
|
582 |
} catch (GdalException e) { |
|
583 |
// TODO Auto-generated catch block |
|
584 |
e.printStackTrace(); |
|
585 |
} |
|
586 |
file.pintaInfo(); |
|
587 |
file.pintaPaleta(); |
|
588 |
|
|
589 |
} |
|
590 |
|
|
591 |
/* (non-Javadoc) |
|
592 |
* @see org.cresques.io.GeoRasterFile#updateImage(int, int, org.cresques.cts.ICoordTrans, java.awt.Image, int) |
|
593 |
*/ |
|
594 |
public Image updateImage(int width, int height, ICoordTrans rp, Image img, int flags) { |
|
595 |
double dFileAspect, dWindowAspect; |
|
596 |
int line, pRGBArray[] = null; |
|
597 |
|
|
598 |
// Work out the correct aspect for the setView call. |
|
599 |
dFileAspect = (double)v.width()/(double)v.height(); |
|
600 |
dWindowAspect = (double)width /(double)height; |
|
601 |
|
|
602 |
if (dFileAspect > dWindowAspect) { |
|
603 |
height =(int)((double)width/dFileAspect); |
|
604 |
} else { |
|
605 |
width = (int)((double)height*dFileAspect); |
|
606 |
} |
|
607 |
|
|
608 |
// Set the view |
|
609 |
file.setView(v.minX(), v.maxY(), v.maxX(), v.minY(), |
|
610 |
width, height); |
|
611 |
|
|
612 |
pRGBArray = new int[width/**BAND_HEIGHT*/]; |
|
613 |
try { |
|
614 |
//int nLin = height % BAND_HEIGHT; |
|
615 |
setBand(RED_BAND, rBandNr); |
|
616 |
setBand(GREEN_BAND, gBandNr); |
|
617 |
setBand(BLUE_BAND, bBandNr); |
|
618 |
file.setAlpha(getAlpha()); |
|
619 |
for (line=0; line < height; line++) { //+=BAND_HEIGHT) { |
|
620 |
//int bandH = Math.min(BAND_HEIGHT, height-line); |
|
621 |
//file.readBandRGBA(bandH, BAND_HEIGHT, pRGBArray); |
|
622 |
file.readLineRGBA(pRGBArray); |
|
623 |
setRGBLine((BufferedImage) img, 0, line, width, 1/*bandH*/, pRGBArray, 0, width, flags); |
|
624 |
} |
|
625 |
} catch (Exception e) { |
|
626 |
// TODO Auto-generated catch block |
|
627 |
e.printStackTrace(); |
|
628 |
} |
|
629 |
|
|
630 |
return img; |
|
631 |
} |
|
632 |
|
|
633 |
/* (non-Javadoc) |
|
634 |
* @see org.cresques.io.GeoRasterFile#getData(int, int, int) |
|
635 |
*/ |
|
636 |
public Object getData(int x, int y, int band) { |
|
637 |
// TODO Auto-generated method stub |
|
638 |
return null; |
|
639 |
} |
|
640 |
} |
|
641 |
|
|
642 |
|
|
0 | 643 |
branches/v02_desarrollo/libraries/libCq CMS for java.old/src-dvp/org/cresques/io/AliaMapServerClient.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 16-dic-2004 |
|
3 |
*/ |
|
4 |
package org.cresques.io; |
|
5 |
|
|
6 |
import org.cresques.px.Extent; |
|
7 |
|
|
8 |
/** |
|
9 |
* Consulta el servidor de mapas de Alia de Sevilla. |
|
10 |
* (hecho por tracasa) |
|
11 |
* ver http://sevilla.tracasa.es/navegar/?lang=cas |
|
12 |
* Implementa una llamada del tipo: |
|
13 |
* http://sevilla.tracasa.es/navegar/asp/mime.aspx? |
|
14 |
* TIPO=0&Xmin=225916.666666667&Ymin=4133000& |
|
15 |
* Xmax=254583.333333333&Ymax=4150000&PixAncho=430&PixAlto=255 |
|
16 |
* @author Luis W. Sevilla (sevilla_lui@gva.es) |
|
17 |
*/ |
|
18 |
public class AliaMapServerClient extends MapServerClient { |
|
19 |
public final static int CAPA_ORTOFOTO_2000 = 0; |
|
20 |
public final static int CAPA_ORTOFOTO_7500 = 1; |
|
21 |
public final static int CAPA_GUIA_URBANA = 2; |
|
22 |
|
|
23 |
public final static String [] nomCapas = { |
|
24 |
"Ortofoto 1:2.000 (Noviembre 2.001)", |
|
25 |
"Ortofoto 1:7.500 (Enero 1.999)", |
|
26 |
"Guía Urbana (Marzo 1.999)"}; |
|
27 |
|
|
28 |
private int capas = CAPA_ORTOFOTO_2000; |
|
29 |
|
|
30 |
public AliaMapServerClient(String serverName) { |
|
31 |
super(serverName); |
|
32 |
urlBase = "http://sevilla.tracasa.es/navegar/asp/mime.aspx"; |
|
33 |
setExtent(new Extent(225916.67, 4150000.0, 254583.3, 4133000.0)); |
|
34 |
setMaxViewSize(650,400); |
|
35 |
} |
|
36 |
|
|
37 |
public void setCapas(int c) { capas = c; } |
|
38 |
|
|
39 |
public String getUrl() { |
|
40 |
String url = urlBase+"?"+ |
|
41 |
"TIPO="+capas+"&"+ |
|
42 |
"Xmin="+xMin+"&"+ "Ymin="+yMax+"&"+ |
|
43 |
"Xmax="+xMax+"&"+ "Ymax="+yMin+"&"+ |
|
44 |
"PixAncho="+ancho+"&"+"PixAlto="+alto;; |
|
45 |
return url; |
|
46 |
} |
|
47 |
} |
|
0 | 48 |
branches/v02_desarrollo/libraries/libCq CMS for java.old/src-dvp/org/cresques/io/SitnaMapServerClient.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 16-dic-2004 |
|
3 |
*/ |
|
4 |
package org.cresques.io; |
|
5 |
|
|
6 |
import org.cresques.px.Extent; |
|
7 |
|
|
8 |
/** |
|
9 |
* Consulta el servidor de mapas de Sitna de Navarra. |
|
10 |
* (hecho por tracasa) |
|
11 |
* ver http://sitna.tracasa.es/navegar/?lang=cas |
|
12 |
* Implementa una llamada del tipo: |
|
13 |
* http://sitna.tracasa.es/navegar/asp/mime.aspx? |
|
14 |
* TIPO=0&Xmin=450321.428571429&Ymin=628000& |
|
15 |
* Xmax=780678.571428571&Ymax=813000&PixAncho=500&PixAlto=280 |
|
16 |
* @author Luis W. Sevilla (sevilla_lui@gva.es) |
|
17 |
*/ |
|
18 |
public class SitnaMapServerClient extends MapServerClient { |
|
19 |
public final static int CAPA_ORTOCOLOR_2K_03 = 0; |
|
20 |
public final static int CAPA_ORTOFOTO_7500 = 1; |
|
21 |
public final static int CAPA_GUIA_URBANA = 2; |
|
22 |
|
|
23 |
public final static String [] nomCapas = { |
|
24 |
"Ortofoto Color 1:5.000 - A?o 2.003", |
|
25 |
"Ortofoto Color 1:5.000 - A?os 98-00", |
|
26 |
"Ortofoto Color 1:2.000", |
|
27 |
"Ortofoto Color 1:1.000", |
|
28 |
"Mapa de Relieve Color (25 m)", |
|
29 |
"Mapa de Relieve B/N (7,5 m)", |
|
30 |
"Cartograf?a Topogr?fica", |
|
31 |
"Catastro", |
|
32 |
"Catastro + Ortofoto 1:5.000", |
|
33 |
"LANDSAT-5 27/05/91 Falso Color", |
|
34 |
"LANDSAT-5 27/05/91 Pseudocolor", |
|
35 |
"LANDSAT-5 12/06/91 Falso Color", |
|
36 |
"LANDSAT-5 12/06/91 Pseudocolor", |
|
37 |
"LANDSAT-5 15/08/91 Falso Color", |
|
38 |
"LANDSAT-5 15/08/91 Pseudocolor", |
|
39 |
"LANDSAT-5 13/05/92 Falso Color", |
|
40 |
"LANDSAT-5 13/05/92 Pseudocolor", |
|
41 |
"LANDSAT-5 17/08/92 Falso Color", |
|
42 |
"LANDSAT-5 17/08/92 Pseudocolor", |
|
43 |
"LANDSAT-5 01/06/93 Falso Color", |
|
44 |
"LANDSAT-5 01/06/93 Pseudocolor", |
|
45 |
"LANDSAT-5 20/08/93 Falso Color", |
|
46 |
"LANDSAT-5 20/08/93 Pseudocolor", |
|
47 |
"LANDSAT-5 03/05/94 Falso Color", |
|
48 |
"LANDSAT-5 03/05/94 Pseudocolor", |
|
49 |
"LANDSAT-5 23/08/94 Falso Color", |
|
50 |
"LANDSAT-5 23/08/94 Pseudocolor", |
|
51 |
"LANDSAT-5 04/04/95 Falso Color", |
|
52 |
"LANDSAT-5 04/04/95 Pseudocolor", |
|
53 |
"LANDSAT-5 10/08/95 Falso Color", |
|
54 |
"LANDSAT-5 10/08/95 Pseudocolor", |
|
55 |
"LANDSAT-5 24/05/96 Falso Color", |
|
56 |
"LANDSAT-5 24/05/96 Pseudocolor", |
|
57 |
"LANDSAT-5 11/07/96 Falso Color", |
|
58 |
"LANDSAT-5 11/07/96 Pseudocolor", |
|
59 |
"LANDSAT-5 08/03/97 Falso Color", |
|
60 |
"LANDSAT-5 08/03/97 Pseudocolor", |
|
61 |
"LANDSAT-5 27/03/98 Falso Color", |
|
62 |
"LANDSAT-5 27/03/98 Pseudocolor", |
|
63 |
"LANDSAT-5 30/03/99 Falso Color", |
|
64 |
"LANDSAT-5 30/03/99 Pseudocolor", |
|
65 |
"LANDSAT-5 21/08/99 Falso Color", |
|
66 |
"LANDSAT-5 21/08/99 Pseudocolor", |
|
67 |
"LANDSAT-7 08/03/00 Falso Color", |
|
68 |
"LANDSAT-7 08/03/00 Pseudocolor", |
|
69 |
"LANDSAT-5 07/08/00 Falso Color", |
|
70 |
"LANDSAT-5 07/08/00 Pseudocolor", |
|
71 |
"LANDSAT-7 28/04/01 Falso Color", |
|
72 |
"LANDSAT-7 28/04/01 Pseudocolor", |
|
73 |
"LANDSAT-5 31/07/03 Falso Color", |
|
74 |
"LANDSAT-5 31/07/03 Pseudocolor", |
|
75 |
"IRS-1C 13/04/97 Falso Color", |
|
76 |
"IRS-1C 13/04/97 Pseudocolor", |
|
77 |
"IRS-1C 04/09/97 Falso Color", |
|
78 |
"IRS-1C 04/09/97 Pseudocolor", |
|
79 |
"IRS-1C 19/06/98 Falso Color", |
|
80 |
"IRS-1C 19/06/98 Pseudocolor", |
|
81 |
"IRS-1C 06/08/98 Falso Color", |
|
82 |
"IRS-1C 06/08/98 Pseudocolor", |
|
83 |
"IRS-1D 15/06/99 Falso Color", |
|
84 |
"IRS-1D 15/06/99 Pseudocolor", |
|
85 |
"IRS-1C 08/06/00 Falso Color", |
|
86 |
"IRS-1C 08/06/00 Pseudocolor", |
|
87 |
"IRS-1D 23/08/01 Falso Color", |
|
88 |
"IRS-1D 23/08/01 Pseudocolor", |
|
89 |
"IRS-1D 05/04/02 Falso Color", |
|
90 |
"IRS-1D 05/04/02 Pseudocolor", |
|
91 |
"IRS-1C 26/09/02 Falso Color", |
|
92 |
"IRS-1C 26/09/02 Pseudocolor", |
|
93 |
"IRS-1D 10/05/03 Falso Color", |
|
94 |
"IRS-1D 10/05/03 Pseudocolor"}; |
|
95 |
|
|
96 |
private int capas = CAPA_ORTOCOLOR_2K_03; |
|
97 |
|
|
98 |
public SitnaMapServerClient(String serverName) { |
|
99 |
super(serverName); |
|
100 |
urlBase = "http://sitna.tracasa.es/navegar/asp/mime.aspx"; |
|
101 |
setExtent(new Extent(450321.428571429, 813000, 780678.571428571, 628000)); |
|
102 |
setMaxViewSize(700,420); |
|
103 |
} |
|
104 |
|
|
105 |
public void setCapas(int c) { capas = c; } |
|
106 |
|
|
107 |
public String getUrl() { |
|
108 |
String url = urlBase+"?"+ |
|
109 |
"TIPO="+capas+"&"+ |
|
110 |
"Xmin="+xMin+"&"+ "Ymin="+yMax+"&"+ |
|
111 |
"Xmax="+xMax+"&"+ "Ymax="+yMin+"&"+ |
|
112 |
"PixAncho="+ancho+"&"+"PixAlto="+alto;; |
|
113 |
return url; |
|
114 |
} |
|
115 |
} |
|
0 | 116 |
branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/io/MrSidFile.java | ||
---|---|---|
60 | 60 |
|
61 | 61 |
private int alpha = 0; |
62 | 62 |
protected int rBandNr = 1, gBandNr = 2, bBandNr = 3; |
63 |
protected byte [] bandR, bandG, bandB; |
|
63 | 64 |
private int dataType = LTIDataType.LTI_DATATYPE_UINT8; |
64 | 65 |
|
65 | 66 |
//View |
... | ... | |
273 | 274 |
SceneWidth = (int) (((double)currentViewWidth)/viewportScale); |
274 | 275 |
SceneHeight = (int) (((double)currentViewHeight)/viewportScale); |
275 | 276 |
} |
276 |
|
|
277 |
|
|
278 |
|
|
277 |
|
|
279 | 278 |
if(SceneWidth==0)SceneWidth=1; |
280 | 279 |
if(SceneHeight==0)SceneHeight=1; |
281 | 280 |
System.out.println("2.9========>ColorSpace="+eColorSpace+" nbands="+nbands+" eSampleType="+eSampleType); |
... | ... | |
303 | 302 |
int kd, k; |
304 | 303 |
double scale = 1/viewportScale; |
305 | 304 |
int alpha = (this.alpha & 0xff) << 24; |
306 |
if(eColorSpace==LTIColorSpace.LTI_COLORSPACE_RGB) |
|
305 |
if (rBandNr == 1) bandR = buffer.buf1; |
|
306 |
else if (rBandNr == 2) bandR = buffer.buf2; |
|
307 |
else if (rBandNr == 3) bandR = buffer.buf3; |
|
308 |
if (gBandNr == 1) bandG = buffer.buf1; |
|
309 |
else if (gBandNr == 2) bandG = buffer.buf2; |
|
310 |
else if (gBandNr == 3) bandG = buffer.buf3; |
|
311 |
if (bBandNr == 1) bandB = buffer.buf1; |
|
312 |
else if (bBandNr == 2) bandB = buffer.buf2; |
|
313 |
else if (bBandNr == 3) bandB = buffer.buf3; |
|
314 |
if (eColorSpace==LTIColorSpace.LTI_COLORSPACE_RGB) |
|
307 | 315 |
//for(int k=0;k<buffer.size;k++) |
308 | 316 |
for (int y1=0; y1<currentViewHeight; y1++) |
309 | 317 |
for (int x1=0; x1<currentViewWidth; x1++) { |
310 | 318 |
kd = y1*currentViewWidth+x1; |
311 | 319 |
k = ((int) (y1*scale))*SceneWidth+ (int)(((double) x1)*scale); |
312 | 320 |
try { |
313 |
line[kd] = alpha + ((0xff & buffer.buf1[k])<<16) + (( 0xff & buffer.buf2[k])<<8) + (0xff & buffer.buf3[k]);
|
|
321 |
line[kd] = alpha + ((0xff & bandR[k])<<16) + (( 0xff & bandG[k])<<8) + (0xff & bandB[k]);
|
|
314 | 322 |
} catch (java.lang.ArrayIndexOutOfBoundsException e) { |
315 | 323 |
} |
316 | 324 |
} |
... | ... | |
350 | 358 |
showOnOpen(); |
351 | 359 |
load(); |
352 | 360 |
bandCount = file.nbands; |
353 |
if ( bandCount >= 3) { |
|
354 |
setBand(RED_BAND, 1); |
|
355 |
setBand(GREEN_BAND, 2); |
|
356 |
setBand(BLUE_BAND, 3); |
|
357 |
} |
|
361 |
if ( bandCount > 2) { |
|
362 |
setBand(RED_BAND, 0); |
|
363 |
setBand(GREEN_BAND, 1); |
|
364 |
setBand(BLUE_BAND, 2); |
|
365 |
} else |
|
366 |
setBand(RED_BAND|GREEN_BAND|BLUE_BAND, 0); |
|
358 | 367 |
} catch(Exception e){ |
359 | 368 |
System.out.println("Error en constructor de MrSID"); |
360 | 369 |
e.printStackTrace(); |
... | ... | |
373 | 382 |
|
374 | 383 |
public void setBand(int flag, int bandNr) { |
375 | 384 |
super.setBand(flag, bandNr); |
376 |
if ((flag & GeoRasterFile.RED_BAND) == GeoRasterFile.RED_BAND) file.rBandNr = bandNr; |
|
377 |
if ((flag & GeoRasterFile.GREEN_BAND) == GeoRasterFile.GREEN_BAND) file.gBandNr = bandNr; |
|
378 |
if ((flag & GeoRasterFile.BLUE_BAND) == GeoRasterFile.BLUE_BAND) file.bBandNr = bandNr; |
|
385 |
if ((flag & GeoRasterFile.RED_BAND) == GeoRasterFile.RED_BAND) file.rBandNr = bandNr+1;
|
|
386 |
if ((flag & GeoRasterFile.GREEN_BAND) == GeoRasterFile.GREEN_BAND) file.gBandNr = bandNr+1;
|
|
387 |
if ((flag & GeoRasterFile.BLUE_BAND) == GeoRasterFile.BLUE_BAND) file.bBandNr = bandNr+1;
|
|
379 | 388 |
} |
380 | 389 |
public void setView(Extent e) { v = new Extent(e); } |
381 | 390 |
public Extent getView() { return v; } |
... | ... | |
412 | 421 |
|
413 | 422 |
file.setView(v.minX(), v.maxY(), v.maxX(), v.minY(),width, height); |
414 | 423 |
System.out.println("1========>"+v.minX()+","+ v.maxY()+","+v.maxX()+","+v.minY()+","+width+","+height); |
415 |
file.setAlpha(getAlpha()); |
|
416 | 424 |
|
417 | 425 |
//Impedimos que los valores de ancho y alto de la im?gen sean menores que 1 |
418 | 426 |
|
... | ... | |
425 | 433 |
|
426 | 434 |
try { |
427 | 435 |
System.out.println("1.5========>"+width+","+height); |
436 |
file.setAlpha(getAlpha()); |
|
437 |
setBand(RED_BAND, rBandNr); |
|
438 |
setBand(GREEN_BAND, gBandNr); |
|
439 |
setBand(BLUE_BAND, bBandNr); |
|
440 |
|
|
428 | 441 |
file.readScene(pRGBArray); |
429 | 442 |
((BufferedImage)image).setRGB(0, 0, width, height, pRGBArray, 0, width); |
430 | 443 |
|
branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/io/GeoRasterFile.java | ||
---|---|---|
7 | 7 |
|
8 | 8 |
import java.awt.Component; |
9 | 9 |
import java.awt.Image; |
10 |
import java.awt.image.DataBuffer; |
|
10 | 11 |
import java.lang.reflect.Constructor; |
11 | 12 |
import java.lang.reflect.InvocationTargetException; |
12 | 13 |
import java.util.TreeMap; |
... | ... | |
34 | 35 |
public static final int RED_BAND = 0x01; |
35 | 36 |
public static final int GREEN_BAND = 0x02; |
36 | 37 |
public static final int BLUE_BAND = 0x04; |
38 |
|
|
37 | 39 |
/** |
38 | 40 |
* Filtro para raster. |
39 | 41 |
* Permite eliminar la franja inutil alrededor de un raster girado o de |
... | ... | |
132 | 134 |
|
133 | 135 |
protected int rBandNr = 1, gBandNr = 1, bBandNr = 1; |
134 | 136 |
protected int bandCount = 1; |
137 |
private int dataType = DataBuffer.TYPE_BYTE; |
|
135 | 138 |
|
136 | 139 |
static { |
137 | 140 |
supportedExtensions = new TreeMap(); |
... | ... | |
257 | 260 |
if (!doTransparency) setTransparency(255 - alpha); |
258 | 261 |
else tFilter.setAlpha(alpha); |
259 | 262 |
} |
260 |
public int getAlpha() { return tFilter.getAlpha(); } |
|
263 |
public int getAlpha() { |
|
264 |
if (tFilter == null) |
|
265 |
return 255; |
|
266 |
return tFilter.getAlpha(); |
|
267 |
} |
|
261 | 268 |
|
262 | 269 |
public void setUpdatable(Component c) { updatable = c; } |
263 | 270 |
|
... | ... | |
310 | 317 |
return -1; |
311 | 318 |
} |
312 | 319 |
|
320 |
/** |
|
321 |
* @return Returns the dataType. |
|
322 |
*/ |
|
323 |
public int getDataType() { |
|
324 |
return dataType; |
|
325 |
} |
|
326 |
/** |
|
327 |
* @param dataType The dataType to set. |
|
328 |
*/ |
|
329 |
public void setDataType(int dataType) { |
|
330 |
this.dataType = dataType; |
|
331 |
} |
|
332 |
|
|
313 | 333 |
public IObjList getObjects() { |
314 | 334 |
// TODO hay que a?adir el raster a la lista de objetos |
315 | 335 |
IObjList oList = new PxObjList(proj); |
branches/v02_desarrollo/libraries/libCq CMS for java.old/src/org/cresques/px/PxRaster.java | ||
---|---|---|
3 | 3 |
*/ |
4 | 4 |
package org.cresques.px; |
5 | 5 |
|
6 |
import java.awt.geom.GeneralPath; |
|
7 |
import java.awt.geom.Point2D; |
|
8 |
|
|
9 | 6 |
import java.awt.Color; |
10 | 7 |
import java.awt.Component; |
11 | 8 |
import java.awt.Graphics2D; |
12 | 9 |
import java.awt.Image; |
13 |
|
|
10 |
import java.awt.geom.GeneralPath; |
|
11 |
import java.awt.geom.Point2D; |
|
12 |
import java.awt.image.BufferedImage; |
|
13 |
import java.awt.image.DataBuffer; |
|
14 | 14 |
import java.awt.image.ImageObserver; |
15 |
import java.awt.image.Raster; |
|
15 | 16 |
import java.util.Date; |
16 | 17 |
import java.util.Vector; |
17 | 18 |
|
... | ... | |
19 | 20 |
import org.cresques.cts.IProjection; |
20 | 21 |
import org.cresques.geo.Projected; |
21 | 22 |
import org.cresques.geo.ViewPortData; |
22 |
//import org.cresques.io.EcwFile;
|
|
23 |
import org.cresques.io.GdalFile;
|
|
23 | 24 |
import org.cresques.io.GeoRasterFile; |
24 | 25 |
|
25 | 26 |
public class PxRaster extends PxObj implements Projected { |
... | ... | |
54 | 55 |
setExtent(geoFile.getExtent()); |
55 | 56 |
geoFile.setView(geoFile.getExtent()); |
56 | 57 |
extentOrig = extent; |
58 |
if (geoFile.getBandCount()>2) { |
|
59 |
setBand(GeoRasterFile.RED_BAND, 0); |
|
60 |
setBand(GeoRasterFile.GREEN_BAND, 1); |
|
61 |
setBand(GeoRasterFile.BLUE_BAND, 2); |
|
62 |
} else { |
|
63 |
setBand(GeoRasterFile.RED_BAND|GeoRasterFile.GREEN_BAND|GeoRasterFile.BLUE_BAND, 0); |
|
64 |
} |
|
57 | 65 |
} |
58 | 66 |
|
59 | 67 |
/*public PxRaster(String fname, ImageObserver component, Extent view) { |
... | ... | |
79 | 87 |
} |
80 | 88 |
geoFile = colorBand[0]; |
81 | 89 |
extentOrig = extent; |
82 |
if (fnames.length >= 3) { |
|
83 |
this.setBand(GeoRasterFile.RED_BAND, 0);
|
|
84 |
this.setBand(GeoRasterFile.GREEN_BAND, 1);
|
|
85 |
this.setBand(GeoRasterFile.BLUE_BAND, 2);
|
|
90 |
if (fnames.length >= 3 || geoFile.getBandCount()>2) {
|
|
91 |
setBand(GeoRasterFile.RED_BAND, 0); |
|
92 |
setBand(GeoRasterFile.GREEN_BAND, 1); |
|
93 |
setBand(GeoRasterFile.BLUE_BAND, 2); |
|
86 | 94 |
} else { |
87 |
this.setBand(GeoRasterFile.RED_BAND|GeoRasterFile.GREEN_BAND|GeoRasterFile.BLUE_BAND, 1);
|
|
95 |
setBand(GeoRasterFile.RED_BAND|GeoRasterFile.GREEN_BAND|GeoRasterFile.BLUE_BAND, 0);
|
|
88 | 96 |
} |
89 | 97 |
} |
90 | 98 |
|
... | ... | |
97 | 105 |
setExtent(geoFile.getExtent()); |
98 | 106 |
geoFile.setView(view); //geoFile.getExtent()); |
99 | 107 |
extentOrig = extent; |
108 |
if (geoFile.getBandCount()>2) { |
|
109 |
setBand(GeoRasterFile.RED_BAND, 0); |
|
110 |
setBand(GeoRasterFile.GREEN_BAND, 1); |
|
111 |
setBand(GeoRasterFile.BLUE_BAND, 2); |
|
112 |
} else { |
|
113 |
setBand(GeoRasterFile.RED_BAND|GeoRasterFile.GREEN_BAND|GeoRasterFile.BLUE_BAND, 0); |
|
114 |
} |
|
100 | 115 |
} |
101 | 116 |
|
102 | 117 |
public int getBandCount() { return geoFile.getBandCount(); } |
103 | 118 |
|
119 |
public GeoRasterFile [] getFiles() { |
|
120 |
if (colorBand != null) |
|
121 |
return colorBand; |
|
122 |
|
|
123 |
GeoRasterFile [] ret = {geoFile}; |
|
124 |
return ret; |
|
125 |
} |
|
126 |
|
|
104 | 127 |
/** |
105 | 128 |
* Asocia un colorBand al rojo, verde o azul. |
106 | 129 |
* @param flag cual (o cuales) de las bandas. |
... | ... | |
108 | 131 |
*/ |
109 | 132 |
|
110 | 133 |
public void setBand(int flag, int nBand) { |
111 |
if ((flag & GeoRasterFile.RED_BAND) == GeoRasterFile.RED_BAND) rBand = nBand; |
|
112 |
if ((flag & GeoRasterFile.GREEN_BAND) == GeoRasterFile.GREEN_BAND) gBand = nBand; |
|
113 |
if ((flag & GeoRasterFile.BLUE_BAND) == GeoRasterFile.BLUE_BAND) bBand = nBand; |
|
134 |
if (colorBand != null) { |
|
135 |
if ((flag & GeoRasterFile.RED_BAND) == GeoRasterFile.RED_BAND) |
|
136 |
rBand = nBand; |
|
137 |
else if ((flag & GeoRasterFile.GREEN_BAND) == GeoRasterFile.GREEN_BAND) |
|
138 |
gBand = nBand; |
|
139 |
else if ((flag & GeoRasterFile.BLUE_BAND) == GeoRasterFile.BLUE_BAND) |
|
140 |
bBand = nBand; |
|
141 |
} else |
|
142 |
geoFile.setBand(flag, nBand); |
|
114 | 143 |
} |
115 | 144 |
|
116 | 145 |
/** |
... | ... | |
119 | 148 |
*/ |
120 | 149 |
|
121 | 150 |
public int getBand(int flag) { |
122 |
if (flag == GeoRasterFile.RED_BAND) return rBand; |
|
123 |
if (flag == GeoRasterFile.GREEN_BAND) return gBand; |
|
124 |
if (flag == GeoRasterFile.BLUE_BAND) return bBand; |
|
125 |
return -1; |
|
151 |
if (colorBand != null) { |
|
152 |
if (flag == GeoRasterFile.RED_BAND) |
|
153 |
return rBand; |
|
154 |
else if (flag == GeoRasterFile.GREEN_BAND) |
|
155 |
return gBand; |
|
156 |
else if (flag == GeoRasterFile.BLUE_BAND) |
|
157 |
return bBand; |
|
158 |
else |
Also available in: Unified diff