svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrRaster.java @ 8360
History | View | Annotate | Download (22.3 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.layers; |
42 |
|
43 |
import java.awt.Dimension; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.Point; |
46 |
import java.awt.Rectangle; |
47 |
import java.awt.geom.AffineTransform; |
48 |
import java.awt.geom.NoninvertibleTransformException; |
49 |
import java.awt.geom.Point2D; |
50 |
import java.awt.geom.Rectangle2D; |
51 |
import java.awt.image.BufferedImage; |
52 |
import java.io.File; |
53 |
import java.lang.reflect.Constructor; |
54 |
import java.lang.reflect.InvocationTargetException; |
55 |
import java.util.ArrayList; |
56 |
|
57 |
import javax.swing.ImageIcon; |
58 |
|
59 |
import org.cresques.cts.IProjection; |
60 |
import org.cresques.filter.RasterFilterStack; |
61 |
import org.cresques.filter.RasterStats; |
62 |
import org.cresques.px.Extent; |
63 |
|
64 |
import com.hardcode.driverManager.Driver; |
65 |
import com.hardcode.driverManager.DriverLoadException; |
66 |
import com.iver.cit.gvsig.fmap.DriverException; |
67 |
import com.iver.cit.gvsig.fmap.MapControl; |
68 |
import com.iver.cit.gvsig.fmap.ViewPort; |
69 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
70 |
import com.iver.cit.gvsig.fmap.drivers.GeorreferencedRasterDriver; |
71 |
import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
72 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.StringXMLItem; |
73 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem; |
74 |
import com.iver.utiles.XMLEntity; |
75 |
import com.iver.utiles.swing.threads.Cancellable; |
76 |
|
77 |
|
78 |
/**
|
79 |
* Clase b?sica de capa raster.
|
80 |
*
|
81 |
* @author Vicente Caballero Navarro
|
82 |
*/
|
83 |
public class FLyrRaster extends FLyrDefault implements RasterOperations { |
84 |
private RasterAdapter source;
|
85 |
boolean isPrinting = false; |
86 |
boolean mustTileDraw = false; |
87 |
boolean mustTilePrint = true; |
88 |
private int maxTileDrawWidth = 200; |
89 |
private int maxTileDrawHeight = 200; |
90 |
int maxTilePrintWidth = 1500; |
91 |
int maxTilePrintHeight = 1500; |
92 |
private StatusRasterInterface status = null; |
93 |
private boolean firstLoad = false; |
94 |
private int posX = 0, posY = 0; |
95 |
private double posXWC = 0, posYWC = 0; |
96 |
private int r = 0, g = 0, b = 0; |
97 |
private boolean removeRasterFlag = true; |
98 |
|
99 |
/**
|
100 |
* Devuelve el RasterAdapter de la capa.
|
101 |
*
|
102 |
* @return RasterAdapter.
|
103 |
*/
|
104 |
public RasterAdapter getSource() {
|
105 |
return source;
|
106 |
} |
107 |
|
108 |
/**
|
109 |
*Redefine wakeUp de FLyrDefault
|
110 |
*/
|
111 |
public void wakeUp(){ |
112 |
/*setName(getName());
|
113 |
setProjection(getProjection());
|
114 |
try {
|
115 |
load();
|
116 |
} catch (DriverIOException e) {
|
117 |
e.printStackTrace();
|
118 |
}*/
|
119 |
} |
120 |
|
121 |
/**
|
122 |
* Inserta el RasterAdapter.
|
123 |
*
|
124 |
* @param ra RasterAdapter.
|
125 |
*/
|
126 |
public void setSource(RasterAdapter ra) { |
127 |
source = ra; |
128 |
} |
129 |
|
130 |
/**
|
131 |
* Devuelve la pila de filtros aplicada sobre la capa raster.
|
132 |
*
|
133 |
* @return RasterFilterStack.
|
134 |
*/
|
135 |
public RasterFilterStack getFilterStack(){
|
136 |
return source.getFilterStack();
|
137 |
} |
138 |
|
139 |
/**
|
140 |
* Asignar el estado del raster
|
141 |
* @param status
|
142 |
*/
|
143 |
public void setStatus(StatusRasterInterface status){ |
144 |
this.status = status;
|
145 |
} |
146 |
|
147 |
/**
|
148 |
* Asigna la pila de filtros aplicada al raster
|
149 |
* @return
|
150 |
*/
|
151 |
public void setFilterStack(RasterFilterStack stack){ |
152 |
source.setFilterStack(stack); |
153 |
} |
154 |
|
155 |
/**
|
156 |
* Obtiene el estado del raster
|
157 |
* @return
|
158 |
*/
|
159 |
public StatusRasterInterface getStatus(){
|
160 |
return this.status; |
161 |
} |
162 |
|
163 |
/**
|
164 |
* Asigna la posici?n en la que se ha hecho click al mostrar
|
165 |
* informaci?n del raster.
|
166 |
* @param x Posici?n en X
|
167 |
* @param y Posici?n en Y
|
168 |
*/
|
169 |
public void setPos(int x, int y){ |
170 |
this.posX = x;
|
171 |
this.posY = y;
|
172 |
} |
173 |
|
174 |
/**
|
175 |
* Asigna la posici?n en coordenadas del mundo real en la que se ha
|
176 |
* hecho click al mostrar informaci?n del raster.
|
177 |
* @param x Posici?n en X
|
178 |
* @param y Posici?n en Y
|
179 |
*/
|
180 |
public void setPosWC(double x, double y){ |
181 |
this.posXWC = x;
|
182 |
this.posYWC = y;
|
183 |
} |
184 |
|
185 |
/**
|
186 |
* Asigna RGB en la posici?n en la que se ha
|
187 |
* hecho click al mostrar informaci?n del raster.
|
188 |
* @param r valor de rojo
|
189 |
* @param g valor de verde
|
190 |
* @param b valor de azul
|
191 |
*/
|
192 |
public void setRGB(int r, int g, int b){ |
193 |
this.r = r;
|
194 |
this.g = g;
|
195 |
this.b = b;
|
196 |
} |
197 |
|
198 |
/*
|
199 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
|
200 |
*/
|
201 |
public void load() throws DriverIOException { |
202 |
((RasterFileAdapter) source).start(); |
203 |
((RasterFileAdapter) source).setTransparency(getTransparency()); |
204 |
} |
205 |
|
206 |
/**
|
207 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
208 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
|
209 |
* com.iver.utiles.swing.threads.Cancellable)
|
210 |
*/
|
211 |
public void draw(BufferedImage image, Graphics2D g, ViewPort vp, |
212 |
Cancellable cancel,double scale) throws DriverException { |
213 |
if (isWithinScale(scale)){
|
214 |
try {
|
215 |
if(status!=null && firstLoad){ |
216 |
if(mustTileDraw){
|
217 |
Point2D p = vp.getOffset();
|
218 |
Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), vp.getImageWidth(), vp.getImageHeight()); |
219 |
Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
|
220 |
tiles.setAffineTransform((AffineTransform) vp.getAffineTransform().clone());
|
221 |
for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) { |
222 |
// drawing part
|
223 |
try {
|
224 |
ViewPort vport = tiles.getTileViewPort(vp, tileNr); |
225 |
//g.setClip(tiles.getClip(tileNr).x, tiles.getClip(tileNr).y, tiles.getClip(tileNr).width - 5, tiles.getClip(tileNr).height);
|
226 |
((RasterFileAdapter) source).draw(image, g, vport, cancel); |
227 |
} catch (NoninvertibleTransformException e) { |
228 |
e.printStackTrace(); |
229 |
} |
230 |
} |
231 |
}else
|
232 |
((RasterFileAdapter) source).draw(image, g, vp, cancel); |
233 |
status.applyStatus(this);
|
234 |
firstLoad = false;
|
235 |
} |
236 |
|
237 |
if(mustTileDraw){
|
238 |
Point2D p = vp.getOffset();
|
239 |
Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), vp.getImageWidth(), vp.getImageHeight()); |
240 |
Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
|
241 |
tiles.setAffineTransform((AffineTransform) vp.getAffineTransform().clone());
|
242 |
for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) { |
243 |
// drawing part
|
244 |
try {
|
245 |
ViewPort vport = tiles.getTileViewPort(vp, tileNr); |
246 |
((RasterFileAdapter) source).draw(image, g, vport, cancel); |
247 |
} catch (NoninvertibleTransformException e) { |
248 |
e.printStackTrace(); |
249 |
} |
250 |
} |
251 |
}else
|
252 |
((RasterFileAdapter) source).draw(image, g, vp, cancel); |
253 |
|
254 |
} catch (DriverIOException e) {
|
255 |
throw new DriverException(e); |
256 |
} |
257 |
|
258 |
if (getVirtualLayers() != null) { |
259 |
getVirtualLayers().draw(image, g, vp, cancel,scale); |
260 |
} |
261 |
} |
262 |
} |
263 |
|
264 |
/**
|
265 |
* Inserta la proyecci?n.
|
266 |
*
|
267 |
* @param proj Proyecci?n.
|
268 |
*/
|
269 |
public void setProjection(IProjection proj) { |
270 |
super.setProjection(proj);
|
271 |
|
272 |
if (source != null && source.getDriver() != null && source.getDriver() instanceof GeorreferencedRasterDriver) { |
273 |
GeorreferencedRasterDriver geoDrv = (GeorreferencedRasterDriver) source.getDriver(); |
274 |
|
275 |
if (geoDrv.getProjection() == null) { |
276 |
geoDrv.setProjection(proj); |
277 |
} |
278 |
} |
279 |
} |
280 |
|
281 |
public void setTransparency(int trans) { |
282 |
super.setTransparency(trans);
|
283 |
((RasterFileAdapter) source).setTransparency(trans); |
284 |
if (getMapContext() != null){ |
285 |
getMapContext().invalidate(); |
286 |
} |
287 |
} |
288 |
|
289 |
public int getTransparency() { |
290 |
return ((RasterFileAdapter) source).getTransparency();
|
291 |
} |
292 |
|
293 |
/*
|
294 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
295 |
*/
|
296 |
public Rectangle2D getFullExtent() throws DriverException { |
297 |
return ((RasterFileAdapter) source).getFullExtent();
|
298 |
} |
299 |
|
300 |
/**
|
301 |
* Obtiene el valor del pixel del Image en la posici?n x,y
|
302 |
* @param x Posici?n x
|
303 |
* @param y Posici?n y
|
304 |
* @return valor de pixel
|
305 |
*/
|
306 |
public int[] getPixel(double wcx, double wcy){ |
307 |
return ((RasterFileAdapter) source).getPixel(wcx, wcy);
|
308 |
} |
309 |
|
310 |
public double getMaxX(){ |
311 |
try {
|
312 |
return this.getFullExtent().getMaxX(); |
313 |
}catch(DriverException e){
|
314 |
return 0D; |
315 |
} |
316 |
} |
317 |
|
318 |
public double getMaxY(){ |
319 |
try {
|
320 |
return this.getFullExtent().getMaxY(); |
321 |
}catch(DriverException e){
|
322 |
return 0D; |
323 |
} |
324 |
} |
325 |
|
326 |
public double getMinX(){ |
327 |
try {
|
328 |
return this.getFullExtent().getMinX(); |
329 |
}catch(DriverException e){
|
330 |
return 0D; |
331 |
} |
332 |
} |
333 |
|
334 |
public double getMinY(){ |
335 |
try {
|
336 |
return this.getFullExtent().getMinY(); |
337 |
}catch(DriverException e){
|
338 |
return 0D; |
339 |
} |
340 |
} |
341 |
|
342 |
public double getHeight(){ |
343 |
try {
|
344 |
return this.getFullExtent().getHeight(); |
345 |
}catch(DriverException e){
|
346 |
return 0D; |
347 |
} |
348 |
} |
349 |
|
350 |
public double getWidth(){ |
351 |
try {
|
352 |
return this.getFullExtent().getWidth(); |
353 |
}catch(DriverException e){
|
354 |
return 0D; |
355 |
} |
356 |
} |
357 |
|
358 |
|
359 |
/* (non-Javadoc)
|
360 |
* @deprecated. See String getInfo(Point p) throws DriverException
|
361 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(java.awt.Point)
|
362 |
*/
|
363 |
public String queryByPoint(Point p) throws DriverException { |
364 |
String data = "<file:"+normalizeAsXMLTag(getName())+">\n"; |
365 |
|
366 |
ArrayList attr = source.getAttributes();
|
367 |
data += " <raster\n";
|
368 |
data += " File=\""+((RasterFileAdapter) source).getFile()+"\"\n"; |
369 |
for (int i=0; i<attr.size(); i++) { |
370 |
Object [] a = (Object []) attr.get(i); |
371 |
|
372 |
data += " "+a[0].toString()+"="; |
373 |
if (a[1].toString() instanceof String) |
374 |
data += "\""+a[1].toString()+"\"\n"; |
375 |
else
|
376 |
data += a[1].toString()+"\n"; |
377 |
} |
378 |
data += " Point=\""+posX+" , "+posY+"\"\n"; |
379 |
data += " Point_WC=\""+posXWC+" , "+posYWC+"\"\n"; |
380 |
data += " RGB=\""+r+", "+g+", "+b+"\"\n"; |
381 |
data += " />\n";
|
382 |
|
383 |
data += "</file:"+normalizeAsXMLTag(getName())+">\n"; |
384 |
//System.out.println(data);
|
385 |
return data;
|
386 |
} |
387 |
|
388 |
public XMLItem[] getInfo(Point p, double tolerance) throws DriverException { |
389 |
|
390 |
Point2D pReal = getMapContext().getViewPort().toMapPoint(p);
|
391 |
Point2D px = null; |
392 |
if( pReal.getX() > this.getMinX() && |
393 |
pReal.getX() < this.getMaxX() &&
|
394 |
pReal.getY() > this.getMinY() &&
|
395 |
pReal.getY() < this.getMaxY()){
|
396 |
ArrayList attr = source.getAttributes();
|
397 |
int w = 0, h = 0; |
398 |
for (int i=0; i<attr.size(); i++) { |
399 |
Object [] a = (Object []) attr.get(i); |
400 |
if(a[0].toString().equals("Width")) |
401 |
w = ((Integer)a[1]).intValue(); |
402 |
if(a[0].toString().equals("Height")) |
403 |
h = ((Integer)a[1]).intValue(); |
404 |
} |
405 |
px = new Point2D.Double(); |
406 |
px.setLocation( ((pReal.getX() - this.getMinX()) * w) / getWidth(),
|
407 |
((this.getMaxY() - pReal.getY()) * h) / getHeight());
|
408 |
} |
409 |
|
410 |
int[] rgb = this.getPixel(pReal.getX(), pReal.getY()); |
411 |
|
412 |
StringXMLItem[] item = new StringXMLItem[1]; |
413 |
String data = "<file:"+normalizeAsXMLTag(getName())+">\n"; |
414 |
|
415 |
data += " <raster\n";
|
416 |
data += " View_Point=\""+p.getX()+" , "+p.getY()+"\"\n"; |
417 |
data += " World_Point=\""+pReal.getX()+" , "+pReal.getY()+"\"\n"; |
418 |
if(px == null) |
419 |
data += " Pixel_Point=\"Out\"\n";
|
420 |
else
|
421 |
data += " Pixel_Point=\""+(int)px.getX()+" , "+(int)px.getY()+"\"\n"; |
422 |
data += " RGB=\""+rgb[1]+" "+rgb[2]+" "+rgb[3]+"\"\n"; |
423 |
data += " Value_Band=\"";
|
424 |
if(this.getSource().getDataType() >= 0 && this.getSource().getDataType() <= 3){ |
425 |
for(int i = 0; i < this.getSource().getNumBands(); i++) |
426 |
data += ((Integer)((RasterDriver)this.getSource().getDriver()).getData((int)px.getX(), (int)px.getY(), i)).intValue()+" "; |
427 |
} |
428 |
if(this.getSource().getDataType() >= 4){ |
429 |
for(int i = 0; i < this.getSource().getNumBands(); i++) |
430 |
data += ((Float)((RasterDriver)this.getSource().getDriver()).getData((int)px.getX(), (int)px.getY(), i)).floatValue()+" "; |
431 |
} |
432 |
if(this.getSource().getDataType() >= 5){ |
433 |
for(int i = 0; i < this.getSource().getNumBands(); i++) |
434 |
data += ((Double)((RasterDriver)this.getSource().getDriver()).getData((int)px.getX(), (int)px.getY(), i)).doubleValue()+" "; |
435 |
} |
436 |
data += "\"\n";
|
437 |
data += " />\n";
|
438 |
data += "</file:"+normalizeAsXMLTag(getName())+">\n"; |
439 |
|
440 |
item[0] = new StringXMLItem(data, this); |
441 |
return item;
|
442 |
|
443 |
} |
444 |
|
445 |
/**
|
446 |
* Filters a string for being suitable as XML Tag, erasing
|
447 |
* all not alphabetic or numeric characters.
|
448 |
* @param s
|
449 |
* @return string normalized
|
450 |
*/
|
451 |
public String normalizeAsXMLTag(String s) { |
452 |
return s.replaceAll("[^a-zA-Z0-9]",""); |
453 |
} |
454 |
|
455 |
/**
|
456 |
* Obtiene atributos a partir de un georasterfile
|
457 |
* @return
|
458 |
*/
|
459 |
public ArrayList getAttributes() { |
460 |
return source.getAttributes();
|
461 |
} |
462 |
|
463 |
/**
|
464 |
* @throws XMLException
|
465 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
466 |
*/
|
467 |
public XMLEntity getXMLEntity() throws XMLException { |
468 |
XMLEntity xml = super.getXMLEntity();
|
469 |
|
470 |
if (source instanceof RasterFileAdapter) { |
471 |
xml.putProperty("file", ((RasterFileAdapter) source).getFile());
|
472 |
} |
473 |
|
474 |
xml.putProperty("driverName", getSource().getDriver().getName());
|
475 |
|
476 |
//Si no hay ning?n Status aplicamos el StatusLayerRaster que se usa por defecto
|
477 |
if(status == null) |
478 |
status = new StatusLayerRaster();
|
479 |
|
480 |
status.getXMLEntity(xml, true, this); |
481 |
|
482 |
|
483 |
return xml;
|
484 |
} |
485 |
|
486 |
public void setXMLEntity03(XMLEntity xml) |
487 |
throws XMLException {
|
488 |
super.setXMLEntity(xml);
|
489 |
try {
|
490 |
Driver d = LayerFactory.getDM().getDriver(
|
491 |
xml.getStringProperty("driverName"));
|
492 |
File f = new File(xml.getStringProperty("file")); |
493 |
RasterAdapter adapter = new RasterFileAdapter(f);
|
494 |
adapter.setDriver(d); |
495 |
setSource(adapter); |
496 |
// Para notificar al adapter-driver cual es la proyecci?n.
|
497 |
setProjection(super.getProjection());
|
498 |
} catch (DriverLoadException e) {
|
499 |
throw new XMLException(e); |
500 |
} |
501 |
} |
502 |
|
503 |
public void setXMLEntity(XMLEntity xml) |
504 |
throws XMLException {
|
505 |
super.setXMLEntity(xml);
|
506 |
try {
|
507 |
Driver d = LayerFactory.getDM().getDriver(
|
508 |
xml.getStringProperty("driverName"));
|
509 |
File f = new File(xml.getStringProperty("file")); |
510 |
RasterAdapter adapter = new RasterFileAdapter(f);
|
511 |
adapter.setDriver(d); |
512 |
setSource(adapter); |
513 |
// Para notificar al adapter-driver cual es la proyecci?n.
|
514 |
setProjection(super.getProjection());
|
515 |
|
516 |
//Inicializamos la clase a la que se usa por defecto para
|
517 |
//compatibilidad con proyectos antiguos
|
518 |
String claseStr = StatusLayerRaster.defaultClass;
|
519 |
if (xml.contains("raster.class")) { |
520 |
claseStr = xml.getStringProperty("raster.class");
|
521 |
} |
522 |
if(status!=null) |
523 |
status.setXMLEntity(xml, this);
|
524 |
else{
|
525 |
|
526 |
//Cuando cargamos un proyecto
|
527 |
|
528 |
if(claseStr!=null && !claseStr.equals("")){ |
529 |
try{
|
530 |
Class clase = Class.forName(claseStr); |
531 |
Constructor constr = clase.getConstructor(null); |
532 |
status = (StatusRasterInterface)constr.newInstance(null);
|
533 |
if(status!=null) |
534 |
status.setXMLEntity(xml, this);
|
535 |
}catch(ClassNotFoundException exc){ |
536 |
exc.printStackTrace(); |
537 |
}catch(InstantiationException exc){ |
538 |
exc.printStackTrace(); |
539 |
}catch(IllegalAccessException exc){ |
540 |
exc.printStackTrace(); |
541 |
}catch(NoSuchMethodException exc){ |
542 |
exc.printStackTrace(); |
543 |
}catch(InvocationTargetException exc){ |
544 |
exc.printStackTrace(); |
545 |
} |
546 |
} |
547 |
} |
548 |
firstLoad = true;
|
549 |
|
550 |
|
551 |
} catch (DriverLoadException e) {
|
552 |
throw new XMLException(e); |
553 |
} |
554 |
} |
555 |
|
556 |
/* (non-Javadoc)
|
557 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable)
|
558 |
*/
|
559 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale) |
560 |
throws DriverException {
|
561 |
|
562 |
if (isVisible() && isWithinScale(scale)){
|
563 |
isPrinting = true;
|
564 |
if (!mustTilePrint) {
|
565 |
draw(null, g, viewPort, cancel,scale);
|
566 |
} else {
|
567 |
// Para no pedir imagenes demasiado grandes, vamos
|
568 |
// a hacer lo mismo que hace EcwFile: chunkear.
|
569 |
// Llamamos a drawView con cuadraditos m?s peque?os
|
570 |
// del BufferedImage ni caso, cuando se imprime viene con null
|
571 |
Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipRect());
|
572 |
tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
573 |
|
574 |
//Si es la primera lectura salvamos los valores de m?ximo y m?nimo para la aplicaci?n
|
575 |
//de realce si la imagen es de 16 bits.
|
576 |
|
577 |
RasterStats stats = getSource().getFilterStack().getStats(); |
578 |
if(stats != null) |
579 |
stats.history.add(stats.new History(getName(), stats.minBandValue, stats.maxBandValue, stats.secondMinBandValue, stats.secondMaxBandValue)); |
580 |
|
581 |
|
582 |
for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) { |
583 |
// Parte que dibuja
|
584 |
try {
|
585 |
ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
586 |
draw(null, g, vp, cancel,scale);
|
587 |
} catch (NoninvertibleTransformException e) { |
588 |
// TODO Auto-generated catch block
|
589 |
e.printStackTrace(); |
590 |
} |
591 |
} |
592 |
|
593 |
if(stats != null){ |
594 |
getSource().getFilterStack().getStats().history.clear(); |
595 |
stats = getSource().getFilterStack().getStats(); |
596 |
} |
597 |
|
598 |
} |
599 |
isPrinting = false;
|
600 |
} |
601 |
} |
602 |
|
603 |
public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale) |
604 |
throws DriverException {
|
605 |
// Para no pedir imagenes demasiado grandes, vamos
|
606 |
// a hacer lo mismo que hace EcwFile: chunkear.
|
607 |
// Llamamos a drawView con cuadraditos m?s peque?os
|
608 |
// del BufferedImage ni caso, cuando se imprime viene con null
|
609 |
|
610 |
int numW, numH;
|
611 |
int stepX, stepY;
|
612 |
int xProv, yProv, wProv, hProv;
|
613 |
double xProvD, yProvD, wProvD, hProvD;
|
614 |
int A = 1500; |
615 |
int H = 1500; |
616 |
int altoAux, anchoAux;
|
617 |
|
618 |
AffineTransform mat = (AffineTransform) viewPort.getAffineTransform().clone(); |
619 |
|
620 |
// Vamos a hacerlo en trozos de AxH
|
621 |
Rectangle r = g.getClipRect();
|
622 |
numW = (int) (r.width) / A;
|
623 |
numH = (int) (r.height) / H;
|
624 |
|
625 |
|
626 |
double[] srcPts = new double[8]; |
627 |
double[] dstPts= new double[8]; |
628 |
|
629 |
yProv = (int) r.y;
|
630 |
for (stepY=0; stepY < numH+1; stepY++) |
631 |
{ |
632 |
if ((yProv + H) > r.getMaxY())
|
633 |
altoAux = (int) r.getMaxY() - yProv;
|
634 |
else
|
635 |
altoAux = H; |
636 |
|
637 |
xProv = (int) r.x;
|
638 |
for (stepX=0; stepX < numW+1; stepX++) |
639 |
{ |
640 |
if ((xProv + A) > r.getMaxX())
|
641 |
anchoAux = (int) r.getMaxX() - xProv;
|
642 |
else
|
643 |
anchoAux = A; |
644 |
|
645 |
Rectangle newRect = new Rectangle(xProv, yProv, anchoAux, altoAux); |
646 |
|
647 |
// Parte que dibuja
|
648 |
srcPts[0] = xProv;
|
649 |
srcPts[1] = yProv;
|
650 |
srcPts[2] = xProv + anchoAux+1; |
651 |
srcPts[3] = yProv;
|
652 |
srcPts[4] = xProv + anchoAux+1; |
653 |
srcPts[5] = yProv + altoAux+1; |
654 |
srcPts[6] = xProv;
|
655 |
srcPts[7] = yProv + altoAux+1; |
656 |
|
657 |
try {
|
658 |
mat.inverseTransform(srcPts, 0, dstPts, 0, 4); |
659 |
Rectangle2D.Double rectCuadricula = new Rectangle2D.Double( |
660 |
dstPts[0], dstPts[1], |
661 |
dstPts[2] - dstPts[0], dstPts[5]-dstPts[3]); |
662 |
Extent extent = new Extent(rectCuadricula);
|
663 |
|
664 |
Dimension tam = new Dimension(anchoAux+1, altoAux+1); |
665 |
ViewPort vp = viewPort.cloneViewPort(); |
666 |
vp.setImageSize(tam); |
667 |
vp.setExtent(rectCuadricula); |
668 |
vp.setAffineTransform(mat); |
669 |
// ViewPortData vp = new ViewPortData(getProjection(), extent, tam);
|
670 |
// vp.setMat(mat);
|
671 |
// rasterList.draw(g2, vp);
|
672 |
|
673 |
/*System.out.println("FLyrRaster.print(): fila "+stepX+" de "
|
674 |
+ numW + " , col "+stepY+" de " + numH +
|
675 |
"\n, Extent = "+vp.getExtent() + " imageSize: "
|
676 |
+ tam);*/
|
677 |
draw(null, g, vp, cancel,scale);
|
678 |
|
679 |
} catch (NoninvertibleTransformException e) { |
680 |
// TODO Auto-generated catch block
|
681 |
e.printStackTrace(); |
682 |
} |
683 |
// Fin parte que dibuja
|
684 |
xProv = xProv + A; |
685 |
} |
686 |
yProv = yProv + H; |
687 |
} |
688 |
|
689 |
} |
690 |
|
691 |
/**
|
692 |
* A?ade un fichero a la capa raster
|
693 |
* @param fileName Nombre del fichero
|
694 |
*/
|
695 |
public void addFiles(String fileName){ |
696 |
((RasterFileAdapter) source).addFile(fileName); |
697 |
} |
698 |
|
699 |
/**
|
700 |
* Elimina un fichero a la capa raster
|
701 |
* @param fileName Nombre del fichero
|
702 |
*/
|
703 |
public void delFile(String fileName){ |
704 |
((RasterFileAdapter) source).delFile(fileName); |
705 |
} |
706 |
|
707 |
/* (non-Javadoc)
|
708 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setBand(int, int)
|
709 |
*/
|
710 |
public void setBand(int flag, int nBand) { |
711 |
this.getSource().setBand(flag, nBand);
|
712 |
} |
713 |
|
714 |
/**
|
715 |
* Borra de la lista de listeners el que se pasa como par?metro.
|
716 |
*
|
717 |
* @param o LayerListener a borrar.
|
718 |
*
|
719 |
* @return True si ha sido correcto el borrado del Listener.
|
720 |
*/
|
721 |
public boolean removeLayerListener(LayerListener o) { |
722 |
if(this.isRemoveRasterFlag()){ |
723 |
/*try{
|
724 |
((RasterFileAdapter) source).stop();
|
725 |
}catch(DriverIOException exc){
|
726 |
|
727 |
}*/
|
728 |
this.setRemoveRasterFlag(true); |
729 |
} |
730 |
return super.layerListeners.remove(o); |
731 |
} |
732 |
|
733 |
/**
|
734 |
* @return Returns the removeRasterFlag.
|
735 |
*/
|
736 |
public boolean isRemoveRasterFlag() { |
737 |
return removeRasterFlag;
|
738 |
} |
739 |
|
740 |
/**
|
741 |
* Asigna el valor del flag que dice si destruimos la memoria del raster
|
742 |
* al eliminarlo del TOC o no.
|
743 |
* @param removeRasterFlag The removeRasterFlag to set.
|
744 |
*/
|
745 |
public void setRemoveRasterFlag(boolean removeRasterFlag) { |
746 |
this.removeRasterFlag = removeRasterFlag;
|
747 |
} |
748 |
|
749 |
public ImageIcon getTocImageIcon() { |
750 |
return new ImageIcon(MapControl.class.getResource("images/icolayerRaster.PNG")); |
751 |
} |
752 |
|
753 |
/*
|
754 |
* (non-Javadoc)
|
755 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize()
|
756 |
*/
|
757 |
public int[] getTileSize() { |
758 |
int[] size = {maxTileDrawWidth, maxTileDrawHeight}; |
759 |
return size;
|
760 |
} |
761 |
|
762 |
/*
|
763 |
* (non-Javadoc)
|
764 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#isTiled()
|
765 |
*/
|
766 |
public boolean isTiled() { |
767 |
return mustTileDraw;
|
768 |
} |
769 |
|
770 |
/**
|
771 |
* Obtiene el flag que dice si la imagen est? o no georreferenciada
|
772 |
* @return true si est? georreferenciada y false si no lo est?.
|
773 |
*/
|
774 |
public boolean isGeoreferenced() { |
775 |
return getSource().isGeoreferenced();
|
776 |
} |
777 |
} |