root / trunk / extensions / extRasterTools-SE / src / org / gvsig / fmap / layers / FLyrRasterSE.java @ 11173
History | View | Annotate | Download (28.1 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 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 |
package org.gvsig.fmap.layers; |
20 |
|
21 |
import java.awt.Dimension; |
22 |
import java.awt.Graphics2D; |
23 |
import java.awt.Point; |
24 |
import java.awt.Rectangle; |
25 |
import java.awt.geom.AffineTransform; |
26 |
import java.awt.geom.NoninvertibleTransformException; |
27 |
import java.awt.geom.Point2D; |
28 |
import java.awt.geom.Rectangle2D; |
29 |
import java.awt.image.BufferedImage; |
30 |
import java.io.File; |
31 |
import java.io.IOException; |
32 |
import java.lang.reflect.Constructor; |
33 |
import java.lang.reflect.InvocationTargetException; |
34 |
import java.util.ArrayList; |
35 |
|
36 |
import javax.print.attribute.PrintRequestAttributeSet; |
37 |
import javax.swing.ImageIcon; |
38 |
|
39 |
import org.cresques.cts.IProjection; |
40 |
import org.cresques.filter.RasterFilterStack; |
41 |
import org.gvsig.fmap.drivers.GenericRasterDriver; |
42 |
import org.gvsig.fmap.drivers.GeoRasterDriver; |
43 |
import org.gvsig.raster.buffer.BufferFactory; |
44 |
import org.gvsig.raster.dataset.RasterDriverException; |
45 |
import org.gvsig.raster.dataset.RasterMultiDataset; |
46 |
import org.gvsig.raster.dataset.properties.DatasetMetadata; |
47 |
import org.gvsig.raster.grid.GridTransparency; |
48 |
import org.gvsig.raster.grid.filter.RasterFilterList; |
49 |
import org.gvsig.raster.grid.render.Rendering; |
50 |
import org.gvsig.raster.shared.Extent; |
51 |
import org.gvsig.raster.shared.IRasterDataset; |
52 |
import org.gvsig.raster.shared.IRasterProperties; |
53 |
|
54 |
import com.hardcode.driverManager.Driver; |
55 |
import com.hardcode.driverManager.DriverLoadException; |
56 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
57 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
58 |
import com.iver.andami.messages.NotificationManager; |
59 |
import com.iver.cit.gvsig.fmap.MapControl; |
60 |
import com.iver.cit.gvsig.fmap.ViewPort; |
61 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
62 |
import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
63 |
import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
64 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
65 |
import com.iver.cit.gvsig.fmap.layers.LayerListener; |
66 |
import com.iver.cit.gvsig.fmap.layers.RasterOperations; |
67 |
import com.iver.cit.gvsig.fmap.layers.StatusLayerRaster; |
68 |
import com.iver.cit.gvsig.fmap.layers.StatusRasterInterface; |
69 |
import com.iver.cit.gvsig.fmap.layers.Tiling; |
70 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
71 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.StringXMLItem; |
72 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem; |
73 |
import com.iver.utiles.XMLEntity; |
74 |
import com.iver.utiles.swing.threads.Cancellable; |
75 |
|
76 |
|
77 |
/**
|
78 |
*
|
79 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
80 |
*
|
81 |
*/
|
82 |
//TODO: RasterOperations FMap es a extinguir.
|
83 |
public class FLyrRasterSE extends FLyrDefault implements RasterOperations, IRasterProperties, IRasterDataset{ |
84 |
private RasterSEAdapter 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 |
* Crea una capa Raster a partir del nombre driver, fichero y proyecci?n.
|
101 |
* @param layerName Nombre de la capa.
|
102 |
* @param d RasterDriver.
|
103 |
* @param f Fichero.
|
104 |
* @param proj Proyecci?n.
|
105 |
* @return Nueva capa de tipo raster.
|
106 |
* @throws DriverIOException
|
107 |
*/
|
108 |
public static FLyrRasterSE createLayer(String layerName, GenericRasterDriver d, |
109 |
File f, IProjection proj) {
|
110 |
RasterSEAdapter adapter = new RasterSEFileAdapter(f);
|
111 |
adapter.setDriver(d); |
112 |
|
113 |
FLyrRasterSE capa = new FLyrRasterSE();
|
114 |
capa.setName(layerName); |
115 |
capa.setSource(adapter); |
116 |
capa.setProjection(proj); |
117 |
|
118 |
capa.load(); |
119 |
|
120 |
return capa;
|
121 |
} |
122 |
|
123 |
/**
|
124 |
* Devuelve el RasterAdapter de la capa.
|
125 |
*
|
126 |
* @return RasterAdapter.
|
127 |
*/
|
128 |
public RasterSEAdapter getSource() {
|
129 |
return source;
|
130 |
} |
131 |
|
132 |
/**
|
133 |
*Redefine wakeUp de FLyrDefault
|
134 |
*/
|
135 |
public void wakeUp(){ |
136 |
} |
137 |
|
138 |
/**
|
139 |
* Inserta el RasterAdapter.
|
140 |
*
|
141 |
* @param ra RasterAdapter.
|
142 |
*/
|
143 |
public void setSource(RasterSEAdapter ra) { |
144 |
source = ra; |
145 |
} |
146 |
|
147 |
/**
|
148 |
* Devuelve la pila de filtros aplicada sobre la capa raster.
|
149 |
*
|
150 |
* @return RasterFilterStack.
|
151 |
*/
|
152 |
public RasterFilterStack getFilterStack(){
|
153 |
return null; |
154 |
} |
155 |
|
156 |
/**
|
157 |
* Asignar el estado del raster
|
158 |
* @param status
|
159 |
*/
|
160 |
public void setStatus(StatusRasterInterface status){ |
161 |
this.status = status;
|
162 |
} |
163 |
|
164 |
/**
|
165 |
* Asigna la pila de filtros aplicada al raster
|
166 |
* @return
|
167 |
*/
|
168 |
public void setFilterStack(RasterFilterStack stack){ |
169 |
//source.setFilterStack(stack);
|
170 |
} |
171 |
|
172 |
/**
|
173 |
* Obtiene el estado del raster
|
174 |
* @return
|
175 |
*/
|
176 |
public StatusRasterInterface getStatus(){
|
177 |
return this.status; |
178 |
} |
179 |
|
180 |
/**
|
181 |
* Asigna la posici?n en la que se ha hecho click al mostrar
|
182 |
* informaci?n del raster.
|
183 |
* @param x Posici?n en X
|
184 |
* @param y Posici?n en Y
|
185 |
*/
|
186 |
public void setPos(int x, int y){ |
187 |
this.posX = x;
|
188 |
this.posY = y;
|
189 |
} |
190 |
|
191 |
/**
|
192 |
* Asigna la posici?n en coordenadas del mundo real en la que se ha
|
193 |
* hecho click al mostrar informaci?n del raster.
|
194 |
* @param x Posici?n en X
|
195 |
* @param y Posici?n en Y
|
196 |
*/
|
197 |
public void setPosWC(double x, double y){ |
198 |
this.posXWC = x;
|
199 |
this.posYWC = y;
|
200 |
} |
201 |
|
202 |
/**
|
203 |
* Asigna RGB en la posici?n en la que se ha
|
204 |
* hecho click al mostrar informaci?n del raster.
|
205 |
* @param r valor de rojo
|
206 |
* @param g valor de verde
|
207 |
* @param b valor de azul
|
208 |
*/
|
209 |
public void setRGB(int r, int g, int b){ |
210 |
this.r = r;
|
211 |
this.g = g;
|
212 |
this.b = b;
|
213 |
} |
214 |
|
215 |
/*
|
216 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
|
217 |
*/
|
218 |
public void load() { |
219 |
try {
|
220 |
((RasterSEFileAdapter) source).start(); |
221 |
} catch (DriverIOException e) {
|
222 |
NotificationManager.addError("Error en la carga de capa", e);
|
223 |
} |
224 |
((RasterSEFileAdapter) source).setTransparency(getTransparency()); |
225 |
} |
226 |
|
227 |
/**
|
228 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
229 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
|
230 |
* com.iver.utiles.swing.threads.Cancellable)
|
231 |
*/
|
232 |
public void draw(BufferedImage image, Graphics2D g, ViewPort vp, |
233 |
Cancellable cancel,double scale){
|
234 |
if (isWithinScale(scale)){
|
235 |
try {
|
236 |
if(status!=null && firstLoad){ |
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 |
//g.setClip(tiles.getClip(tileNr).x, tiles.getClip(tileNr).y, tiles.getClip(tileNr).width - 5, tiles.getClip(tileNr).height);
|
247 |
((RasterSEFileAdapter) source).draw(image, g, vport, cancel); |
248 |
} catch (NoninvertibleTransformException e) { |
249 |
e.printStackTrace(); |
250 |
} |
251 |
} |
252 |
}else
|
253 |
((RasterSEFileAdapter) source).draw(image, g, vp, cancel); |
254 |
status.applyStatus(this);
|
255 |
firstLoad = false;
|
256 |
} |
257 |
|
258 |
if(mustTileDraw){
|
259 |
Point2D p = vp.getOffset();
|
260 |
Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), vp.getImageWidth(), vp.getImageHeight()); |
261 |
Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
|
262 |
tiles.setAffineTransform((AffineTransform) vp.getAffineTransform().clone());
|
263 |
for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) { |
264 |
// drawing part
|
265 |
try {
|
266 |
ViewPort vport = tiles.getTileViewPort(vp, tileNr); |
267 |
((RasterSEFileAdapter) source).draw(image, g, vport, cancel); |
268 |
} catch (NoninvertibleTransformException e) { |
269 |
e.printStackTrace(); |
270 |
} |
271 |
} |
272 |
}else
|
273 |
((RasterSEFileAdapter) source).draw(image, g, vp, cancel); |
274 |
|
275 |
} catch (DriverIOException e) {
|
276 |
NotificationManager.addError("Error dibujando", e);
|
277 |
} |
278 |
|
279 |
if (getVirtualLayers() != null) { |
280 |
try {
|
281 |
getVirtualLayers().draw(image, g, vp, cancel,scale); |
282 |
} catch (ReadDriverException e) {
|
283 |
NotificationManager.addError("Error dibujando", e);
|
284 |
} |
285 |
} |
286 |
} |
287 |
} |
288 |
|
289 |
/**
|
290 |
* Inserta la proyecci?n.
|
291 |
*
|
292 |
* @param proj Proyecci?n.
|
293 |
*/
|
294 |
public void setProjection(IProjection proj) { |
295 |
super.setProjection(proj);
|
296 |
|
297 |
if (source != null && source.getDriver() != null && source.getDriver() instanceof GeoRasterDriver) { |
298 |
GeoRasterDriver geoDrv = (GeoRasterDriver) source.getDriver(); |
299 |
|
300 |
if (geoDrv.getProjection() == null) { |
301 |
geoDrv.setProjection(proj); |
302 |
} |
303 |
} |
304 |
} |
305 |
|
306 |
public void setTransparency(int trans) { |
307 |
super.setTransparency(trans);
|
308 |
((RasterSEFileAdapter) source).setTransparency(trans); |
309 |
if (getMapContext() != null){ |
310 |
getMapContext().invalidate(); |
311 |
} |
312 |
} |
313 |
|
314 |
public int getTransparency() { |
315 |
return ((RasterSEFileAdapter) source).getTransparency();
|
316 |
} |
317 |
|
318 |
/*
|
319 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
320 |
*/
|
321 |
public Rectangle2D getFullExtent(){ |
322 |
return ((RasterSEFileAdapter) source).getFullExtent();
|
323 |
} |
324 |
|
325 |
/**
|
326 |
* Obtiene el valor del pixel del Image en la posici?n x,y
|
327 |
* @param x Posici?n x
|
328 |
* @param y Posici?n y
|
329 |
* @return valor de pixel
|
330 |
*/
|
331 |
public int[] getPixel(double wcx, double wcy){ |
332 |
return ((RasterSEFileAdapter) source).getPixel(wcx, wcy);
|
333 |
} |
334 |
|
335 |
public double getMaxX(){ |
336 |
return this.getFullExtent().getMaxX(); |
337 |
} |
338 |
|
339 |
public double getMaxY(){ |
340 |
return this.getFullExtent().getMaxY(); |
341 |
} |
342 |
|
343 |
public double getMinX(){ |
344 |
return this.getFullExtent().getMinX(); |
345 |
} |
346 |
|
347 |
public double getMinY(){ |
348 |
return this.getFullExtent().getMinY(); |
349 |
} |
350 |
|
351 |
public double getHeight(){ |
352 |
return this.getFullExtent().getHeight(); |
353 |
} |
354 |
|
355 |
public double getWidth(){ |
356 |
return this.getFullExtent().getWidth(); |
357 |
} |
358 |
|
359 |
|
360 |
/* (non-Javadoc)
|
361 |
* @deprecated. See String getInfo(Point p) throws DriverException
|
362 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(java.awt.Point)
|
363 |
*/
|
364 |
public String queryByPoint(Point p) throws DriverException { |
365 |
String data = "<file:"+normalizeAsXMLTag(getName())+">\n"; |
366 |
|
367 |
ArrayList attr = source.getAttributes();
|
368 |
data += " <raster\n";
|
369 |
data += " File=\""+((RasterSEFileAdapter) source).getFile()+"\"\n"; |
370 |
for (int i=0; i<attr.size(); i++) { |
371 |
Object [] a = (Object []) attr.get(i); |
372 |
|
373 |
data += " "+a[0].toString()+"="; |
374 |
if (a[1].toString() instanceof String) |
375 |
data += "\""+a[1].toString()+"\"\n"; |
376 |
else
|
377 |
data += a[1].toString()+"\n"; |
378 |
} |
379 |
data += " Point=\""+posX+" , "+posY+"\"\n"; |
380 |
data += " Point_WC=\""+posXWC+" , "+posYWC+"\"\n"; |
381 |
data += " RGB=\""+r+", "+g+", "+b+"\"\n"; |
382 |
data += " />\n";
|
383 |
|
384 |
data += "</file:"+normalizeAsXMLTag(getName())+">\n"; |
385 |
//System.out.println(data);
|
386 |
return data;
|
387 |
} |
388 |
|
389 |
public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) { |
390 |
|
391 |
Point2D pReal = getMapContext().getViewPort().toMapPoint(p);
|
392 |
Point2D px = null; |
393 |
if( pReal.getX() > this.getMinX() && |
394 |
pReal.getX() < this.getMaxX() &&
|
395 |
pReal.getY() > this.getMinY() &&
|
396 |
pReal.getY() < this.getMaxY()){
|
397 |
ArrayList attr = source.getAttributes();
|
398 |
int w = 0, h = 0; |
399 |
for (int i=0; i<attr.size(); i++) { |
400 |
Object [] a = (Object []) attr.get(i); |
401 |
if(a[0].toString().equals("Width")) |
402 |
w = ((Integer)a[1]).intValue(); |
403 |
if(a[0].toString().equals("Height")) |
404 |
h = ((Integer)a[1]).intValue(); |
405 |
} |
406 |
px = new Point2D.Double(); |
407 |
px.setLocation( ((pReal.getX() - this.getMinX()) * w) / getWidth(),
|
408 |
((this.getMaxY() - pReal.getY()) * h) / getHeight());
|
409 |
} |
410 |
|
411 |
int[] rgb = this.getPixel(pReal.getX(), pReal.getY()); |
412 |
|
413 |
StringXMLItem[] item = new StringXMLItem[1]; |
414 |
String data = "<file:"+normalizeAsXMLTag(getName())+">\n"; |
415 |
|
416 |
data += " <raster\n";
|
417 |
data += " View_Point=\""+p.getX()+" , "+p.getY()+"\"\n"; |
418 |
data += " World_Point=\""+pReal.getX()+" , "+pReal.getY()+"\"\n"; |
419 |
if(px == null) |
420 |
data += " Pixel_Point=\"Out\"\n";
|
421 |
else
|
422 |
data += " Pixel_Point=\""+(int)px.getX()+" , "+(int)px.getY()+"\"\n"; |
423 |
data += " RGB=\""+rgb[1]+" "+rgb[2]+" "+rgb[3]+"\"\n"; |
424 |
data += " Band_Value=\"";
|
425 |
if(this.getSource().getDataType() >= 0 && this.getSource().getDataType() <= 3){ |
426 |
for(int i = 0; i < this.getSource().getNumBands(); i++) |
427 |
data += ((Integer)((RasterDriver)this.getSource().getDriver()).getData((int)px.getX(), (int)px.getY(), i)).intValue()+" "; |
428 |
} |
429 |
if(this.getSource().getDataType() >= 4){ |
430 |
for(int i = 0; i < this.getSource().getNumBands(); i++) |
431 |
data += ((Float)((RasterDriver)this.getSource().getDriver()).getData((int)px.getX(), (int)px.getY(), i)).floatValue()+" "; |
432 |
} |
433 |
if(this.getSource().getDataType() >= 5){ |
434 |
for(int i = 0; i < this.getSource().getNumBands(); i++) |
435 |
data += ((Double)((RasterDriver)this.getSource().getDriver()).getData((int)px.getX(), (int)px.getY(), i)).doubleValue()+" "; |
436 |
} |
437 |
data += "\"\n";
|
438 |
data += " />\n";
|
439 |
data += "</file:"+normalizeAsXMLTag(getName())+">\n"; |
440 |
|
441 |
item[0] = new StringXMLItem(data, this); |
442 |
return item;
|
443 |
|
444 |
} |
445 |
|
446 |
/**
|
447 |
* Filters a string for being suitable as XML Tag, erasing
|
448 |
* all not alphabetic or numeric characters.
|
449 |
* @param s
|
450 |
* @return string normalized
|
451 |
*/
|
452 |
public String normalizeAsXMLTag(String s) { |
453 |
return s.replaceAll("[^a-zA-Z0-9]",""); |
454 |
} |
455 |
|
456 |
/**
|
457 |
* Obtiene atributos a partir de un georasterfile
|
458 |
* @return
|
459 |
*/
|
460 |
public ArrayList getAttributes() { |
461 |
return source.getAttributes();
|
462 |
} |
463 |
|
464 |
/**
|
465 |
* @throws XMLException
|
466 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
467 |
*/
|
468 |
public XMLEntity getXMLEntity() throws XMLException { |
469 |
XMLEntity xml = super.getXMLEntity();
|
470 |
|
471 |
if (source instanceof RasterSEFileAdapter) { |
472 |
xml.putProperty("file", ((RasterSEFileAdapter) source).getFile());
|
473 |
} |
474 |
|
475 |
xml.putProperty("driverName", getSource().getDriver().getName());
|
476 |
|
477 |
//Si no hay ning?n Status aplicamos el StatusLayerRaster que se usa por defecto
|
478 |
if(status == null) |
479 |
status = new StatusLayerRaster();
|
480 |
|
481 |
status.getXMLEntity(xml, true, this); |
482 |
|
483 |
|
484 |
return xml;
|
485 |
} |
486 |
|
487 |
public void setXMLEntity03(XMLEntity xml) |
488 |
throws XMLException {
|
489 |
super.setXMLEntity(xml);
|
490 |
try {
|
491 |
Driver d = LayerFactory.getDM().getDriver(
|
492 |
xml.getStringProperty("driverName"));
|
493 |
File f = new File(xml.getStringProperty("file")); |
494 |
RasterSEAdapter adapter = new RasterSEFileAdapter(f);
|
495 |
adapter.setDriver(d); |
496 |
setSource(adapter); |
497 |
// Para notificar al adapter-driver cual es la proyecci?n.
|
498 |
setProjection(super.getProjection());
|
499 |
} catch (DriverLoadException e) {
|
500 |
throw new XMLException(e); |
501 |
} |
502 |
} |
503 |
|
504 |
public void setXMLEntity(XMLEntity xml) |
505 |
throws XMLException {
|
506 |
super.setXMLEntity(xml);
|
507 |
try {
|
508 |
Driver d = LayerFactory.getDM().getDriver(
|
509 |
xml.getStringProperty("driverName"));
|
510 |
File f = new File(xml.getStringProperty("file")); |
511 |
RasterSEAdapter adapter = new RasterSEFileAdapter(f);
|
512 |
adapter.setDriver(d); |
513 |
setSource(adapter); |
514 |
// Para notificar al adapter-driver cual es la proyecci?n.
|
515 |
setProjection(super.getProjection());
|
516 |
|
517 |
//Inicializamos la clase a la que se usa por defecto para
|
518 |
//compatibilidad con proyectos antiguos
|
519 |
String claseStr = StatusLayerRaster.defaultClass;
|
520 |
if (xml.contains("raster.class")) { |
521 |
claseStr = xml.getStringProperty("raster.class");
|
522 |
} |
523 |
if(status!=null) |
524 |
status.setXMLEntity(xml, this);
|
525 |
else{
|
526 |
|
527 |
//Cuando cargamos un proyecto
|
528 |
|
529 |
if(claseStr!=null && !claseStr.equals("")){ |
530 |
try{
|
531 |
Class clase = Class.forName(claseStr); |
532 |
Constructor constr = clase.getConstructor(null); |
533 |
status = (StatusRasterInterface)constr.newInstance(null);
|
534 |
if(status!=null) |
535 |
status.setXMLEntity(xml, this);
|
536 |
}catch(ClassNotFoundException exc){ |
537 |
exc.printStackTrace(); |
538 |
}catch(InstantiationException exc){ |
539 |
exc.printStackTrace(); |
540 |
}catch(IllegalAccessException exc){ |
541 |
exc.printStackTrace(); |
542 |
}catch(NoSuchMethodException exc){ |
543 |
exc.printStackTrace(); |
544 |
}catch(InvocationTargetException exc){ |
545 |
exc.printStackTrace(); |
546 |
} |
547 |
} |
548 |
} |
549 |
firstLoad = true;
|
550 |
|
551 |
|
552 |
} catch (DriverLoadException e) {
|
553 |
throw new XMLException(e); |
554 |
} |
555 |
} |
556 |
|
557 |
/* (non-Javadoc)
|
558 |
* @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)
|
559 |
*/
|
560 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet propeties){ |
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.getClipBounds());
|
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.getClipBounds();
|
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 |
draw(null, g, vp, cancel,scale);
|
670 |
|
671 |
} catch (NoninvertibleTransformException e) { |
672 |
e.printStackTrace(); |
673 |
} |
674 |
// Fin parte que dibuja
|
675 |
xProv = xProv + A; |
676 |
} |
677 |
yProv = yProv + H; |
678 |
} |
679 |
|
680 |
} |
681 |
|
682 |
/* (non-Javadoc)
|
683 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setBand(int, int)
|
684 |
*/
|
685 |
public void setBand(int flag, int nBand) { |
686 |
this.getSource().setBand(flag, nBand);
|
687 |
} |
688 |
|
689 |
/**
|
690 |
* Borra de la lista de listeners el que se pasa como par?metro.
|
691 |
*
|
692 |
* @param o LayerListener a borrar.
|
693 |
*
|
694 |
* @return True si ha sido correcto el borrado del Listener.
|
695 |
*/
|
696 |
public boolean removeLayerListener(LayerListener o) { |
697 |
if(this.isRemoveRasterFlag()){ |
698 |
this.setRemoveRasterFlag(true); |
699 |
} |
700 |
return super.layerListeners.remove(o); |
701 |
} |
702 |
|
703 |
/**
|
704 |
* @return Returns the removeRasterFlag.
|
705 |
*/
|
706 |
public boolean isRemoveRasterFlag() { |
707 |
return removeRasterFlag;
|
708 |
} |
709 |
|
710 |
/**
|
711 |
* Asigna el valor del flag que dice si destruimos la memoria del raster
|
712 |
* al eliminarlo del TOC o no.
|
713 |
* @param removeRasterFlag The removeRasterFlag to set.
|
714 |
*/
|
715 |
public void setRemoveRasterFlag(boolean removeRasterFlag) { |
716 |
this.removeRasterFlag = removeRasterFlag;
|
717 |
} |
718 |
|
719 |
public ImageIcon getTocImageIcon() { |
720 |
return new ImageIcon(MapControl.class.getResource("images/icolayerRaster.PNG")); |
721 |
} |
722 |
|
723 |
/*
|
724 |
* (non-Javadoc)
|
725 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize()
|
726 |
*/
|
727 |
public int[] getTileSize() { |
728 |
int[] size = {maxTileDrawWidth, maxTileDrawHeight}; |
729 |
return size;
|
730 |
} |
731 |
|
732 |
/*
|
733 |
* (non-Javadoc)
|
734 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#isTiled()
|
735 |
*/
|
736 |
public boolean isTiled() { |
737 |
return mustTileDraw;
|
738 |
} |
739 |
|
740 |
/**
|
741 |
* Obtiene el flag que dice si la imagen est? o no georreferenciada
|
742 |
* @return true si est? georreferenciada y false si no lo est?.
|
743 |
*/
|
744 |
public boolean isGeoreferenced() { |
745 |
return getSource().isGeoreferenced();
|
746 |
} |
747 |
|
748 |
/**
|
749 |
* Get datasource object
|
750 |
* @return
|
751 |
*/
|
752 |
public BufferFactory getDatasource(){
|
753 |
return getSource().getDatasource();
|
754 |
} |
755 |
|
756 |
/**
|
757 |
* Get render object
|
758 |
* @return Rendering
|
759 |
*/
|
760 |
public Rendering getRender(){
|
761 |
return this.getSource().getRender(); |
762 |
} |
763 |
|
764 |
/*
|
765 |
* (non-Javadoc)
|
766 |
* @see org.gvsig.fmap.raster.IRasterOperations#getPXHeight()
|
767 |
*/
|
768 |
public double getPxHeight() { |
769 |
return getSource().getDatasource().getHeight();
|
770 |
} |
771 |
|
772 |
/*
|
773 |
* (non-Javadoc)
|
774 |
* @see org.gvsig.fmap.raster.IRasterOperations#getPxWidth()
|
775 |
*/
|
776 |
public double getPxWidth() { |
777 |
return getSource().getDatasource().getWidth();
|
778 |
} |
779 |
|
780 |
/*
|
781 |
* (non-Javadoc)
|
782 |
* @see org.gvsig.fmap.raster.IGeoDimension#getWCHeight()
|
783 |
*/
|
784 |
public double getWCHeight() { |
785 |
return this.getHeight(); |
786 |
} |
787 |
|
788 |
/*
|
789 |
* (non-Javadoc)
|
790 |
* @see org.gvsig.fmap.raster.IGeoDimension#getWCWidth()
|
791 |
*/
|
792 |
public double getWCWidth() { |
793 |
return this.getWidth(); |
794 |
} |
795 |
|
796 |
/*
|
797 |
* (non-Javadoc)
|
798 |
* @see org.gvsig.fmap.raster.IRasterFile#getFileSize()
|
799 |
*/
|
800 |
public long[] getFileSize(){ |
801 |
int nFiles = getDatasource().getGeoRasterMultiFile().getDatasetCount();
|
802 |
long[] s = new long[nFiles]; |
803 |
for(int i = 0; i < nFiles; i++) |
804 |
s[i] = getDatasource().getGeoRasterMultiFile().getDataset(i).getFileSize(); |
805 |
return s;
|
806 |
} |
807 |
|
808 |
/*
|
809 |
* (non-Javadoc)
|
810 |
* @see org.gvsig.fmap.raster.IRasterFile#getFileName()
|
811 |
*/
|
812 |
public String[] getFileName(){ |
813 |
int nFiles = getDatasource().getGeoRasterMultiFile().getDatasetCount();
|
814 |
String[] s = new String[nFiles]; |
815 |
for(int i = 0; i < nFiles; i++) |
816 |
s[i] = getDatasource().getGeoRasterMultiFile().getDataset(i).getFName(); |
817 |
return s;
|
818 |
} |
819 |
|
820 |
/*
|
821 |
* (non-Javadoc)
|
822 |
* @see org.gvsig.fmap.raster.IRasterFile#getFileCount()
|
823 |
*/
|
824 |
public int getFileCount(){ |
825 |
return getDatasource().getGeoRasterMultiFile().getDatasetCount();
|
826 |
} |
827 |
|
828 |
/*
|
829 |
* (non-Javadoc)
|
830 |
* @see org.gvsig.fmap.raster.IRasterFile#getFileFormat()
|
831 |
*/
|
832 |
public String getFileFormat(){ |
833 |
String fName = getDatasource().getGeoRasterMultiFile().getDataset(0).getFName(); |
834 |
int index = fName.lastIndexOf(".") + 1; |
835 |
String ext = null; |
836 |
if(index > 0) |
837 |
ext = fName.substring(fName.lastIndexOf(".") + 1, fName.length()); |
838 |
return ext;
|
839 |
} |
840 |
|
841 |
/*
|
842 |
* (non-Javadoc)
|
843 |
* @see org.gvsig.fmap.raster.IRasterOperations#getBandCount()
|
844 |
*/
|
845 |
public int getBandCount(){ |
846 |
return getDatasource().getGeoRasterMultiFile().getBandCount();
|
847 |
} |
848 |
|
849 |
/*
|
850 |
* (non-Javadoc)
|
851 |
* @see org.gvsig.fmap.raster.IRasterOperations#getDatatype()
|
852 |
*/
|
853 |
public int[] getDataType(){ |
854 |
return getDatasource().getGeoRasterMultiFile().getDataType();
|
855 |
} |
856 |
|
857 |
/*
|
858 |
* (non-Javadoc)
|
859 |
* @see org.gvsig.fmap.raster.IRasterRendering#getRenderTransparency()
|
860 |
*/
|
861 |
public GridTransparency getRenderTransparency(){
|
862 |
return getRender().getLastTransparency();
|
863 |
} |
864 |
|
865 |
/*
|
866 |
* (non-Javadoc)
|
867 |
* @see org.gvsig.fmap.raster.IRasterDataset#getGeoRasterMultiDataset()
|
868 |
*/
|
869 |
public RasterMultiDataset getGeoRasterMultiDataset() {
|
870 |
return getDatasource().getGeoRasterMultiFile();
|
871 |
} |
872 |
|
873 |
public Extent getFullRasterExtent(){
|
874 |
return new Extent(((RasterSEFileAdapter) source).getFullExtent()); |
875 |
} |
876 |
|
877 |
/*
|
878 |
* (non-Javadoc)
|
879 |
* @see org.gvsig.fmap.raster.IRasterDataset#addFile(java.lang.String)
|
880 |
*/
|
881 |
public void addFile(String fileName){ |
882 |
try {
|
883 |
((RasterSEFileAdapter) source).addFile(fileName); |
884 |
} catch (IOException e) { |
885 |
NotificationManager.addError(e.getMessage(), e); |
886 |
} |
887 |
} |
888 |
|
889 |
/*
|
890 |
* (non-Javadoc)
|
891 |
* @see org.gvsig.fmap.raster.IRasterDataset#delFile(java.lang.String)
|
892 |
*/
|
893 |
public void delFile(String fileName){ |
894 |
((RasterSEFileAdapter) source).delFile(fileName); |
895 |
} |
896 |
|
897 |
/*
|
898 |
* (non-Javadoc)
|
899 |
* @see org.gvsig.fmap.raster.IRasterDataset#getInfo(java.lang.String)
|
900 |
*/
|
901 |
public Object getInfo(String key) { |
902 |
if(key.equals("DriverName")) |
903 |
return getSource().getDriver().getName();
|
904 |
return null; |
905 |
} |
906 |
|
907 |
/*
|
908 |
* (non-Javadoc)
|
909 |
* @see org.gvsig.fmap.raster.IRasterRendering#getRenderFilterList()
|
910 |
*/
|
911 |
public RasterFilterList getRenderFilterList(){
|
912 |
return getRender().getFilterList();
|
913 |
} |
914 |
|
915 |
/*
|
916 |
* (non-Javadoc)
|
917 |
* @see org.gvsig.raster.shared.IRasterGeoOperations#getPixelSizeX()
|
918 |
*/
|
919 |
public double[] getPxWidthByDataset() { |
920 |
return getSource().getDatasource().getGeoRasterMultiFile().getWidth();
|
921 |
} |
922 |
|
923 |
/*
|
924 |
* (non-Javadoc)
|
925 |
* @see org.gvsig.raster.shared.IRasterGeoOperations#getPixelSizeY()
|
926 |
*/
|
927 |
public double[] getPxHeightByDataset() { |
928 |
return getSource().getDatasource().getGeoRasterMultiFile().getHeight();
|
929 |
} |
930 |
|
931 |
/*
|
932 |
* (non-Javadoc)
|
933 |
* @see org.gvsig.raster.shared.IRasterOperations#getMetadata()
|
934 |
*/
|
935 |
public DatasetMetadata[] getMetadata() { |
936 |
int count = source.getDatasource().getGeoRasterMultiFile().getDatasetCount();
|
937 |
DatasetMetadata[] metadata = new DatasetMetadata[count]; |
938 |
for (int i=0; i<count; i++) { |
939 |
metadata[i] = source.getDatasource().getGeoRasterMultiFile().getDataset(i).getMetadata(); |
940 |
} |
941 |
return metadata;
|
942 |
} |
943 |
|
944 |
/*
|
945 |
* (non-Javadoc)
|
946 |
* @see org.gvsig.raster.shared.IRasterOperations#getBandCountFromDataset()
|
947 |
*/
|
948 |
public int[] getBandCountFromDataset() { |
949 |
int count = source.getDatasource().getGeoRasterMultiFile().getDatasetCount();
|
950 |
int[] bands = new int[count]; |
951 |
for (int i=0; i<count; i++) { |
952 |
bands[i] = source.getDatasource().getGeoRasterMultiFile().getDataset(i).getBandCount(); |
953 |
} |
954 |
return bands;
|
955 |
} |
956 |
|
957 |
/*
|
958 |
* (non-Javadoc)
|
959 |
* @see org.gvsig.raster.shared.IRasterOperations#getColourInterpretation(int, int)
|
960 |
*/
|
961 |
public String getColourInterpretation(int band, int dataset) { |
962 |
if (source.getDatasource().getGeoRasterMultiFile().getColorInterpretation(dataset) == null) return "Undefined"; |
963 |
return source.getDatasource().getGeoRasterMultiFile().getColorInterpretation(dataset).get(band);
|
964 |
} |
965 |
|
966 |
public String getStringProjection() { |
967 |
try {
|
968 |
return source.getDatasource().getGeoRasterMultiFile().getStringProjection();
|
969 |
} catch (RasterDriverException e) {
|
970 |
// TODO Auto-generated catch block
|
971 |
e.printStackTrace(); |
972 |
} |
973 |
return null; |
974 |
} |
975 |
|
976 |
/**
|
977 |
* Asigna los par?metros para la carga de la capa
|
978 |
* @param param Par?metros.
|
979 |
*/
|
980 |
public void setLoadParams(Object param){ |
981 |
source.setLoadParams(param); |
982 |
} |
983 |
} |