svn-gvsig-desktop / tags / v1_0_2_Build_914 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrRaster.java @ 12200
History | View | Annotate | Download (23.8 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 | 9013 | caballero | import javax.print.attribute.PrintRequestAttributeSet; |
58 | 5761 | jmvivo | import javax.swing.ImageIcon; |
59 | |||
60 | 1680 | luisw | import org.cresques.cts.IProjection; |
61 | 5979 | nacho | import org.cresques.filter.RasterFilterStack; |
62 | 9056 | nacho | import org.cresques.io.data.Grid; |
63 | 10195 | nacho | import org.cresques.io.data.RasterBuf; |
64 | 9056 | nacho | import org.cresques.io.datastruct.Statistic; |
65 | 1680 | luisw | import org.cresques.px.Extent; |
66 | 9056 | nacho | |
67 | 1680 | luisw | import com.hardcode.driverManager.Driver; |
68 | import com.hardcode.driverManager.DriverLoadException; |
||
69 | import com.iver.cit.gvsig.fmap.DriverException; |
||
70 | 5761 | jmvivo | import com.iver.cit.gvsig.fmap.MapControl; |
71 | 1680 | luisw | 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 | 8765 | jjdelcerro | import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
75 | 5057 | ldiaz | import com.iver.cit.gvsig.fmap.layers.layerOperations.StringXMLItem; |
76 | 5200 | ldiaz | import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem; |
77 | 9056 | nacho | import com.iver.utiles.DoubleUtilities; |
78 | 1680 | luisw | import com.iver.utiles.XMLEntity; |
79 | 5317 | fjp | import com.iver.utiles.swing.threads.Cancellable; |
80 | 1680 | luisw | |
81 | |||
82 | 526 | vcaballero | /**
|
83 | 1034 | vcaballero | * Clase b?sica de capa raster.
|
84 | 526 | vcaballero | *
|
85 | * @author Vicente Caballero Navarro
|
||
86 | */
|
||
87 | 567 | luisw | public class FLyrRaster extends FLyrDefault implements RasterOperations { |
88 | 2183 | fernando | private RasterAdapter source;
|
89 | boolean isPrinting = false; |
||
90 | boolean mustTileDraw = false; |
||
91 | boolean mustTilePrint = true; |
||
92 | 5979 | nacho | private int maxTileDrawWidth = 200; |
93 | private int maxTileDrawHeight = 200; |
||
94 | 2183 | fernando | 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 | 2322 | igbrotru | private int r = 0, g = 0, b = 0; |
101 | 3410 | nacho | private boolean removeRasterFlag = true; |
102 | 9056 | nacho | |
103 | 1034 | vcaballero | /**
|
104 | * Devuelve el RasterAdapter de la capa.
|
||
105 | *
|
||
106 | * @return RasterAdapter.
|
||
107 | */
|
||
108 | public RasterAdapter getSource() {
|
||
109 | return source;
|
||
110 | } |
||
111 | 567 | luisw | |
112 | 1034 | vcaballero | /**
|
113 | 4376 | nacho | *Redefine wakeUp de FLyrDefault
|
114 | */
|
||
115 | public void wakeUp(){ |
||
116 | 4404 | nacho | /*setName(getName());
|
117 | 4376 | nacho | setProjection(getProjection());
|
118 | try {
|
||
119 | load();
|
||
120 | } catch (DriverIOException e) {
|
||
121 | e.printStackTrace();
|
||
122 | 9056 | nacho | }*/
|
123 | 4376 | nacho | } |
124 | 9056 | nacho | |
125 | 4376 | nacho | /**
|
126 | 1034 | vcaballero | * Inserta el RasterAdapter.
|
127 | *
|
||
128 | * @param ra RasterAdapter.
|
||
129 | */
|
||
130 | public void setSource(RasterAdapter ra) { |
||
131 | source = ra; |
||
132 | } |
||
133 | 567 | luisw | |
134 | 2183 | fernando | /**
|
135 | 2623 | nacho | * 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 | 9056 | nacho | |
143 | 2623 | nacho | /**
|
144 | 2183 | fernando | * Asignar el estado del raster
|
145 | * @param status
|
||
146 | */
|
||
147 | public void setStatus(StatusRasterInterface status){ |
||
148 | this.status = status;
|
||
149 | } |
||
150 | 9056 | nacho | |
151 | 2183 | fernando | /**
|
152 | 2623 | nacho | * Asigna la pila de filtros aplicada al raster
|
153 | * @return
|
||
154 | */
|
||
155 | public void setFilterStack(RasterFilterStack stack){ |
||
156 | 9056 | nacho | source.setFilterStack(stack); |
157 | 2623 | nacho | } |
158 | 9056 | nacho | |
159 | 2623 | nacho | /**
|
160 | 2183 | fernando | * Obtiene el estado del raster
|
161 | * @return
|
||
162 | */
|
||
163 | public StatusRasterInterface getStatus(){
|
||
164 | return this.status; |
||
165 | } |
||
166 | 9056 | nacho | |
167 | 2183 | fernando | /**
|
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 | 9056 | nacho | |
178 | 2183 | fernando | /**
|
179 | 9056 | nacho | * Asigna la posici?n en coordenadas del mundo real en la que se ha
|
180 | 2183 | fernando | * 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 | 9056 | nacho | |
189 | 2322 | igbrotru | /**
|
190 | 9056 | nacho | * Asigna RGB en la posici?n en la que se ha
|
191 | 2322 | igbrotru | * 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 | 9056 | nacho | |
202 | 567 | luisw | /*
|
203 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
|
||
204 | */
|
||
205 | 1034 | vcaballero | public void load() throws DriverIOException { |
206 | ((RasterFileAdapter) source).start(); |
||
207 | 1455 | luisw | ((RasterFileAdapter) source).setTransparency(getTransparency()); |
208 | 567 | luisw | } |
209 | 1034 | vcaballero | |
210 | 526 | vcaballero | /**
|
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 | 5317 | fjp | * com.iver.utiles.swing.threads.Cancellable)
|
214 | 526 | vcaballero | */
|
215 | 659 | luisw | public void draw(BufferedImage image, Graphics2D g, ViewPort vp, |
216 | 2531 | caballero | Cancellable cancel,double scale) throws DriverException { |
217 | 9056 | nacho | if (isWithinScale(scale)){
|
218 | 671 | luisw | try {
|
219 | 2183 | fernando | if(status!=null && firstLoad){ |
220 | 5979 | nacho | 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 | 9056 | nacho | ((RasterFileAdapter) source).draw(image, g, vp, cancel); |
237 | 2623 | nacho | status.applyStatus(this);
|
238 | 2183 | fernando | firstLoad = false;
|
239 | } |
||
240 | 9056 | nacho | |
241 | 5979 | nacho | 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 | 9056 | nacho | |
258 | 671 | luisw | } catch (DriverIOException e) {
|
259 | throw new DriverException(e); |
||
260 | } |
||
261 | 1034 | vcaballero | |
262 | if (getVirtualLayers() != null) { |
||
263 | 2531 | caballero | getVirtualLayers().draw(image, g, vp, cancel,scale); |
264 | 1034 | vcaballero | } |
265 | 2531 | caballero | } |
266 | 526 | vcaballero | } |
267 | 1034 | vcaballero | |
268 | /**
|
||
269 | * Inserta la proyecci?n.
|
||
270 | *
|
||
271 | * @param proj Proyecci?n.
|
||
272 | */
|
||
273 | 567 | luisw | public void setProjection(IProjection proj) { |
274 | super.setProjection(proj);
|
||
275 | 1034 | vcaballero | |
276 | 1466 | luisw | if (source != null && source.getDriver() != null && source.getDriver() instanceof GeorreferencedRasterDriver) { |
277 | 567 | luisw | GeorreferencedRasterDriver geoDrv = (GeorreferencedRasterDriver) source.getDriver(); |
278 | 1034 | vcaballero | |
279 | if (geoDrv.getProjection() == null) { |
||
280 | 567 | luisw | geoDrv.setProjection(proj); |
281 | 1034 | vcaballero | } |
282 | 567 | luisw | } |
283 | 562 | fernando | } |
284 | 9056 | nacho | |
285 | 1455 | luisw | public void setTransparency(int trans) { |
286 | super.setTransparency(trans);
|
||
287 | ((RasterFileAdapter) source).setTransparency(trans); |
||
288 | 6881 | cesar | if (getMapContext() != null){ |
289 | getMapContext().invalidate(); |
||
290 | 6007 | nacho | } |
291 | 1455 | luisw | } |
292 | 562 | fernando | |
293 | 2183 | fernando | public int getTransparency() { |
294 | 1455 | luisw | return ((RasterFileAdapter) source).getTransparency();
|
295 | } |
||
296 | 9056 | nacho | |
297 | 567 | luisw | /*
|
298 | 526 | vcaballero | * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
299 | */
|
||
300 | 651 | fernando | public Rectangle2D getFullExtent() throws DriverException { |
301 | 567 | luisw | return ((RasterFileAdapter) source).getFullExtent();
|
302 | 526 | vcaballero | } |
303 | 303 | fernando | |
304 | 2322 | igbrotru | /**
|
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 | 2347 | igbrotru | public int[] getPixel(double wcx, double wcy){ |
311 | return ((RasterFileAdapter) source).getPixel(wcx, wcy);
|
||
312 | 2322 | igbrotru | } |
313 | 9056 | nacho | |
314 | 2396 | nacho | public double getMaxX(){ |
315 | try {
|
||
316 | return this.getFullExtent().getMaxX(); |
||
317 | }catch(DriverException e){
|
||
318 | return 0D; |
||
319 | } |
||
320 | } |
||
321 | 9056 | nacho | |
322 | 2396 | nacho | public double getMaxY(){ |
323 | try {
|
||
324 | return this.getFullExtent().getMaxY(); |
||
325 | }catch(DriverException e){
|
||
326 | return 0D; |
||
327 | } |
||
328 | } |
||
329 | 9056 | nacho | |
330 | 2396 | nacho | public double getMinX(){ |
331 | try {
|
||
332 | return this.getFullExtent().getMinX(); |
||
333 | }catch(DriverException e){
|
||
334 | return 0D; |
||
335 | } |
||
336 | } |
||
337 | 9056 | nacho | |
338 | 2396 | nacho | public double getMinY(){ |
339 | try {
|
||
340 | return this.getFullExtent().getMinY(); |
||
341 | }catch(DriverException e){
|
||
342 | return 0D; |
||
343 | } |
||
344 | } |
||
345 | 9056 | nacho | |
346 | 2396 | nacho | public double getHeight(){ |
347 | try {
|
||
348 | return this.getFullExtent().getHeight(); |
||
349 | }catch(DriverException e){
|
||
350 | return 0D; |
||
351 | } |
||
352 | } |
||
353 | 9056 | nacho | |
354 | 2396 | nacho | public double getWidth(){ |
355 | try {
|
||
356 | return this.getFullExtent().getWidth(); |
||
357 | }catch(DriverException e){
|
||
358 | return 0D; |
||
359 | } |
||
360 | } |
||
361 | |||
362 | 9056 | nacho | |
363 | 1680 | luisw | /* (non-Javadoc)
|
364 | 5048 | ldiaz | * @deprecated. See String getInfo(Point p) throws DriverException
|
365 | 1680 | luisw | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(java.awt.Point)
|
366 | 526 | vcaballero | */
|
367 | 1680 | luisw | public String queryByPoint(Point p) throws DriverException { |
368 | 3242 | luisw2 | String data = "<file:"+normalizeAsXMLTag(getName())+">\n"; |
369 | 1680 | luisw | |
370 | ArrayList attr = source.getAttributes();
|
||
371 | 1717 | luisw | data += " <raster\n";
|
372 | data += " File=\""+((RasterFileAdapter) source).getFile()+"\"\n"; |
||
373 | 1680 | luisw | for (int i=0; i<attr.size(); i++) { |
374 | Object [] a = (Object []) attr.get(i); |
||
375 | |||
376 | 1717 | luisw | 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 | 1680 | luisw | } |
382 | 2183 | fernando | data += " Point=\""+posX+" , "+posY+"\"\n"; |
383 | data += " Point_WC=\""+posXWC+" , "+posYWC+"\"\n"; |
||
384 | 2322 | igbrotru | data += " RGB=\""+r+", "+g+", "+b+"\"\n"; |
385 | 1717 | luisw | data += " />\n";
|
386 | 1680 | luisw | |
387 | 3242 | luisw2 | data += "</file:"+normalizeAsXMLTag(getName())+">\n"; |
388 | 2183 | fernando | //System.out.println(data);
|
389 | 1717 | luisw | return data;
|
390 | 526 | vcaballero | } |
391 | 9056 | nacho | |
392 | 8765 | jjdelcerro | public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws DriverException { |
393 | 9056 | nacho | |
394 | 6881 | cesar | Point2D pReal = getMapContext().getViewPort().toMapPoint(p);
|
395 | 6030 | nacho | Point2D px = null; |
396 | 9056 | nacho | if( pReal.getX() > this.getMinX() && |
397 | pReal.getX() < this.getMaxX() &&
|
||
398 | pReal.getY() > this.getMinY() &&
|
||
399 | 6030 | nacho | 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 | 9056 | nacho | } |
409 | 8765 | jjdelcerro | px = new Point2D.Double(); |
410 | 6030 | nacho | px.setLocation( ((pReal.getX() - this.getMinX()) * w) / getWidth(),
|
411 | ((this.getMaxY() - pReal.getY()) * h) / getHeight());
|
||
412 | } |
||
413 | 9056 | nacho | |
414 | 6030 | nacho | int[] rgb = this.getPixel(pReal.getX(), pReal.getY()); |
415 | 9056 | nacho | |
416 | StringXMLItem[] item = new StringXMLItem[1]; |
||
417 | 5048 | ldiaz | String data = "<file:"+normalizeAsXMLTag(getName())+">\n"; |
418 | 9056 | nacho | |
419 | 5048 | ldiaz | data += " <raster\n";
|
420 | 6030 | nacho | data += " View_Point=\""+p.getX()+" , "+p.getY()+"\"\n"; |
421 | 9056 | nacho | data += " World_Point=\""+DoubleUtilities.format(pReal.getX(), 5)+" , "+DoubleUtilities.format(pReal.getY(), 5)+"\"\n"; |
422 | 6030 | nacho | if(px == null) |
423 | data += " Pixel_Point=\"Out\"\n";
|
||
424 | 9056 | nacho | else{
|
425 | 8765 | jjdelcerro | data += " Pixel_Point=\""+(int)px.getX()+" , "+(int)px.getY()+"\"\n"; |
426 | 9056 | nacho | 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 | 8765 | jjdelcerro | data += " RGB=\""+rgb[1]+" "+rgb[2]+" "+rgb[3]+"\"\n"; |
445 | 9056 | nacho | |
446 | 5048 | ldiaz | data += " />\n";
|
447 | data += "</file:"+normalizeAsXMLTag(getName())+">\n"; |
||
448 | 9056 | nacho | |
449 | item[0] = new StringXMLItem(data, this); |
||
450 | 5057 | ldiaz | return item;
|
451 | 9056 | nacho | |
452 | } |
||
453 | |||
454 | 3242 | luisw2 | /**
|
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 | 435 | vcaballero | |
464 | 526 | vcaballero | /**
|
465 | 2396 | nacho | * Obtiene atributos a partir de un georasterfile
|
466 | * @return
|
||
467 | */
|
||
468 | public ArrayList getAttributes() { |
||
469 | return source.getAttributes();
|
||
470 | } |
||
471 | 9056 | nacho | |
472 | 2396 | nacho | /**
|
473 | 1828 | fernando | * @throws XMLException
|
474 | 526 | vcaballero | * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
475 | */
|
||
476 | 1828 | fernando | public XMLEntity getXMLEntity() throws XMLException { |
477 | 526 | vcaballero | XMLEntity xml = super.getXMLEntity();
|
478 | 9056 | nacho | |
479 | 895 | vcaballero | if (source instanceof RasterFileAdapter) { |
480 | xml.putProperty("file", ((RasterFileAdapter) source).getFile());
|
||
481 | 1034 | vcaballero | } |
482 | 9056 | nacho | |
483 | 895 | vcaballero | xml.putProperty("driverName", getSource().getDriver().getName());
|
484 | 9056 | nacho | |
485 | 4234 | nacho | //Si no hay ning?n Status aplicamos el StatusLayerRaster que se usa por defecto
|
486 | if(status == null) |
||
487 | status = new StatusLayerRaster();
|
||
488 | 9056 | nacho | |
489 | 4234 | nacho | status.getXMLEntity(xml, true, this); |
490 | 9056 | nacho | |
491 | |||
492 | 526 | vcaballero | return xml;
|
493 | } |
||
494 | 9056 | nacho | |
495 | 2183 | fernando | 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 | 9056 | nacho | |
512 | 1455 | luisw | 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 | 1466 | luisw | // Para notificar al adapter-driver cual es la proyecci?n.
|
523 | setProjection(super.getProjection());
|
||
524 | 9056 | nacho | |
525 | 4234 | nacho | //Inicializamos la clase a la que se usa por defecto para
|
526 | //compatibilidad con proyectos antiguos
|
||
527 | String claseStr = StatusLayerRaster.defaultClass;
|
||
528 | 2183 | fernando | if (xml.contains("raster.class")) { |
529 | claseStr = xml.getStringProperty("raster.class");
|
||
530 | } |
||
531 | if(status!=null) |
||
532 | status.setXMLEntity(xml, this);
|
||
533 | else{
|
||
534 | 9056 | nacho | |
535 | //Cuando cargamos un proyecto
|
||
536 | |||
537 | 2183 | fernando | 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 | 9056 | nacho | } |
555 | 2183 | fernando | } |
556 | } |
||
557 | firstLoad = true;
|
||
558 | 9056 | nacho | |
559 | |||
560 | 1455 | luisw | } catch (DriverLoadException e) {
|
561 | 1472 | luisw | throw new XMLException(e); |
562 | 1455 | luisw | } |
563 | } |
||
564 | 435 | vcaballero | |
565 | 569 | luisw | /* (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 | 9013 | caballero | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet propeties) |
569 | 1488 | luisw | throws DriverException {
|
570 | 9056 | nacho | |
571 | if (isVisible() && isWithinScale(scale)){
|
||
572 | 1488 | luisw | isPrinting = true;
|
573 | if (!mustTilePrint) {
|
||
574 | 2531 | caballero | draw(null, g, viewPort, cancel,scale);
|
575 | 1488 | luisw | } 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 | 9056 | nacho | |
583 | 3084 | nacho | //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 | 9056 | nacho | |
586 | Statistic stats = getSource().getFilterStack().getStats(); |
||
587 | 11148 | nacho | try{
|
588 | if(stats != null) |
||
589 | stats.history.add(stats.new History(getName(), stats.minBandValue, stats.maxBandValue, stats.secondMinBandValue, stats.secondMaxBandValue)); |
||
590 | }catch(NoSuchFieldError e){ |
||
591 | e.printStackTrace(); |
||
592 | } |
||
593 | 9056 | nacho | |
594 | |||
595 | 1488 | luisw | for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) { |
596 | // Parte que dibuja
|
||
597 | try {
|
||
598 | ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
||
599 | 2531 | caballero | draw(null, g, vp, cancel,scale);
|
600 | 1488 | luisw | } catch (NoninvertibleTransformException e) { |
601 | // TODO Auto-generated catch block
|
||
602 | e.printStackTrace(); |
||
603 | } |
||
604 | } |
||
605 | 9056 | nacho | |
606 | 3084 | nacho | if(stats != null){ |
607 | getSource().getFilterStack().getStats().history.clear(); |
||
608 | stats = getSource().getFilterStack().getStats(); |
||
609 | } |
||
610 | 9056 | nacho | |
611 | 1488 | luisw | } |
612 | isPrinting = false;
|
||
613 | 2531 | caballero | } |
614 | 1488 | luisw | } |
615 | |||
616 | 2531 | caballero | public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale) |
617 | 9056 | nacho | throws DriverException {
|
618 | 1040 | fjp | // Para no pedir imagenes demasiado grandes, vamos
|
619 | // a hacer lo mismo que hace EcwFile: chunkear.
|
||
620 | // Llamamos a drawView con cuadraditos m?s peque?os
|
||
621 | // del BufferedImage ni caso, cuando se imprime viene con null
|
||
622 | 9056 | nacho | |
623 | 1040 | fjp | int numW, numH;
|
624 | int stepX, stepY;
|
||
625 | int xProv, yProv, wProv, hProv;
|
||
626 | double xProvD, yProvD, wProvD, hProvD;
|
||
627 | 9056 | nacho | int A = 1500; |
628 | 1152 | fjp | int H = 1500; |
629 | 1040 | fjp | int altoAux, anchoAux;
|
630 | 9056 | nacho | |
631 | 1152 | fjp | AffineTransform mat = (AffineTransform) viewPort.getAffineTransform().clone(); |
632 | 9056 | nacho | |
633 | 1040 | fjp | // Vamos a hacerlo en trozos de AxH
|
634 | Rectangle r = g.getClipRect();
|
||
635 | numW = (int) (r.width) / A;
|
||
636 | 9056 | nacho | numH = (int) (r.height) / H;
|
637 | |||
638 | |||
639 | 1040 | fjp | double[] srcPts = new double[8]; |
640 | double[] dstPts= new double[8]; |
||
641 | |||
642 | yProv = (int) r.y;
|
||
643 | for (stepY=0; stepY < numH+1; stepY++) |
||
644 | { |
||
645 | 9056 | nacho | if ((yProv + H) > r.getMaxY())
|
646 | 1040 | fjp | altoAux = (int) r.getMaxY() - yProv;
|
647 | else
|
||
648 | altoAux = H; |
||
649 | 9056 | nacho | |
650 | 1040 | fjp | xProv = (int) r.x;
|
651 | 9056 | nacho | for (stepX=0; stepX < numW+1; stepX++) |
652 | { |
||
653 | if ((xProv + A) > r.getMaxX())
|
||
654 | 1040 | fjp | anchoAux = (int) r.getMaxX() - xProv;
|
655 | else
|
||
656 | anchoAux = A; |
||
657 | 9056 | nacho | |
658 | 1040 | fjp | Rectangle newRect = new Rectangle(xProv, yProv, anchoAux, altoAux); |
659 | 9056 | nacho | |
660 | 1040 | fjp | // Parte que dibuja
|
661 | srcPts[0] = xProv;
|
||
662 | srcPts[1] = yProv;
|
||
663 | srcPts[2] = xProv + anchoAux+1; |
||
664 | srcPts[3] = yProv;
|
||
665 | srcPts[4] = xProv + anchoAux+1; |
||
666 | srcPts[5] = yProv + altoAux+1; |
||
667 | srcPts[6] = xProv;
|
||
668 | srcPts[7] = yProv + altoAux+1; |
||
669 | 9056 | nacho | |
670 | 1040 | fjp | try {
|
671 | mat.inverseTransform(srcPts, 0, dstPts, 0, 4); |
||
672 | Rectangle2D.Double rectCuadricula = new Rectangle2D.Double( |
||
673 | dstPts[0], dstPts[1], |
||
674 | 9056 | nacho | dstPts[2] - dstPts[0], dstPts[5]-dstPts[3]); |
675 | 1040 | fjp | Extent extent = new Extent(rectCuadricula);
|
676 | 9056 | nacho | |
677 | 1040 | fjp | Dimension tam = new Dimension(anchoAux+1, altoAux+1); |
678 | ViewPort vp = viewPort.cloneViewPort(); |
||
679 | 1152 | fjp | vp.setImageSize(tam); |
680 | 1040 | fjp | vp.setExtent(rectCuadricula); |
681 | 1152 | fjp | vp.setAffineTransform(mat); |
682 | 1040 | fjp | // ViewPortData vp = new ViewPortData(getProjection(), extent, tam);
|
683 | // vp.setMat(mat);
|
||
684 | // rasterList.draw(g2, vp);
|
||
685 | 9056 | nacho | |
686 | 2396 | nacho | /*System.out.println("FLyrRaster.print(): fila "+stepX+" de "
|
687 | 9056 | nacho | + numW + " , col "+stepY+" de " + numH +
|
688 | 1152 | fjp | "\n, Extent = "+vp.getExtent() + " imageSize: "
|
689 | 2396 | nacho | + tam);*/
|
690 | 2531 | caballero | draw(null, g, vp, cancel,scale);
|
691 | 9056 | nacho | |
692 | 1040 | fjp | } catch (NoninvertibleTransformException e) { |
693 | // TODO Auto-generated catch block
|
||
694 | e.printStackTrace(); |
||
695 | } |
||
696 | // Fin parte que dibuja
|
||
697 | 9056 | nacho | xProv = xProv + A; |
698 | } |
||
699 | 1040 | fjp | yProv = yProv + H; |
700 | 9056 | nacho | } |
701 | |||
702 | 569 | luisw | } |
703 | 9056 | nacho | |
704 | 2183 | fernando | /**
|
705 | * A?ade un fichero a la capa raster
|
||
706 | * @param fileName Nombre del fichero
|
||
707 | */
|
||
708 | public void addFiles(String fileName){ |
||
709 | ((RasterFileAdapter) source).addFile(fileName); |
||
710 | } |
||
711 | 9056 | nacho | |
712 | 2183 | fernando | /**
|
713 | * Elimina un fichero a la capa raster
|
||
714 | * @param fileName Nombre del fichero
|
||
715 | */
|
||
716 | public void delFile(String fileName){ |
||
717 | ((RasterFileAdapter) source).delFile(fileName); |
||
718 | } |
||
719 | 9056 | nacho | |
720 | 2623 | nacho | /* (non-Javadoc)
|
721 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setBand(int, int)
|
||
722 | */
|
||
723 | public void setBand(int flag, int nBand) { |
||
724 | this.getSource().setBand(flag, nBand);
|
||
725 | } |
||
726 | 9056 | nacho | |
727 | 3257 | nacho | /**
|
728 | * Borra de la lista de listeners el que se pasa como par?metro.
|
||
729 | *
|
||
730 | * @param o LayerListener a borrar.
|
||
731 | *
|
||
732 | * @return True si ha sido correcto el borrado del Listener.
|
||
733 | */
|
||
734 | public boolean removeLayerListener(LayerListener o) { |
||
735 | 3410 | nacho | if(this.isRemoveRasterFlag()){ |
736 | 4404 | nacho | /*try{
|
737 | 3410 | nacho | ((RasterFileAdapter) source).stop();
|
738 | }catch(DriverIOException exc){
|
||
739 | 9056 | nacho | |
740 | 4404 | nacho | }*/
|
741 | 3410 | nacho | this.setRemoveRasterFlag(true); |
742 | 3257 | nacho | } |
743 | return super.layerListeners.remove(o); |
||
744 | } |
||
745 | 9056 | nacho | |
746 | 3410 | nacho | /**
|
747 | * @return Returns the removeRasterFlag.
|
||
748 | */
|
||
749 | public boolean isRemoveRasterFlag() { |
||
750 | return removeRasterFlag;
|
||
751 | } |
||
752 | 9056 | nacho | |
753 | 3410 | nacho | /**
|
754 | * Asigna el valor del flag que dice si destruimos la memoria del raster
|
||
755 | * al eliminarlo del TOC o no.
|
||
756 | * @param removeRasterFlag The removeRasterFlag to set.
|
||
757 | */
|
||
758 | public void setRemoveRasterFlag(boolean removeRasterFlag) { |
||
759 | this.removeRasterFlag = removeRasterFlag;
|
||
760 | } |
||
761 | 9056 | nacho | |
762 | public ImageIcon getTocImageIcon() { |
||
763 | 5761 | jmvivo | return new ImageIcon(MapControl.class.getResource("images/icolayerRaster.PNG")); |
764 | } |
||
765 | 9056 | nacho | |
766 | 6007 | nacho | /*
|
767 | * (non-Javadoc)
|
||
768 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize()
|
||
769 | */
|
||
770 | public int[] getTileSize() { |
||
771 | 9056 | nacho | int[] size = {maxTileDrawWidth, maxTileDrawHeight}; |
772 | 6007 | nacho | return size;
|
773 | } |
||
774 | |||
775 | /*
|
||
776 | * (non-Javadoc)
|
||
777 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#isTiled()
|
||
778 | */
|
||
779 | public boolean isTiled() { |
||
780 | return mustTileDraw;
|
||
781 | } |
||
782 | 9056 | nacho | |
783 | 6037 | nacho | /**
|
784 | * Obtiene el flag que dice si la imagen est? o no georreferenciada
|
||
785 | * @return true si est? georreferenciada y false si no lo est?.
|
||
786 | */
|
||
787 | public boolean isGeoreferenced() { |
||
788 | return getSource().isGeoreferenced();
|
||
789 | } |
||
790 | 9056 | nacho | |
791 | /**
|
||
792 | * Obtiene el grid asociado
|
||
793 | * @return grid
|
||
794 | */
|
||
795 | public Grid getGrid(){
|
||
796 | return getSource().getGrid();
|
||
797 | } |
||
798 | |||
799 | /**
|
||
800 | * Obtiene el tipo de dato de la capa raster
|
||
801 | * @return Entero que representa el tipo de dato de la capa raster.
|
||
802 | */
|
||
803 | public int getDataType() { |
||
804 | return getSource().getDataType();
|
||
805 | } |
||
806 | 9239 | nacho | |
807 | /*
|
||
808 | * (non-Javadoc)
|
||
809 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#cloneLayer()
|
||
810 | */
|
||
811 | public FLayer cloneLayer() throws Exception { |
||
812 | FLyrRaster clonedLayer = new FLyrRaster();
|
||
813 | |||
814 | File f = new File(getSource().getFiles()[0].getName()); |
||
815 | RasterAdapter adapter = new RasterFileAdapter(f);
|
||
816 | com.hardcode.driverManager.Driver driver = LayerFactory.getDM().getDriver("gvSIG Image Driver");
|
||
817 | adapter.setDriver(driver); |
||
818 | |||
819 | clonedLayer.setName(getName()); |
||
820 | clonedLayer.setVisible(isVisible()); |
||
821 | clonedLayer.setSource(adapter); |
||
822 | clonedLayer.setProjection(getProjection()); |
||
823 | |||
824 | clonedLayer.setXMLEntity(getXMLEntity()); |
||
825 | |||
826 | clonedLayer.load(); |
||
827 | |||
828 | return clonedLayer;
|
||
829 | } |
||
830 | 10195 | nacho | |
831 | /**
|
||
832 | * Set data buffer to create a memory raster driver
|
||
833 | * @param buf data buffer
|
||
834 | */
|
||
835 | public void setBuffer(RasterBuf buf){ |
||
836 | source.setBuffer(buf); |
||
837 | } |
||
838 | |||
839 | /**
|
||
840 | * Set extent to create a memory raster driver
|
||
841 | * @param ext Extent
|
||
842 | */
|
||
843 | public void setExtent(Extent ext){ |
||
844 | source.setExtent(ext); |
||
845 | } |
||
846 | 214 | fernando | } |