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