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