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